refactor: simplify codebase with unified patterns and reduced duplication
- unify ChatConfigService setters into generic setPermission method - replace PermissionService switch statements with data-driven checkers map - deduplicate config.ts callback handlers via loop-based registration (414→254 lines) - extract shared updateChatCommands utility from role-add/role-delete - add proper generics to chunk utility, fix mention loop indexing - extract isHiddenAdmin helper and ANONYMOUS_ADMIN_ID constant in perms - remove debug console.logs, standardize arrow exports and type imports - add roleAdminPermission schema and migration
This commit is contained in:
parent
1eb2200fbe
commit
85c7410ffb
21 changed files with 638 additions and 364 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import type { BotType } from '@/bot/index.js'
|
||||
import { bold, code, format } from 'gramio'
|
||||
import { updateChatCommands } from '@/bot/utilities/commands.js'
|
||||
import { PermissionService } from '@/shared/services/permission.js'
|
||||
import { RoleService } from '@/shared/services/role.js'
|
||||
|
||||
|
|
@ -34,19 +35,7 @@ export default (bot: BotType) => {
|
|||
return ctx.reply('failed to delete role, skill issue')
|
||||
}
|
||||
|
||||
setImmediate(async () => {
|
||||
const roles = await RoleService.getByChatId(ctx.chatId)
|
||||
await bot.api.setMyCommands({
|
||||
scope: {
|
||||
chat_id: ctx.chatId,
|
||||
type: 'chat',
|
||||
},
|
||||
commands: roles.map(role => ({
|
||||
command: role.slug,
|
||||
description: `Mention all members of this role`,
|
||||
})),
|
||||
})
|
||||
})
|
||||
updateChatCommands(bot, ctx.chatId)
|
||||
|
||||
return ctx.reply(format`role ${bold(role.slug)} deleted`)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue