mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 12:49:57 +00:00
Better error handling + more commands + code optimization
This commit is contained in:
parent
e4c8327117
commit
96f915838d
67
bot.js
67
bot.js
@ -1,27 +1,80 @@
|
|||||||
const { Telegraf } = require('telegraf');
|
const { Telegraf } = require('telegraf');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
const Config = require('./props/config.json');
|
const Config = require('./props/config.json');
|
||||||
const { isOnSpamWatch } = require('./plugins/lib-spamwatch/spamwatch.js');
|
const { isOnSpamWatch } = require('./plugins/lib-spamwatch/spamwatch.js');
|
||||||
|
|
||||||
const bot = new Telegraf(Config.botToken);
|
const bot = new Telegraf(Config.botToken);
|
||||||
|
const MAX_RETRIES = 5;
|
||||||
|
let restartCount = 0;
|
||||||
|
|
||||||
|
|
||||||
const loadCommands = () => {
|
const loadCommands = () => {
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const commandsPath = path.join(__dirname, 'commands');
|
const commandsPath = path.join(__dirname, 'commands');
|
||||||
|
|
||||||
|
try {
|
||||||
fs.readdirSync(commandsPath).forEach((file) => {
|
fs.readdirSync(commandsPath).forEach((file) => {
|
||||||
|
try {
|
||||||
const command = require(path.join(commandsPath, file));
|
const command = require(path.join(commandsPath, file));
|
||||||
if (typeof command === 'function') {
|
if (typeof command === 'function') {
|
||||||
command(bot, isOnSpamWatch);
|
command(bot, isOnSpamWatch);
|
||||||
}
|
}
|
||||||
|
} catch (fileError) {
|
||||||
|
console.error(`Failed to load command file ${file}: ${fileError.message}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (dirError) {
|
||||||
|
console.error(`Failed to read commands directory: ${dirError.message}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const sendMessage = async (ctx, text, options = {}) => {
|
||||||
|
try {
|
||||||
|
await ctx.reply(text, options);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error sending message:', error.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Função para iniciar o bot
|
||||||
|
const startBot = async () => {
|
||||||
|
try {
|
||||||
|
await bot.launch();
|
||||||
|
console.log('Bot is running...');
|
||||||
|
restartCount = 0;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to start bot:', error.message);
|
||||||
|
if (restartCount < MAX_RETRIES) {
|
||||||
|
restartCount++;
|
||||||
|
console.log(`Retrying to start bot... Attempt ${restartCount}`);
|
||||||
|
setTimeout(startBot, 5000);
|
||||||
|
} else {
|
||||||
|
console.error('Maximum retry attempts reached. Exiting.');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleShutdown = (signal) => {
|
||||||
|
console.log(`Received ${signal}. Stopping bot...`);
|
||||||
|
bot.stop(signal).then(() => {
|
||||||
|
console.log('Bot stopped.');
|
||||||
|
process.exit(0);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
loadCommands();
|
process.once('SIGINT', () => handleShutdown('SIGINT'));
|
||||||
|
process.once('SIGTERM', () => handleShutdown('SIGTERM'));
|
||||||
|
|
||||||
bot.launch().then(() => {
|
process.on('uncaughtException', (error) => {
|
||||||
console.log('Bot está rodando...');
|
console.error('Uncaught Exception:', error.message);
|
||||||
|
console.error(error.stack);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.once('SIGINT', () => bot.stop('SIGINT'));
|
process.on('unhandledRejection', (reason, promise) => {
|
||||||
process.once('SIGTERM', () => bot.stop('SIGTERM'));
|
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
||||||
|
});
|
||||||
|
|
||||||
|
loadCommands();
|
||||||
|
startBot();
|
||||||
|
@ -15,88 +15,50 @@ async function collectInfo(ctx) {
|
|||||||
return { Strings, chatId, userId, isAdmin, onCrew };
|
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) => {
|
module.exports = (bot) => {
|
||||||
bot.command('ban', spamwatchMiddleware, async (ctx) => {
|
bot.command('ban', spamwatchMiddleware, (ctx) => {
|
||||||
const info = await collectInfo(ctx);
|
handleMember(ctx, (chatId, userId) => ctx.telegram.kickChatMember(chatId, userId),
|
||||||
const { Strings, chatId, userId, isAdmin, onCrew } = info;
|
getStrings(ctx.from.language_code).banSuccess,
|
||||||
|
getStrings(ctx.from.language_code).banErr
|
||||||
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.kickChatMember(chatId, userId);
|
|
||||||
const banReport = Strings.banSuccess.replace('{userId}', userId);
|
|
||||||
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
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('unban', spamwatchMiddleware, async (ctx) => {
|
bot.command('unban', spamwatchMiddleware, (ctx) => {
|
||||||
const info = await collectInfo(ctx);
|
handleMember(ctx, (chatId, userId) => ctx.telegram.unbanChatMember(chatId, userId),
|
||||||
const { Strings, chatId, userId, isAdmin, onCrew } = info;
|
getStrings(ctx.from.language_code).unBanSuccess,
|
||||||
|
getStrings(ctx.from.language_code).unBanErr
|
||||||
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
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
};
|
};
|
130
commands/crew.js
130
commands/crew.js
@ -12,120 +12,76 @@ function formatUptime(uptime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSystemInfo() {
|
function getSystemInfo() {
|
||||||
const platform = os.platform();
|
const { platform, release, arch, cpus, totalmem, freemem, loadavg, uptime } = os;
|
||||||
const release = os.release();
|
const [cpu] = cpus();
|
||||||
const arch = os.arch();
|
|
||||||
const cpuModel = os.cpus()[0].model;
|
|
||||||
const cpuCores = os.cpus().length;
|
|
||||||
const totalMemory = (os.totalmem() / (1024 ** 3)).toFixed(2) + ' GB';
|
|
||||||
const freeMemory = (os.freemem() / (1024 ** 3)).toFixed(2) + ' GB';
|
|
||||||
const loadAverage = os.loadavg().map(avg => avg.toFixed(2)).join(', ');
|
|
||||||
const uptime = formatUptime(os.uptime());
|
|
||||||
const nodeVersion = process.version;
|
|
||||||
|
|
||||||
return `*Server Stats*\n\n` +
|
return `*Server Stats*\n\n` +
|
||||||
`*OS:* \`${platform} ${release}\`\n` +
|
`*OS:* \`${platform()} ${release()}\`\n` +
|
||||||
`*Arch:* \`${arch}\`\n` +
|
`*Arch:* \`${arch()}\`\n` +
|
||||||
`*Node.js Version:* \`${nodeVersion}\`\n` +
|
`*Node.js Version:* \`${process.version}\`\n` +
|
||||||
`*CPU:* \`${cpuModel}\`\n` +
|
`*CPU:* \`${cpu.model}\`\n` +
|
||||||
`*CPU Cores:* \`${cpuCores} cores\`\n` +
|
`*CPU Cores:* \`${cpus().length} cores\`\n` +
|
||||||
`*RAM:* \`${freeMemory} / ${totalMemory}\`\n` +
|
`*RAM:* \`${(freemem() / (1024 ** 3)).toFixed(2)} GB / ${(totalmem() / (1024 ** 3)).toFixed(2)} GB\`\n` +
|
||||||
`*Load Average:* \`${loadAverage}\`\n` +
|
`*Load Average:* \`${loadavg().map(avg => avg.toFixed(2)).join(', ')}\`\n` +
|
||||||
`*Uptime:* \`${uptime}\`\n\n`;
|
`*Uptime:* \`${formatUptime(uptime())}\`\n\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleAdminCommand(ctx, action, successMessage, errorMessage) {
|
||||||
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
|
const userId = ctx.from.id;
|
||||||
|
if (Config.admins.includes(userId)) {
|
||||||
|
try {
|
||||||
|
await action();
|
||||||
|
ctx.reply(successMessage, {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
ctx.reply(errorMessage.replace('{error}', error.message), {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.reply(Strings.botAdminOnly, {
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (bot) => {
|
module.exports = (bot) => {
|
||||||
bot.command('getbotstats', spamwatchMiddleware, async (ctx) => {
|
bot.command('getbotstats', spamwatchMiddleware, async (ctx) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
const userId = ctx.from.id || Strings.unKnown;
|
handleAdminCommand(ctx, async () => {
|
||||||
if (Config.admins.includes(userId)) {
|
const stats = getSystemInfo();
|
||||||
const machineStats = getSystemInfo();
|
await ctx.reply(stats, {
|
||||||
ctx.reply(
|
|
||||||
machineStats, {
|
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
}
|
|
||||||
).catch(error => ctx.reply(
|
|
||||||
"Error when getting server status:\n" + error, {
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
}
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
ctx.reply(Strings.botAdminOnly, {
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
}
|
}, '', Strings.errorRetrievingStats); // No success message
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('setbotname', spamwatchMiddleware, async (ctx) => {
|
bot.command('setbotname', spamwatchMiddleware, async (ctx) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
const userId = ctx.from.id || Strings.unKnown;
|
|
||||||
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 ? Strings.botNameChanged.replace('{botName}', botName) : `Bot name changed to ${botName}`;
|
handleAdminCommand(ctx, async () => {
|
||||||
try {
|
|
||||||
await ctx.telegram.setMyName(botName);
|
await ctx.telegram.setMyName(botName);
|
||||||
ctx.reply(
|
}, Strings.botNameChanged.replace('{botName}', botName), Strings.botNameErr.replace('{tgErr}', '{error}'));
|
||||||
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 {
|
|
||||||
ctx.reply(Strings.botAdminOnly, {
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('setbotdesc', spamwatchMiddleware, async (ctx) => {
|
bot.command('setbotdesc', spamwatchMiddleware, async (ctx) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
const userId = ctx.from.id || Strings.unKnown;
|
|
||||||
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 ? Strings.botDescChanged.replace('{botDesc}', botDesc) : `Bot description changed to ${botDesc}`;
|
handleAdminCommand(ctx, async () => {
|
||||||
try {
|
|
||||||
await ctx.telegram.setMyDescription(botDesc);
|
await ctx.telegram.setMyDescription(botDesc);
|
||||||
ctx.reply(
|
}, Strings.botDescChanged.replace('{botDesc}', botDesc), Strings.botDescErr.replace('{tgErr}', '{error}'));
|
||||||
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 {
|
|
||||||
ctx.reply(
|
|
||||||
Strings.botAdminOnly, {
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('botkickme', spamwatchMiddleware, async (ctx) => {
|
bot.command('botkickme', spamwatchMiddleware, async (ctx) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
const chatId = ctx.chat.id || Strings.unKnown;
|
ctx.reply(Strings.kickingMyself, {
|
||||||
ctx.reply(
|
|
||||||
Strings.kickingMyself, {
|
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
ctx.telegram.leaveChat(chatId);
|
await ctx.telegram.leaveChat(ctx.chat.id);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -3,69 +3,73 @@ const { getStrings } = require('../plugins/checklang.js');
|
|||||||
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
||||||
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
||||||
|
|
||||||
function furryFunction(ctx) {
|
function sendRandomReply(ctx, gifUrl, textKey, notTextKey) {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
if (Math.random() < 0.5 ? "yes" : "no" === "yes") {
|
const shouldSendGif = Math.random() < 0.5;
|
||||||
ctx.replyWithAnimation(
|
|
||||||
resources.furryGif, {
|
if (shouldSendGif) {
|
||||||
caption: Strings.isFurry,
|
ctx.replyWithAnimation(gifUrl, {
|
||||||
|
caption: Strings[textKey],
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
}
|
}).catch(err => {
|
||||||
);
|
gifErr = gifErr.replace('{err}', err);
|
||||||
|
|
||||||
|
ctx.reply(Strings.gifErr, {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
ctx.reply(
|
ctx.reply(Strings[notTextKey], {
|
||||||
Strings.isNtFurry, {
|
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function gayFunction(ctx) {
|
|
||||||
|
async function handleDiceCommand(ctx, emoji, delay) {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
if (Math.random() < 0.5 ? "yes" : "no" === "yes") {
|
|
||||||
ctx.replyWithAnimation(
|
const result = await ctx.sendDice({ emoji, reply_to_message_id: ctx.message.message_id });
|
||||||
resources.gayFlag, {
|
const botResponse = Strings.funEmojiResult
|
||||||
caption: Strings.isGay,
|
.replace('{emoji}', result.dice.emoji)
|
||||||
|
.replace('{value}', result.dice.value);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
ctx.reply(botResponse, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
}
|
});
|
||||||
);
|
}, delay);
|
||||||
} else {
|
|
||||||
ctx.reply(
|
|
||||||
Strings.isNtGay, {
|
|
||||||
parse_mode: 'Markdown',
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (bot) => {
|
module.exports = (bot) => {
|
||||||
bot.command('dice', spamwatchMiddleware, async (ctx) => {
|
bot.command('dice', spamwatchMiddleware, async (ctx) => {
|
||||||
ctx.telegram.sendDice(
|
await handleDiceCommand(ctx, undefined, 4000);
|
||||||
ctx.chat.id, {
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('slot', spamwatchMiddleware, async (ctx) => {
|
bot.command('slot', spamwatchMiddleware, async (ctx) => {
|
||||||
ctx.telegram.sendDice(
|
await handleDiceCommand(ctx, '🎰', 3000);
|
||||||
ctx.chat.id, {
|
});
|
||||||
emoji: '🎰',
|
|
||||||
|
bot.command('ball', spamwatchMiddleware, async (ctx) => {
|
||||||
|
await handleDiceCommand(ctx, '⚽', 3000);
|
||||||
|
});
|
||||||
|
|
||||||
|
bot.command('idice', spamwatchMiddleware, async (ctx) => {
|
||||||
|
const stickerId = "CAACAgQAAxkBAAJxjWbSSP-8ZNEhEpAJjQsHsGf-UuEPAAJCAAPI-uwTAAEBVWWh4ucINQQ";
|
||||||
|
ctx.replyWithSticker(stickerId, {
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
}
|
});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('furry', spamwatchMiddleware, async (ctx) => {
|
bot.command('furry', spamwatchMiddleware, async (ctx) => {
|
||||||
furryFunction(ctx);
|
sendRandomReply(ctx, resources.furryGif, 'isFurry', 'isNtFurry');
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('gay', spamwatchMiddleware, async (ctx) => {
|
bot.command('gay', spamwatchMiddleware, async (ctx) => {
|
||||||
gayFunction(ctx);
|
sendRandomReply(ctx, resources.gayFlag, 'isGay', 'isNtGay');
|
||||||
});
|
});
|
||||||
};
|
};
|
@ -4,48 +4,29 @@ const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(is
|
|||||||
|
|
||||||
async function getUserInfo(ctx) {
|
async function getUserInfo(ctx) {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
let userInfoTemplate = Strings.userInfo;
|
|
||||||
|
|
||||||
const userName = ctx.from.first_name || Strings.unKnown;
|
userInfo = Strings.userInfo
|
||||||
const userId = ctx.from.id || Strings.unKnown;
|
.replace('{userName}', ctx.from.first_name || Strings.unKnown)
|
||||||
const userHandle = ctx.from.username ? `@${ctx.from.username}` : Strings.varNone;
|
.replace('{userId}', ctx.from.id || Strings.unKnown)
|
||||||
const isBot = ctx.from.is_bot ? Strings.varYes : Strings.varNo;
|
.replace('{userHandle}', ctx.from.username ? `@${ctx.from.username}` : Strings.varNone)
|
||||||
const userPremium = ctx.from.is_premium ? Strings.varYes : Strings.varNo;
|
.replace('{userPremium}', ctx.from.is_premium ? Strings.varYes : Strings.varNo)
|
||||||
const userLang = ctx.from.language_code || Strings.unKnown;
|
.replace('{userLang}', ctx.from.language_code || Strings.unKnown);
|
||||||
|
|
||||||
userInfoTemplate = userInfoTemplate
|
return userInfo;
|
||||||
.replace('{userName}', userName)
|
|
||||||
.replace('{userId}', userId)
|
|
||||||
.replace('{userHandle}', userHandle)
|
|
||||||
.replace('{isBot}', isBot)
|
|
||||||
.replace('{userPremium}', userPremium)
|
|
||||||
.replace('{userLang}', userLang);
|
|
||||||
|
|
||||||
return userInfoTemplate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getChatInfo(ctx) {
|
async function getChatInfo(ctx) {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
if (ctx.chat.type === 'group' || ctx.chat.type === 'supergroup') {
|
if (ctx.chat.type === 'group' || ctx.chat.type === 'supergroup') {
|
||||||
let chatInfoTemplate = Strings.chatInfo;
|
chatInfo = Strings.chatInfo
|
||||||
|
.replace('{chatId}', ctx.chat.id || Strings.unKnown)
|
||||||
|
.replace('{chatName}', ctx.chat.title || Strings.unKnown)
|
||||||
|
.replace('{chatHandle}', ctx.chat.username ? `@${ctx.chat.username}` : Strings.varNone)
|
||||||
|
.replace('{chatMembersCount}', await ctx.getChatMembersCount(ctx.chat.id || Strings.unKnown))
|
||||||
|
.replace('{chatType}', ctx.chat.type || Strings.unKnown)
|
||||||
|
.replace('{isForum}', ctx.chat.is_forum ? Strings.varYes : Strings.varNo);
|
||||||
|
|
||||||
const chatId = ctx.chat.id || Strings.unKnown;
|
return chatInfo;
|
||||||
const chatName = ctx.chat.title;
|
|
||||||
const chatHandle = ctx.chat.username ? `@${ctx.chat.username}` : Strings.varNone;
|
|
||||||
const chatType = ctx.chat.type || Strings.unKnown;
|
|
||||||
|
|
||||||
const chatMembersCount = await ctx.telegram.getChatMembersCount(chatId);
|
|
||||||
const isForum = ctx.chat.is_forum ? Strings.varYes : Strings.varNo;
|
|
||||||
|
|
||||||
chatInfoTemplate = chatInfoTemplate
|
|
||||||
.replace('{chatId}', chatId)
|
|
||||||
.replace('{chatName}', chatName)
|
|
||||||
.replace('{chatHandle}', chatHandle)
|
|
||||||
.replace('{chatMembersCount}', chatMembersCount)
|
|
||||||
.replace('{chatType}', chatType)
|
|
||||||
.replace('{isForum}', isForum);
|
|
||||||
|
|
||||||
return chatInfoTemplate;
|
|
||||||
} else {
|
} else {
|
||||||
return ctx.reply(
|
return ctx.reply(
|
||||||
Strings.groupOnly, {
|
Strings.groupOnly, {
|
||||||
|
@ -11,10 +11,10 @@
|
|||||||
"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}",
|
"botNameErr": "*Error when changing bot name:*\n{tgErr}",
|
||||||
"botDescChanged": "*Bot description changed to* `{botDesc}`",
|
"botDescChanged": "*Bot description changed to* `{botDesc}.`",
|
||||||
"botDescErr": "*Error when changing bot description:*\n\n{tgErr}",
|
"botDescErr": "*Error when changing bot description:*\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}",
|
||||||
@ -22,9 +22,11 @@
|
|||||||
"unBanErr": "Could not unban the user. Please check if the ID is correct and if the bot has admin permissions.\n\n{tgErr}",
|
"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 *furry*!",
|
||||||
"isNtFurry": "Aahhh. You are not a furry!",
|
"isNtFurry": "Aahhh. You are not a furry!",
|
||||||
"randomNum": "*Generated number (0-10):* `{number}`",
|
"randomNum": "*Generated number (0-10):* `{number}.`",
|
||||||
"userInfo": "*User info*\n\n*Your name is:* `{userName}`\n*Your username is:* `{userHandle}`\n*Your ID is:* `{userId}`\n*You are a bot:* `{isBot}`\n*Your language:* `{userLang}`\n*You are a Premium user:* `{userPremium}`",
|
"userInfo": "*User info*\n\n*Name:* `{userName}`\n*Username:* `{userHandle}`\n*User ID:* `{userId}`\n*Language:* `{userLang}`\n*Premium user:* `{userPremium}`",
|
||||||
"chatInfo": "*Group info*\n\n*Chat name:* `{chatName}`\n*Chat ID:* `{chatId}`\n*Chat handle:* `{chatHandle}`\n*Chat type:* `{chatType}`\n*Chat members count:* `{chatMembersCount}`\n*Is a forum:* `{isForum}`"
|
"chatInfo": "*Chat info*\n\n*Name:* `{chatName}`\n*Chat ID:* `{chatId}`\n*Handle:* `{chatHandle}`\n*Type:* `{chatType}`\n*Members:* `{chatMembersCount}`\n*Is a forum:* `{isForum}`",
|
||||||
|
"funEmojiResult": "*You rolled {emoji} and got *`{value}`*!*\nYou don't know what that means? Me too!",
|
||||||
|
"gifErr": "*Something went wrong while sending the GIF. Please try again later.*\n\n{err}"
|
||||||
}
|
}
|
@ -11,10 +11,10 @@
|
|||||||
"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.",
|
||||||
"botNameChanged": "*Nome do bot alterado para* `{botName}`",
|
"botNameChanged": "*Nome do bot alterado para* `{botName}.`",
|
||||||
"botNameErr": "*Erro ao alterar o nome do bot:*\n\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\n`{tgErr}`",
|
"botDescErr": "*Erro ao alterar a descrição do bot:*\n`{tgErr}`",
|
||||||
"invalidId": "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 `{userId}` foi banido.",
|
"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}`",
|
"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}`",
|
||||||
@ -22,9 +22,11 @@
|
|||||||
"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}`",
|
"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ê é *furry*!",
|
||||||
"isNtFurry": "Aahhh. Você não é um furry!",
|
"isNtFurry": "Aahhh. Você não é um furry!",
|
||||||
"randomNum": "*Número gerado (0-10):* `{number}`",
|
"randomNum": "*Número gerado (0-10):* `{number}.`",
|
||||||
"userInfo": "*Informações do usuário*\n\n*Seu nome é:* `{userName}`\n*Seu usuário é:* `{userHandle}`\n*Seu ID é:* `{userId}`\n*Você é um bot:* `{isBot}`\n*Seu idioma:* `{userLang}`\n*Você é um usuário premium:* `{userPremium}`",
|
"userInfo": "*Informações do usuário*\n\n*Nome:* `{userName}`\n*Usuário:* `{userHandle}`\n*ID:* `{userId}`\n*Idioma:* `{userLang}`\n*Usuário Premium:* `{userPremium}`",
|
||||||
"chatInfo": "*Informações do chat*\n\n*Nome do chat:* `{chatName}`\n*ID do chat:* `{chatId}`\n*Identificador:* `{chatHandle}`\n*Tipo de chat:* `{chatType}`\n*Número de membros:* `{chatMembersCount}`\n*É um fórum:* `{isForum}`"
|
"chatInfo": "*Informações do chat*\n\n*Nome:* `{chatName}`\n*ID do chat:* `{chatId}`\n*Identificador:* `{chatHandle}`\n*Tipo:* `{chatType}`\n*Membros:* `{chatMembersCount}`\n*É um fórum:* `{isForum}`",
|
||||||
|
"funEmojiResult": "*Você lançou {emoji} e obteve *`{value}`*!*\nVocê não sabe o que isso significa? Nem eu!",
|
||||||
|
"gifErr": "*Algo deu errado ao enviar o GIF. Tente novamente mais tarde.*\n\n{err}"
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user