43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import {Command} from "../base/command";
|
|
import {Message} from "typescript-telegram-bot-api";
|
|
import {Requirements} from "../base/requirements";
|
|
import {Requirement} from "../base/requirement";
|
|
import {fullName, logError, oldSendMessage} from "../util/utils";
|
|
import {Environment} from "../common/environment";
|
|
import {botUser} from "../index";
|
|
|
|
export class AdminsAdd extends Command {
|
|
command = "addAdmin";
|
|
title = Environment.commandTitles.adminsAdd;
|
|
description = Environment.commandDescriptions.adminsAdd;
|
|
|
|
requirements = Requirements.Build(
|
|
Requirement.BOT_CREATOR,
|
|
Requirement.REPLY,
|
|
Requirement.CHAT
|
|
);
|
|
|
|
async execute(msg: Message): Promise<void> {
|
|
if (!msg.reply_to_message || !msg.reply_to_message.from) return;
|
|
|
|
const id = msg.reply_to_message.from.id;
|
|
const text = fullName(msg.reply_to_message.from);
|
|
|
|
if (id === botUser.id) {
|
|
await oldSendMessage(msg, Environment.botCannotMakeItselfAdminText).catch(logError);
|
|
return;
|
|
}
|
|
|
|
if (id === Environment.CREATOR_ID) {
|
|
await oldSendMessage(msg, Environment.botCreatorAlreadyAdminText).catch(logError);
|
|
return;
|
|
}
|
|
|
|
if (await Environment.addAdmin(id)) {
|
|
await oldSendMessage(msg, Environment.getUserIsNowAdminText(text)).catch(logError);
|
|
} else {
|
|
await oldSendMessage(msg, Environment.getUserAlreadyAdminText(text)).catch(logError);
|
|
}
|
|
}
|
|
}
|