feat(bot): scope help output by admin role

This commit is contained in:
2026-03-10 20:40:15 +04:00
parent 54895c0bd2
commit 05561a397d
3 changed files with 287 additions and 15 deletions

View File

@@ -11,6 +11,11 @@ export interface ScopedTelegramCommands {
commands: readonly TelegramCommandDefinition[]
}
export interface TelegramHelpOptions {
includePrivateCommands?: boolean
includeAdminCommands?: boolean
}
const DEFAULT_COMMAND_NAMES = [
'help',
'household_status'
@@ -65,19 +70,38 @@ export function getTelegramCommandScopes(locale: BotLocale): readonly ScopedTele
]
}
export function formatTelegramHelpText(locale: BotLocale): string {
export function formatTelegramHelpText(
locale: BotLocale,
options: TelegramHelpOptions = {}
): string {
const t = getBotTranslations(locale)
const defaultCommands = new Set<TelegramCommandName>(DEFAULT_COMMAND_NAMES)
const privateCommands = mapCommands(locale, PRIVATE_CHAT_COMMAND_NAMES)
const adminCommands = mapCommands(locale, GROUP_ADMIN_COMMAND_NAMES).filter(
(command) => !defaultCommands.has(command.command)
)
const includePrivateCommands = options.includePrivateCommands ?? true
const includeAdminCommands = options.includeAdminCommands ?? false
const privateCommands = includePrivateCommands
? mapCommands(locale, PRIVATE_CHAT_COMMAND_NAMES)
: []
const adminCommands = includeAdminCommands
? mapCommands(locale, GROUP_ADMIN_COMMAND_NAMES).filter(
(command) => !defaultCommands.has(command.command)
)
: []
return [
t.help.intro,
t.help.privateChatHeading,
...privateCommands.map((command) => `/${command.command} - ${command.description}`),
t.help.groupAdminsHeading,
...adminCommands.map((command) => `/${command.command} - ${command.description}`)
].join('\n')
const sections = [t.help.intro]
if (privateCommands.length > 0) {
sections.push(
t.help.privateChatHeading,
...privateCommands.map((command) => `/${command.command} - ${command.description}`)
)
}
if (adminCommands.length > 0) {
sections.push(
t.help.groupAdminsHeading,
...adminCommands.map((command) => `/${command.command} - ${command.description}`)
)
}
return sections.join('\n')
}