Skip to content

Commit

Permalink
refactor: format and add accompany type
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Apr 25, 2024
1 parent e206d9a commit 45d2ffe
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Client {
}, 50);
} catch (error: unknown) {
core.setFailed(error as any);
process.exit(1);
throw error;
}
}

Expand All @@ -50,7 +50,7 @@ export class Client {
}
} catch (error: unknown) {
core.setFailed(error as any);
process.exit(1);
throw error;
}
}

Expand All @@ -63,6 +63,7 @@ export class Client {
}
ans.push(...res);
}

return ans
.map((u) => ({ uid: u.uid, username: u.username, level: u.guard_level }))
.sort((lhs, rhs) => (lhs.level ?? 3) - (rhs.level ?? 3));
Expand Down
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ function today(): string {
}

async function run(): Promise<void> {
const roomid = core.getInput('roomid');
const ruid = core.getInput('ruid');
const client = new Client(roomid, ruid);
const roomid = core.getInput('roomid');
const outDir = core.getInput('outDir');

const client = new Client(roomid, ruid);
const list = await client.get();

{
Expand All @@ -31,8 +32,8 @@ async function run(): Promise<void> {
);
}
}

{
const outDir = core.getInput('outDir');
const csvname = path.join(outDir, `${today()}.csv`);
const content = toCSV(list);
core.info(`---------------------------------------`);
Expand Down
12 changes: 8 additions & 4 deletions src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ export function getType(level?: number): string {
}

export function toCSV(list: User[]): string {
const text = ['rank,uid,username,type'];
const text = ['rank,uid,username,type,accompany'];
let cnt = 1;
for (const user of list) {
text.push(`${cnt++},${user.uid},${user.username},${getType(user.level)}`);
text.push(
`${cnt++},${user.uid},${user.username},${getType(user.level)},${user.accompany ?? ''}`
);
}
return text.join('\n');
}

export function toMarkdown(list: User[]): string {
const text = ['|序号|UID|用户名|大航海|', '|:-:|:-:|:-:|:-:|'];
const text = ['|序号|UID|用户名|大航海|陪伴天数|', '|:-:|:-:|:-:|:-:|:-:|'];
let cnt = 1;
for (const user of list) {
text.push(`|${cnt++}|${user.uid}|${user.username}|${getType(user.level)}|`);
text.push(
`|${cnt++}|${user.uid}|${user.username}|${getType(user.level)}|${user.accompany ?? ''}|`
);
}
return text.join('\n');
}
18 changes: 18 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
export interface User {
/**
* Captain uid
*/
uid: number;

/**
* Captain username (at fetched time)
*/
username: string;

/**
* Captain level: 3 for 舰长, 2 for 提督, 1 for 总督
*
* @default 3
*/
level?: number;

/**
* Captain accompany length (number of days)
*/
accompany?: number;
}

0 comments on commit 45d2ffe

Please sign in to comment.