mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-31 06:05:22 +00:00
Cleanup
This commit is contained in:
62
index.js
62
index.js
@@ -4,43 +4,59 @@
|
||||
require('child_process').execSync('node init.js', { stdio: 'inherit' });
|
||||
|
||||
const { inspect } = require('util');
|
||||
|
||||
const print = value =>
|
||||
console.log(inspect(value, { colors: true, depth: null }));
|
||||
|
||||
const Telegraf = require('telegraf');
|
||||
|
||||
const { loadJSON } = require('./utils/json');
|
||||
// Utils
|
||||
const { link } = require('./utils/tg');
|
||||
const { loadJSON } = require('./utils/json');
|
||||
const { print, logError } = require('./utils/log');
|
||||
|
||||
// DBs
|
||||
const bans = require('./bans');
|
||||
const warns = require('./warns');
|
||||
const admins = require('./admins');
|
||||
|
||||
const replyOptions = {
|
||||
parse_mode: 'HTML',
|
||||
disable_web_page_preview: true
|
||||
};
|
||||
|
||||
const config = loadJSON('config.json');
|
||||
|
||||
const bot = new Telegraf(config.token);
|
||||
|
||||
bot.use((ctx, next) =>
|
||||
(print(ctx.update), next()));
|
||||
(print(ctx.update),
|
||||
next()));
|
||||
|
||||
bot.command('warn', ({ message, reply }) => {
|
||||
admins.isAdmin(message.from).then(isAdmin => {
|
||||
if (isAdmin) {
|
||||
if (message.reply_to_message) {
|
||||
const userToWarn = message.reply_to_message.from;
|
||||
warns.warn(userToWarn, message.text)
|
||||
.then(warns =>
|
||||
reply(
|
||||
`${link(userToWarn)} warned! (${warns}/3)`,
|
||||
{
|
||||
parse_mode: 'HTML',
|
||||
disable_web_page_preview: true,
|
||||
reply_to: message.reply_to_message.message_id
|
||||
}));
|
||||
}
|
||||
}
|
||||
});
|
||||
bot.command('adminme', ctx =>
|
||||
(admins.admin(ctx.from),
|
||||
ctx.reply('Admined!')));
|
||||
|
||||
bot.command('warn', async ({ message, chat, reply }) => {
|
||||
if (!await admins.isAdmin(message.from)) {
|
||||
return;
|
||||
}
|
||||
if (!message.reply_to_message) {
|
||||
return;
|
||||
}
|
||||
|
||||
const messageToWarn = message.reply_to_message;
|
||||
const userToWarn = messageToWarn.from;
|
||||
const reason = message.text.split(' ').slice(1).join(' ').trim();
|
||||
|
||||
if (reason.length === 0) {
|
||||
return reply('Need a reason');
|
||||
}
|
||||
|
||||
const warnCount = await warns.warn(userToWarn, reason);
|
||||
return Promise.all([
|
||||
bot.telegram.deleteMessage(chat.id, messageToWarn.message_id),
|
||||
bot.telegram.deleteMessage(chat.id, message.message_id),
|
||||
reply(
|
||||
`${link(userToWarn)} warned! (${warnCount}/3)\nReason: ${reason}`,
|
||||
replyOptions)
|
||||
]).catch(logError);
|
||||
});
|
||||
|
||||
bot.startPolling();
|
||||
|
Reference in New Issue
Block a user