From 1d6e569caead43d59e02e58c9cdbc49772b78095 Mon Sep 17 00:00:00 2001 From: lucmsilva651 Date: Sun, 28 Jul 2024 11:48:30 -0300 Subject: [PATCH] Beta ban system + Simple fixes on getinfo --- commands/admin.js | 58 +++++++++++++++++++++++++++++++++++++++++ commands/getinfo.js | 6 ++++- locales/english.json | 3 +++ locales/portuguese.json | 3 +++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 commands/admin.js diff --git a/commands/admin.js b/commands/admin.js new file mode 100644 index 0000000..ec0c425 --- /dev/null +++ b/commands/admin.js @@ -0,0 +1,58 @@ +const Config = require('../props/config.json'); +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 admins = await ctx.telegram.getChatAdministrators(chatId); + const isAdmin = admins.some(admin => admin.user.id === userId); + const onCrew = Config.admins.includes(userId); + + return { Strings, chatId, banId, isAdmin, onCrew }; +} + +module.exports = (bot) => { + bot.command('lynxban', async (ctx) => { + const info = await collectInfo(ctx); + const { Strings, chatId, banId, isAdmin, onCrew } = info; + + if (onCrew || isAdmin) { + if (banId === NaN) { + return ctx.reply( + Strings.banInvalidId, { + 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); + ctx.reply( + banReport, { + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id + } + ); + } catch (err) { + const banErr = Strings.banErr.replace('{tgErr}', err); + ctx.reply( + banErr, { + 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/commands/getinfo.js b/commands/getinfo.js index 4a41ff0..e2b6414 100644 --- a/commands/getinfo.js +++ b/commands/getinfo.js @@ -45,7 +45,11 @@ async function getChatInfo(ctx) { return chatInfoTemplate; } else { - return Strings.groupOnly; + return ctx.reply( + Strings.groupOnly, { + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id + }); } } diff --git a/locales/english.json b/locales/english.json index 57765ae..6f167a9 100644 --- a/locales/english.json +++ b/locales/english.json @@ -10,6 +10,9 @@ "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.", + "banErr": "Could not ban 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 5946803..8a9e7d6 100644 --- a/locales/portuguese.json +++ b/locales/portuguese.json @@ -10,6 +10,9 @@ "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.", + "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}`", "isGay": "Sim, você é *gay*!", "isNtGay": "Aahhh. Você não é gay!", "isFurry": "Sim, você é um *furry* esquisito!",