Skip to content

Commit 3d061a6

Browse files
committed
feat: 导出成绩
1 parent 3667315 commit 3d061a6

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

apps/tgbot/src/bot/commandList.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const commandListPrivate = [
1111
{ command: 'bind', description: '绑定账号' },
1212
{ command: 'profile', description: '查看自己绑定的账号' },
1313
{ command: 'delprofile', description: '删除绑定的账号' },
14+
{ command: 'export', description: '导出当前账号的成绩列表(国服 / 国际服)' },
1415
...commandListBase
1516
] as const;
1617

packages/botcore/src/botBuilder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import levelProgress from './modules/levelProgress';
1010
import b50 from './modules/b50';
1111
import musicSearch from './modules/musicSearch';
1212
import admin from './modules/admin';
13+
import exportUserMusic from './modules/exportUserMusic';
1314

1415
interface BuilderEnvBase<T extends BotTypes> {
1516
bot: Bot<T>,
@@ -34,7 +35,7 @@ export const buildBot = <T extends BotTypes>(env: BuilderEnvBase<T>) => {
3435
)
3536
} satisfies BuilderEnv<T>;
3637

37-
for (const attachHandlers of [callbackQuery, help, bind, scoreQuery, plateProgress, levelProgress, /* levelConstTable, */ b50, musicSearch, admin]) {
38+
for (const attachHandlers of [callbackQuery, help, bind, scoreQuery, plateProgress, levelProgress, /* levelConstTable, */ b50, exportUserMusic, musicSearch, admin]) {
3839
attachHandlers(passEnv);
3940
}
4041
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { BotTypes } from '@clansty/maibot-firm';
2+
import { BuilderEnv } from '../botBuilder';
3+
4+
export default <T extends BotTypes>({ bot, env, getContext }: BuilderEnv<T>) => {
5+
bot.registerCommand('export', async (event) => {
6+
const ctx = getContext(event);
7+
const profile = await ctx.getCurrentProfile();
8+
const enc = new TextEncoder();
9+
10+
const userMusicDetailList = await profile.getUserMusic([]);
11+
await event.reply()
12+
.addDocument(bot.constructFile(enc.encode(JSON.stringify({
13+
userMusicList: [{
14+
userMusicDetailList
15+
}]
16+
}, null, 2)), 'userMusic.json'))
17+
.dispatch();
18+
19+
return true;
20+
});
21+
}

0 commit comments

Comments
 (0)