Added self-kicking method for Crew

This commit is contained in:
Lucas Gabriel 2024-07-31 12:01:57 -03:00
parent ac11b53619
commit 0016357513
No known key found for this signature in database
GPG Key ID: D9B075FC6DC93985
3 changed files with 52 additions and 26 deletions

View File

@ -1,4 +1,3 @@
// specific commands to the crew
const Config = require('../props/config.json'); const Config = require('../props/config.json');
const { getStrings } = require('../plugins/checklang.js'); const { getStrings } = require('../plugins/checklang.js');
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
@ -63,18 +62,24 @@ module.exports = (bot) => {
const userId = ctx.from.id || Strings.unKnown; const userId = ctx.from.id || Strings.unKnown;
if (Config.admins.includes(userId)) { if (Config.admins.includes(userId)) {
const botName = ctx.message.text.split(' ').slice(1).join(' '); const botName = ctx.message.text.split(' ').slice(1).join(' ');
const botNameReport = Strings.botNameChanged.replace('{botName}', botName); const botNameReport = Strings.botNameChanged ? Strings.botNameChanged.replace('{botName}', botName) : `Bot name changed to ${botName}`;
ctx.telegram.setMyName(botName).catch(error => ctx.reply( try {
"Error when changing bot name:\n" + error, { await ctx.telegram.setMyName(botName);
reply_to_message_id: ctx.message.message_id ctx.reply(
} botNameReport, {
)); parse_mode: 'Markdown',
ctx.reply( reply_to_message_id: ctx.message.message_id
botNameReport, { }
parse_mode: 'Markdown', );
reply_to_message_id: ctx.message.message_id } catch (error) {
} const botNameErr = Strings.botNameErr ? Strings.botNameErr.replace('{tgErr}', error.message) : `Error setting bot name: ${error.message}`;
); ctx.reply(
botNameErr, {
parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id
}
);
}
} else { } else {
ctx.reply(Strings.botAdminOnly, { ctx.reply(Strings.botAdminOnly, {
reply_to_message_id: ctx.message.message_id reply_to_message_id: ctx.message.message_id
@ -87,18 +92,24 @@ module.exports = (bot) => {
const userId = ctx.from.id || Strings.unKnown; const userId = ctx.from.id || Strings.unKnown;
if (Config.admins.includes(userId)) { if (Config.admins.includes(userId)) {
const botDesc = ctx.message.text.split(' ').slice(1).join(' '); const botDesc = ctx.message.text.split(' ').slice(1).join(' ');
const botDescReport = Strings.botDescChanged.replace('{botDesc}', botDesc); const botDescReport = Strings.botDescChanged ? Strings.botDescChanged.replace('{botDesc}', botDesc) : `Bot description changed to ${botDesc}`;
ctx.telegram.setMyDescription(botDesc).catch(error => ctx.reply( try {
"Error when changing bot description:\n" + error, { await ctx.telegram.setMyDescription(botDesc);
reply_to_message_id: ctx.message.message_id ctx.reply(
} botDescReport, {
)); parse_mode: 'Markdown',
ctx.reply( reply_to_message_id: ctx.message.message_id
botDescReport, { }
parse_mode: 'Markdown', );
reply_to_message_id: ctx.message.message_id } catch (error) {
} const botDescErr = Strings.botDescErr ? Strings.botDescErr.replace('{tgErr}', error.message) : `Error setting bot description: ${error.message}`;
); ctx.reply(
botDescErr, {
parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id
}
);
}
} else { } else {
ctx.reply( ctx.reply(
Strings.botAdminOnly, { Strings.botAdminOnly, {
@ -106,4 +117,15 @@ module.exports = (bot) => {
}); });
} }
}); });
bot.command('botkickme', spamwatchMiddleware, async (ctx) => {
const Strings = getStrings(ctx.from.language_code);
const chatId = ctx.chat.id || Strings.unKnown;
ctx.reply(
Strings.kickingMyself, {
parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id
});
ctx.telegram.leaveChat(chatId);
});
}; };

View File

@ -6,12 +6,15 @@
"varYes": "Yes", "varYes": "Yes",
"varNo": "No", "varNo": "No",
"varNone": "None", "varNone": "None",
"kickingMyself": "*Since you don't need me, I'll get out of here.*",
"noPermission": "You don't have permissions to run this command.", "noPermission": "You don't have permissions to run this command.",
"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.",
"botNameChanged": "*Bot name changed to* `{botName}`", "botNameChanged": "*Bot name changed to* `{botName}`",
"botNameErr": "*Error when changing bot name:*\n\n{tgErr}",
"botDescChanged": "*Bot description changed to* `{botDesc}`", "botDescChanged": "*Bot description changed to* `{botDesc}`",
"botDescErr": "*Error when changing bot description:*\n\n{tgErr}",
"invalidId": "Please enter a valid user ID.", "invalidId": "Please enter a valid user ID.",
"banSuccess": "User with ID `{userId}` 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}",

View File

@ -6,6 +6,7 @@
"varYes": "Sim", "varYes": "Sim",
"varNo": "Não", "varNo": "Não",
"varNone": "Nenhum", "varNone": "Nenhum",
"kickingMyself": "*Já que você não precisa de mim, vou ir embora.*",
"noPermission": "Você não tem permissões para rodar esse comando.", "noPermission": "Você não tem permissões para rodar esse comando.",
"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.",