mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 12:49:57 +00:00
Unban system + changed ban command
This commit is contained in:
parent
1d6e569cae
commit
d4c236ed9d
@ -4,32 +4,32 @@ const { getStrings } = require('../plugins/checklang.js');
|
|||||||
async function collectInfo(ctx) {
|
async function collectInfo(ctx) {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
const chatId = ctx.chat.id || Strings.unKnown;
|
const chatId = ctx.chat.id || Strings.unKnown;
|
||||||
const userId = ctx.from.id || Strings.unKnown;
|
const adminId = ctx.from.id || Strings.unKnown;
|
||||||
const banId = parseInt(ctx.message.text.split(' ')[1], 10);
|
const userId = parseInt(ctx.message.text.split(' ')[1], 10);
|
||||||
const admins = await ctx.telegram.getChatAdministrators(chatId);
|
const admins = await ctx.telegram.getChatAdministrators(chatId);
|
||||||
const isAdmin = admins.some(admin => admin.user.id === userId);
|
const isAdmin = admins.some(admin => admin.user.id === adminId);
|
||||||
const onCrew = Config.admins.includes(userId);
|
const onCrew = Config.admins.includes(adminId);
|
||||||
|
|
||||||
return { Strings, chatId, banId, isAdmin, onCrew };
|
return { Strings, chatId, userId, isAdmin, onCrew };
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (bot) => {
|
module.exports = (bot) => {
|
||||||
bot.command('lynxban', async (ctx) => {
|
bot.command('ban', async (ctx) => {
|
||||||
const info = await collectInfo(ctx);
|
const info = await collectInfo(ctx);
|
||||||
const { Strings, chatId, banId, isAdmin, onCrew } = info;
|
const { Strings, chatId, userId, isAdmin, onCrew } = info;
|
||||||
|
|
||||||
if (onCrew || isAdmin) {
|
if (onCrew || isAdmin) {
|
||||||
if (banId === NaN) {
|
if (userId === NaN) {
|
||||||
return ctx.reply(
|
return ctx.reply(
|
||||||
Strings.banInvalidId, {
|
Strings.invalidId, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
await ctx.telegram.kickChatMember(chatId, banId);
|
await ctx.telegram.kickChatMember(chatId, userId);
|
||||||
const banReport = Strings.banSuccess.replace('{banId}', banId);
|
const banReport = Strings.banSuccess.replace('{userId}', userId);
|
||||||
ctx.reply(
|
ctx.reply(
|
||||||
banReport, {
|
banReport, {
|
||||||
parse_mode: 'Markdown',
|
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
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
@ -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.",
|
"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.",
|
"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.",
|
"groupOnly": "This command should be used only on groups, and not on private chats.",
|
||||||
"banInvalidId": "Please enter a valid user ID.",
|
"invalidId": "Please enter a valid user ID.",
|
||||||
"banSuccess": "User with ID `{banId}` has been banned.",
|
"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}",
|
"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*!",
|
"isGay": "Yes, you are *gay*!",
|
||||||
"isNtGay": "Aahhh. You are not gay!",
|
"isNtGay": "Aahhh. You are not gay!",
|
||||||
"isFurry": "Yes, you are a freaky *furry*!",
|
"isFurry": "Yes, you are a freaky *furry*!",
|
||||||
|
@ -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.",
|
"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.",
|
"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.",
|
"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.",
|
"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}`",
|
"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*!",
|
"isGay": "Sim, você é *gay*!",
|
||||||
"isNtGay": "Aahhh. Você não é gay!",
|
"isNtGay": "Aahhh. Você não é gay!",
|
||||||
"isFurry": "Sim, você é um *furry* esquisito!",
|
"isFurry": "Sim, você é um *furry* esquisito!",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user