mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 12:49:57 +00:00
Removed admin functions from bot
This commit is contained in:
parent
84df4d64f8
commit
50faf8b11f
@ -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
|
|
||||||
);
|
|
||||||
});
|
|
||||||
};
|
|
@ -24,11 +24,6 @@
|
|||||||
"botNameErr": "*Error changing bot name:*\n`{tgErr}`",
|
"botNameErr": "*Error changing bot name:*\n`{tgErr}`",
|
||||||
"botDescChanged": "*Bot description changed to* `{botDesc}`.",
|
"botDescChanged": "*Bot description changed to* `{botDesc}`.",
|
||||||
"botDescErr": "*Error changing bot description:*\n`{tgErr}`",
|
"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*!",
|
"isGay": "Yes, you are *gay*!",
|
||||||
"isNtGay": "Ah, you are not gay!",
|
"isNtGay": "Ah, you are not gay!",
|
||||||
"isFurry": "Yes, you are *furry*!",
|
"isFurry": "Yes, you are *furry*!",
|
||||||
|
@ -24,11 +24,6 @@
|
|||||||
"botNameErr": "*Erro ao alterar o nome do bot:*\n`{tgErr}`",
|
"botNameErr": "*Erro ao alterar o nome do bot:*\n`{tgErr}`",
|
||||||
"botDescChanged": "*Descrição do bot alterada para* `{botDesc}`.",
|
"botDescChanged": "*Descrição do bot alterada para* `{botDesc}`.",
|
||||||
"botDescErr": "*Erro ao alterar a descrição do bot:*\n`{tgErr}`",
|
"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*!",
|
"isGay": "Sim, você é *gay*!",
|
||||||
"isNtGay": "Ah, você não é gay!",
|
"isNtGay": "Ah, você não é gay!",
|
||||||
"isFurry": "Sim, você é *furry*!",
|
"isFurry": "Sim, você é *furry*!",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user