2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-31 06:05:22 +00:00
This commit is contained in:
Thomas Rory Gummerson
2017-07-24 14:44:42 +02:00
parent bcee0c4aa7
commit f55c834a02
2 changed files with 51 additions and 23 deletions

View File

@@ -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();