From d4c236ed9d81bef929b03bb9524f31cb20996b9c Mon Sep 17 00:00:00 2001 From: lucmsilva651 Date: Sun, 28 Jul 2024 12:00:56 -0300 Subject: [PATCH] Unban system + changed ban command --- commands/admin.js | 64 ++++++++++++++++++++++++++++++++++------- locales/english.json | 6 ++-- locales/portuguese.json | 4 ++- 3 files changed, 60 insertions(+), 14 deletions(-) diff --git a/commands/admin.js b/commands/admin.js index ec0c425..f632d14 100644 --- a/commands/admin.js +++ b/commands/admin.js @@ -4,32 +4,32 @@ const { getStrings } = require('../plugins/checklang.js'); async function collectInfo(ctx) { const Strings = getStrings(ctx.from.language_code); const chatId = ctx.chat.id || Strings.unKnown; - const userId = ctx.from.id || Strings.unKnown; - const banId = parseInt(ctx.message.text.split(' ')[1], 10); + 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 === userId); - const onCrew = Config.admins.includes(userId); + const isAdmin = admins.some(admin => admin.user.id === adminId); + const onCrew = Config.admins.includes(adminId); - return { Strings, chatId, banId, isAdmin, onCrew }; + return { Strings, chatId, userId, isAdmin, onCrew }; } module.exports = (bot) => { - bot.command('lynxban', async (ctx) => { + bot.command('ban', async (ctx) => { const info = await collectInfo(ctx); - const { Strings, chatId, banId, isAdmin, onCrew } = info; + const { Strings, chatId, userId, isAdmin, onCrew } = info; if (onCrew || isAdmin) { - if (banId === NaN) { + if (userId === NaN) { return ctx.reply( - Strings.banInvalidId, { + Strings.invalidId, { parse_mode: 'Markdown', reply_to_message_id: ctx.message.message_id } ); } else { try { - await ctx.telegram.kickChatMember(chatId, banId); - const banReport = Strings.banSuccess.replace('{banId}', banId); + await ctx.telegram.kickChatMember(chatId, userId); + const banReport = Strings.banSuccess.replace('{userId}', userId); ctx.reply( banReport, { parse_mode: 'Markdown', @@ -55,4 +55,46 @@ module.exports = (bot) => { ); }; }); + + bot.command('unban', async (ctx) => { + const info = await collectInfo(ctx); + const { Strings, chatId, userId, isAdmin, onCrew } = info; + + if (onCrew || isAdmin) { + if (userId === NaN) { + return ctx.reply( + Strings.invalidId, { + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id + } + ); + } else { + try { + await ctx.telegram.unbanChatMember(chatId, userId); + const unBanReport = Strings.unBanSuccess.replace('{userId}', userId); + ctx.reply( + unBanReport, { + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id + } + ); + } catch (err) { + const unBanErr = Strings.unBanErr.replace('{tgErr}', err); + ctx.reply( + unBanErr, { + 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 + } + ); + }; + }); }; \ No newline at end of file diff --git a/locales/english.json b/locales/english.json index 6f167a9..2f838b3 100644 --- a/locales/english.json +++ b/locales/english.json @@ -10,9 +10,11 @@ "botAdminOnly": "This command is exclusive to the bot's general administrators. I can't disclose who they are, nor what this command does.", "privateOnly": "This command should be used only on private chats, and not on groups.", "groupOnly": "This command should be used only on groups, and not on private chats.", - "banInvalidId": "Please enter a valid user ID.", - "banSuccess": "User with ID `{banId}` has been banned.", + "invalidId": "Please enter a valid user ID.", + "banSuccess": "User with ID `{userId}` has been banned.", "banErr": "Could not ban the user. Please 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. Please check if the ID is correct and if the bot has admin permissions.\n\n{tgErr}", "isGay": "Yes, you are *gay*!", "isNtGay": "Aahhh. You are not gay!", "isFurry": "Yes, you are a freaky *furry*!", diff --git a/locales/portuguese.json b/locales/portuguese.json index 8a9e7d6..eb3fc49 100644 --- a/locales/portuguese.json +++ b/locales/portuguese.json @@ -10,9 +10,11 @@ "botAdminOnly": "Esse comando é exclusivo a administradores gerais do bot. Não posso informar quem são, e nem o que esse comando faz.", "privateOnly": "Esse comando deve ser utilizado apenas em chats privados, e não em grupos.", "groupOnly": "Esse comando deve ser utilizado apenas em grupos, e não em chats privados.", - "banInvalidId": "Por favor, insira um ID de usuário válido.", + "invalidId": "Por favor, insira um ID de usuário válido.", "banSuccess": "Usuário com ID `{banId}` 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 `{banId}` 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": "Aahhh. Você não é gay!", "isFurry": "Sim, você é um *furry* esquisito!",