From 3700f6139393043e462c601939f7a7088b61a09b Mon Sep 17 00:00:00 2001 From: Danil Nikolaev Date: Wed, 18 Mar 2026 13:43:28 +0300 Subject: [PATCH] add /admins command --- src/commands/admins-list.ts | 55 +++++++++++++++++++++++++++++++++++++ src/index.ts | 2 ++ src/util/utils.ts | 11 +++++--- 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/commands/admins-list.ts diff --git a/src/commands/admins-list.ts b/src/commands/admins-list.ts new file mode 100644 index 0000000..e94a8ac --- /dev/null +++ b/src/commands/admins-list.ts @@ -0,0 +1,55 @@ +import {Command} from "../base/command"; +import {Message} from "typescript-telegram-bot-api"; +import {Requirements} from "../base/requirements"; +import {Requirement} from "../base/requirement"; +import {Environment} from "../common/environment"; +import {fullName, logError, replyToMessage, sendErrorPlaceholder} from "../util/utils"; +import {StoredUser} from "../model/stored-user"; +import {UserStore} from "../common/user-store"; + +export class AdminsList extends Command { + + command = ["adminslist", "admins"]; + argsMode = "none" as const; + + requirements = Requirements.Build(Requirement.BOT_ADMIN); + + async execute(msg: Message): Promise { + try { + const adminIds: number[] = [...Environment.ADMIN_IDS]; + const users: (StoredUser | null)[] = []; + + for (let i = 0; i < adminIds.length; i++) { + const id = adminIds[i]; + const user = await UserStore.get(id); + if (user) { + users.push(user); + } else { + users.push(null); + } + } + + let text = "*Администраторы*:\n\n"; + users.forEach(user => { + text += "\\* "; + + if (user) { + text += `[${fullName(user)}](tg://user?id=${user.id})`; + } else { + text += "Нет информации о пользователе"; + } + + text += "\n"; + }); + + await replyToMessage({ + message: msg, + text: text, + parse_mode: "MarkdownV2" + }); + } catch (e) { + logError(e); + await sendErrorPlaceholder(msg).catch(logError); + } + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 6c213e0..93c30cb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,6 +81,7 @@ import {OpenAIGenImage} from "./commands/openai-gen-image"; import {clearUpFolderFromOldFiles} from "./util/files"; import {DownloadYtVideo} from "./callback_commands/download-yt-video"; import {YtInfo} from "./callback_commands/yt-info"; +import {AdminsList} from "./commands/admins-list"; process.setUncaughtExceptionCaptureCallback(logError); @@ -161,6 +162,7 @@ export const commands: Command[] = [ new AdminsAdd(), new AdminsRemove(), + new AdminsList(), new Shutdown(), new Leave(), diff --git a/src/util/utils.ts b/src/util/utils.ts index a1e39eb..a03aa4e 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -49,6 +49,7 @@ import {EditOptions} from "../model/edit-options"; import VideoInfo from "youtubei.js/dist/src/parser/youtube/VideoInfo"; import {DownloadYtVideo} from "../callback_commands/download-yt-video"; import {TryAgain} from "../callback_commands/try-again"; +import {StoredUser} from "../model/stored-user"; export const ignore = () => { }; @@ -389,11 +390,13 @@ export function chatCommandToString(cmd: Command): string { return `${cmd.title ? `${cmd.title}: ` : ""}${cmd.description ? `${cmd.description}` : ""}`; } -export function fullName(from: User): string { - let fullName = from.first_name; +export function fullName(from: User | StoredUser): string { + const isStored = "isBot" in from; - if (from.last_name) { - fullName += " " + from.last_name; + let fullName = isStored ? from.firstName : from.first_name; + + if (isStored ? from.lastName : from.last_name) { + fullName += " " + (isStored ? from.lastName : from.last_name); } return fullName;