Skip to content

Commit 3667315

Browse files
committed
feat: debugUserProfile
1 parent 2315633 commit 3667315

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

apps/tgbot/src/adapter/Bot.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ export class BotAdapter extends Bot<BotTypes> {
7070
}
7171
});
7272
}
73+
74+
constructFile(file: Uint8Array, filename: string): BotTypes['SendableFile'] {
75+
return new InputFile(file, filename);
76+
}
7377
}

apps/tgbot/src/bot/commandList.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ export const commandListAdmin = [
1818
...commandListPrivate,
1919
{ command: 'ban', description: '在排行榜中封禁用户' },
2020
{ command: 'set_my_command', description: '更新 Bot 命令列表' },
21+
{ command: 'debug_net_card', description: '调试 Net 用户资料,参数:卡号' },
2122
// { command: 'stats', description: '统计信息' }
2223
] as const;

packages/botcore/src/modules/admin/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ export default class AdminClient {
2222
public async rankingBan(username: string) {
2323
await this.baseRequest('ranking-ban', { username });
2424
}
25+
26+
public async debugUserProfile(cardId: string) {
27+
return await this.baseRequest('debug-user-profile', { cardId });
28+
}
2529
}

packages/botcore/src/modules/admin/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ export default <T extends BotTypes>({ bot, env, getContext, musicToFile }: Build
2424
return true;
2525
});
2626

27+
bot.registerCommand('debug_net_card', async (event) => {
28+
checkAdminUser(event.fromId);
29+
30+
const card = event.params[0];
31+
const req = await client.debugUserProfile(card);
32+
const data = await req.json();
33+
const enc = new TextEncoder();
34+
35+
await event.reply()
36+
.addDocument(bot.constructFile(enc.encode(JSON.stringify(data, null, 2)), `${card}.json`))
37+
.dispatch();
38+
39+
return true;
40+
});
41+
2742
// bot.command('set_my_command', async (ctx) => {
2843
// ctx.transaction('set_my_command');
2944
// checkAdminUser(ctx);

packages/botfirm/src/Bot.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ export abstract class Bot<T extends BotTypes> {
3636
public abstract registerInlineQuery(query: RegExp | RegExp[], handler: (event: InlineQueryEventBase<T>) => Promise<boolean>): void;
3737

3838
public abstract registerInlineQueryResultChosen(resultId: RegExp | RegExp[], handler: (event: InlineQueryResultChosenEventBase<T>) => Promise<boolean>): void;
39+
40+
public constructFile(file: Uint8Array, filename: string): T['SendableFile'] {
41+
throw new Error('不支持此平台');
42+
}
3943
}

0 commit comments

Comments
 (0)