diff --git a/src/commands/admin.js b/src/commands/admin.js deleted file mode 100644 index 49ee611..0000000 --- a/src/commands/admin.js +++ /dev/null @@ -1,63 +0,0 @@ -const { getStrings } = require('../plugins/checklang.js'); -const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); -const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); - -async function collectInfo(ctx) { - const Strings = getStrings(ctx.from.language_code); - const chatId = ctx.chat.id || Strings.unKnown; - const adminId = ctx.from.id || Strings.unKnown; - const userId = parseInt(ctx.message.text.split(' ')[1], 10); - const admins = await ctx.telegram.getChatAdministrators(chatId); - const isAdmin = admins.some(admin => admin.user.id === adminId); - const onCrew = JSON.parse("[" + process.env.botAdmins + "]"); - - return { Strings, chatId, userId, isAdmin, onCrew }; -} - -async function handleMember(ctx, action, successMessage, errorMessage) { - const { Strings, chatId, userId, isAdmin, onCrew } = await collectInfo(ctx); - - if (onCrew || isAdmin) { - if (isNaN(userId)) { - return ctx.reply(Strings.invalidId, { - parse_mode: 'Markdown', - reply_to_message_id: ctx.message.message_id - }); - } - try { - await action(chatId, userId); - const report = successMessage.replace('{userId}', userId); - ctx.reply(report, { - parse_mode: 'Markdown', - reply_to_message_id: ctx.message.message_id - }); - } catch (err) { - const error = errorMessage.replace('{tgErr}', err.message); - ctx.reply(error, { - parse_mode: 'Markdown', - reply_to_message_id: ctx.message.message_id - }); - } - } else { - ctx.reply(Strings.noPermission, { - parse_mode: 'Markdown', - reply_to_message_id: ctx.message.message_id - }); - } -} - -module.exports = (bot) => { - bot.command('ban', spamwatchMiddleware, (ctx) => { - handleMember(ctx, (chatId, userId) => ctx.telegram.kickChatMember(chatId, userId), - getStrings(ctx.from.language_code).banSuccess, - getStrings(ctx.from.language_code).banErr - ); - }); - - bot.command('unban', spamwatchMiddleware, (ctx) => { - handleMember(ctx, (chatId, userId) => ctx.telegram.unbanChatMember(chatId, userId), - getStrings(ctx.from.language_code).unBanSuccess, - getStrings(ctx.from.language_code).unBanErr - ); - }); -}; diff --git a/src/locales/english.json b/src/locales/english.json index dd9fdd0..e4e52cb 100644 --- a/src/locales/english.json +++ b/src/locales/english.json @@ -24,11 +24,6 @@ "botNameErr": "*Error changing bot name:*\n`{tgErr}`", "botDescChanged": "*Bot description changed to* `{botDesc}`.", "botDescErr": "*Error changing bot description:*\n`{tgErr}`", - "invalidId": "Please enter a valid user ID.", - "banSuccess": "User with ID `{userId}` has been banned.", - "banErr": "Could not ban the user. Check if the ID is correct and if the bot has admin permissions.\n\n`{tgErr}`", - "unBanSuccess": "User with ID `{userId}` has been unbanned.", - "unBanErr": "Could not unban the user. Check if the ID is correct and if the bot has admin permissions.\n\n`{tgErr}`", "isGay": "Yes, you are *gay*!", "isNtGay": "Ah, you are not gay!", "isFurry": "Yes, you are *furry*!", diff --git a/src/locales/portuguese.json b/src/locales/portuguese.json index 2b7a864..37cda68 100644 --- a/src/locales/portuguese.json +++ b/src/locales/portuguese.json @@ -24,11 +24,6 @@ "botNameErr": "*Erro ao alterar o nome do bot:*\n`{tgErr}`", "botDescChanged": "*Descrição do bot alterada para* `{botDesc}`.", "botDescErr": "*Erro ao alterar a descrição do bot:*\n`{tgErr}`", - "invalidId": "Por favor, insira um ID de usuário válido.", - "banSuccess": "Usuário com ID `{userId}` foi banido.", - "banErr": "Não foi possível banir o usuário. Verifique se o ID está correto e se o bot tem permissões de administrador.\n\n`{tgErr}`", - "unBanSuccess": "Usuário com ID `{userId}` foi desbanido.", - "unBanErr": "Não foi possível desbanir o usuário. Verifique se o ID está correto e se o bot tem permissões de administrador.\n\n`{tgErr}`", "isGay": "Sim, você é *gay*!", "isNtGay": "Ah, você não é gay!", "isFurry": "Sim, você é *furry*!",