2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-09-03 15:45:20 +00:00
This commit is contained in:
Thomas Rory Gummerson
2017-07-24 15:06:12 +02:00
parent f55c834a02
commit 9bd52ba77f
3 changed files with 39 additions and 11 deletions

View File

@@ -26,5 +26,6 @@ const isBanned = user =>
module.exports = {
ban,
unban
unban,
isBanned
};

View File

@@ -1,9 +1,10 @@
'use strict';
const DEBUG = false;
// validate config
require('child_process').execSync('node init.js', { stdio: 'inherit' });
const { inspect } = require('util');
const Telegraf = require('telegraf');
// Utils
@@ -25,9 +26,20 @@ const config = loadJSON('config.json');
const bot = new Telegraf(config.token);
bot.use((ctx, next) =>
(print(ctx.update),
next()));
bot.use(async (ctx, next) => {
DEBUG && print(ctx.update);
const banned = await bans.isBanned(ctx.from);
if (banned) {
return bot.telegram.kickChatMember(ctx.chat.id, ctx.from.id)
.then(() => reply(
`${link(ctx.from)} <b>banned</b>!\n` +
`Reason: ${banned}`,
replyOptions))
.catch(logError)
.then(next);
}
return next();
});
bot.command('adminme', ctx =>
(admins.admin(ctx.from),
@@ -50,13 +62,26 @@ bot.command('warn', async ({ message, chat, reply }) => {
}
const warnCount = await warns.warn(userToWarn, reason);
return Promise.all([
const promises = [
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.telegram.deleteMessage(chat.id, message.message_id)
];
if (warnCount < 3) {
promises.push(reply(
`${link(userToWarn)} warned! (${warnCount}/3)\n` +
`Reason: ${reason}`,
replyOptions));
} else {
promises.push(bot.telegram.kickChatMember(chat.id, userToWarn.id));
promises.push(bans.ban(userToWarn, 'Reached max number of warnings'));
promises.push(reply(
`${link(userToWarn)} <b>banned</b>! (${warnCount}/3)\n` +
`Reason: Reached max number of warnings`,
replyOptions));
}
return Promise.all(promises).catch(logError);
});
bot.startPolling();

View File

@@ -1,5 +1,7 @@
'use strict';
const { inspect } = require('util');
const logError = err =>
console.error(`${err.name}: ${err.message}`);