2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-09-01 14:45:27 +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' }); require('child_process').execSync('node init.js', { stdio: 'inherit' });
const { inspect } = require('util'); const { inspect } = require('util');
const print = value =>
console.log(inspect(value, { colors: true, depth: null }));
const Telegraf = require('telegraf'); const Telegraf = require('telegraf');
const { loadJSON } = require('./utils/json'); // Utils
const { link } = require('./utils/tg'); const { link } = require('./utils/tg');
const { loadJSON } = require('./utils/json');
const { print, logError } = require('./utils/log');
// DBs
const bans = require('./bans'); const bans = require('./bans');
const warns = require('./warns'); const warns = require('./warns');
const admins = require('./admins'); const admins = require('./admins');
const replyOptions = {
parse_mode: 'HTML',
disable_web_page_preview: true
};
const config = loadJSON('config.json'); const config = loadJSON('config.json');
const bot = new Telegraf(config.token); const bot = new Telegraf(config.token);
bot.use((ctx, next) => bot.use((ctx, next) =>
(print(ctx.update), next())); (print(ctx.update),
next()));
bot.command('warn', ({ message, reply }) => { bot.command('adminme', ctx =>
admins.isAdmin(message.from).then(isAdmin => { (admins.admin(ctx.from),
if (isAdmin) { ctx.reply('Admined!')));
if (message.reply_to_message) {
const userToWarn = message.reply_to_message.from; bot.command('warn', async ({ message, chat, reply }) => {
warns.warn(userToWarn, message.text) if (!await admins.isAdmin(message.from)) {
.then(warns => return;
reply( }
`${link(userToWarn)} warned! (${warns}/3)`, if (!message.reply_to_message) {
{ return;
parse_mode: 'HTML', }
disable_web_page_preview: true,
reply_to: message.reply_to_message.message_id 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(); bot.startPolling();

12
utils/log.js Normal file
View File

@@ -0,0 +1,12 @@
'use strict';
const logError = err =>
console.error(`${err.name}: ${err.message}`);
const print = value =>
console.log(inspect(value, { colors: true, depth: null }));
module.exports = {
logError,
print
};