add /admins command

This commit is contained in:
2026-03-18 13:43:28 +03:00
parent bfb6fe33db
commit 3700f61393
3 changed files with 64 additions and 4 deletions
+55
View File
@@ -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<void> {
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);
}
}
}
+2
View File
@@ -81,6 +81,7 @@ import {OpenAIGenImage} from "./commands/openai-gen-image";
import {clearUpFolderFromOldFiles} from "./util/files"; import {clearUpFolderFromOldFiles} from "./util/files";
import {DownloadYtVideo} from "./callback_commands/download-yt-video"; import {DownloadYtVideo} from "./callback_commands/download-yt-video";
import {YtInfo} from "./callback_commands/yt-info"; import {YtInfo} from "./callback_commands/yt-info";
import {AdminsList} from "./commands/admins-list";
process.setUncaughtExceptionCaptureCallback(logError); process.setUncaughtExceptionCaptureCallback(logError);
@@ -161,6 +162,7 @@ export const commands: Command[] = [
new AdminsAdd(), new AdminsAdd(),
new AdminsRemove(), new AdminsRemove(),
new AdminsList(),
new Shutdown(), new Shutdown(),
new Leave(), new Leave(),
+7 -4
View File
@@ -49,6 +49,7 @@ import {EditOptions} from "../model/edit-options";
import VideoInfo from "youtubei.js/dist/src/parser/youtube/VideoInfo"; import VideoInfo from "youtubei.js/dist/src/parser/youtube/VideoInfo";
import {DownloadYtVideo} from "../callback_commands/download-yt-video"; import {DownloadYtVideo} from "../callback_commands/download-yt-video";
import {TryAgain} from "../callback_commands/try-again"; import {TryAgain} from "../callback_commands/try-again";
import {StoredUser} from "../model/stored-user";
export const ignore = () => { export const ignore = () => {
}; };
@@ -389,11 +390,13 @@ export function chatCommandToString(cmd: Command): string {
return `${cmd.title ? `${cmd.title}: ` : ""}${cmd.description ? `${cmd.description}` : ""}`; return `${cmd.title ? `${cmd.title}: ` : ""}${cmd.description ? `${cmd.description}` : ""}`;
} }
export function fullName(from: User): string { export function fullName(from: User | StoredUser): string {
let fullName = from.first_name; const isStored = "isBot" in from;
if (from.last_name) { let fullName = isStored ? from.firstName : from.first_name;
fullName += " " + from.last_name;
if (isStored ? from.lastName : from.last_name) {
fullName += " " + (isStored ? from.lastName : from.last_name);
} }
return fullName; return fullName;