Unban system + changed ban command
This commit is contained in:
parent
1d6e569cae
commit
d4c236ed9d
3 changed files with 60 additions and 14 deletions
|
@ -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
|
||||
}
|
||||
);
|
||||
};
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue