add /admins command
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
|
||||
+7
-4
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user