First build
This commit is contained in:
@@ -1,49 +1,53 @@
|
||||
import type { Context } from '#root/bot/context.js'
|
||||
import type { LanguageCode } from '@grammyjs/types'
|
||||
import type { CommandContext } from 'grammy'
|
||||
import { i18n } from '#root/bot/i18n.js'
|
||||
import { Command, CommandGroup } from '@grammyjs/commands'
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import type { LanguageCode } from "@grammyjs/types";
|
||||
import type { CommandContext } from "grammy";
|
||||
import { i18n } from "#root/bot/i18n.js";
|
||||
import { Command, CommandGroup } from "@grammyjs/commands";
|
||||
|
||||
function addCommandLocalizations(command: Command) {
|
||||
i18n.locales.forEach((locale) => {
|
||||
i18n.locales.forEach(locale => {
|
||||
command.localize(
|
||||
locale as LanguageCode,
|
||||
command.name,
|
||||
i18n.t(locale, `${command.name}.description`),
|
||||
)
|
||||
})
|
||||
return command
|
||||
i18n.t(locale, `${command.name}.description`)
|
||||
);
|
||||
});
|
||||
return command;
|
||||
}
|
||||
|
||||
function addCommandToChats(command: Command, chats: number[]) {
|
||||
for (const chatId of chats) {
|
||||
command.addToScope({
|
||||
type: 'chat',
|
||||
chat_id: chatId,
|
||||
})
|
||||
type: "chat",
|
||||
chat_id: chatId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function setCommandsHandler(ctx: CommandContext<Context>) {
|
||||
const start = new Command('start', i18n.t('en', 'start.description'))
|
||||
.addToScope({ type: 'all_private_chats' })
|
||||
addCommandLocalizations(start)
|
||||
addCommandToChats(start, ctx.config.botAdmins)
|
||||
const start = new Command(
|
||||
"start",
|
||||
i18n.t("en", "start.description")
|
||||
).addToScope({ type: "all_private_chats" });
|
||||
addCommandLocalizations(start);
|
||||
addCommandToChats(start, ctx.config.botAdmins);
|
||||
|
||||
const language = new Command('language', i18n.t('en', 'language.description'))
|
||||
.addToScope({ type: 'all_private_chats' })
|
||||
addCommandLocalizations(language)
|
||||
addCommandToChats(language, ctx.config.botAdmins)
|
||||
const language = new Command(
|
||||
"language",
|
||||
i18n.t("en", "language.description")
|
||||
).addToScope({ type: "all_private_chats" });
|
||||
addCommandLocalizations(language);
|
||||
addCommandToChats(language, ctx.config.botAdmins);
|
||||
|
||||
const setcommands = new Command('setcommands', i18n.t('en', 'setcommands.description'))
|
||||
addCommandToChats(setcommands, ctx.config.botAdmins)
|
||||
const setcommands = new Command(
|
||||
"setcommands",
|
||||
i18n.t("en", "setcommands.description")
|
||||
);
|
||||
addCommandToChats(setcommands, ctx.config.botAdmins);
|
||||
|
||||
const commands = new CommandGroup()
|
||||
.add(start)
|
||||
.add(language)
|
||||
.add(setcommands)
|
||||
const commands = new CommandGroup().add(start).add(language).add(setcommands);
|
||||
|
||||
await commands.setCommands(ctx)
|
||||
await commands.setCommands(ctx);
|
||||
|
||||
return ctx.reply(ctx.t('admin-commands-updated'))
|
||||
return ctx.reply(ctx.t("admin-commands-updated"));
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { Context } from '#root/bot/context.js'
|
||||
import type { ErrorHandler } from 'grammy'
|
||||
import { getUpdateInfo } from '#root/bot/helpers/logging.js'
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import type { ErrorHandler } from "grammy";
|
||||
import { getUpdateInfo } from "#root/bot/helpers/logging.js";
|
||||
|
||||
export const errorHandler: ErrorHandler<Context> = (error) => {
|
||||
const { ctx } = error
|
||||
export const errorHandler: ErrorHandler<Context> = error => {
|
||||
const { ctx } = error;
|
||||
|
||||
ctx.logger.error({
|
||||
err: error.error,
|
||||
update: getUpdateInfo(ctx),
|
||||
})
|
||||
}
|
||||
update: getUpdateInfo(ctx)
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user