2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-23 02:17:47 +00:00
the-guard-bot/index.js

111 lines
3.5 KiB
JavaScript
Raw Normal View History

2017-07-24 17:12:38 +02:00
'use strict';
// Utils
2017-09-21 13:57:49 +04:30
const { deleteAfter } = require('./utils/tg');
const { logError } = require('./utils/log');
2017-09-21 13:57:49 +04:30
/**
* @type {Telegraf}
* Bot
*/
2017-09-21 13:57:49 +04:30
const bot = require('./bot');
bot.telegram.getMe().then((botInfo) => {
bot.options.username = botInfo.username;
});
/**
* @type {number}
* Time in milliseconds after which join and leave messages should be deleted
*/
const delTimeout = 2 * 60 * 1000;
/**
* @type {string}
* Path of middlewares and commands
*/
const middleware = './handlers/middlewares';
const message = './handlers/messages';
const command = './handlers/commands';
/**
* @type {function}
* Middleware Handlers
*/
const leaveUnmanagedHandler = require(`${middleware}/leaveUnmanaged`);
const removeCommandsHandler = require(`${middleware}/removeCommands`);
const kickBannedHandler = require(`${middleware}/kickBanned`);
const syncStatusHandler = require(`${middleware}/syncStatus`);
const antibotHandler = require(`${middleware}/antibot`);
const addedToGroupHandler = require(`${middleware}/addedToGroup`);
/**
* @type {function}
* Messages Handlers
*/
const addUserHandler = require(`${message}/addUser`);
const removeLinksHandler = require(`${message}/removeLinks`);
const checkUsernameHandler = require(`${message}/checkUsername`);
const addCustomCmdHandler = require(`${message}/addCustomCmd`);
const runCustomCmdHandler = require(`${message}/runCustomCmd`);
/**
* @type {function}
* Commmands Handlers
*/
const adminHandler = require(`${command}/admin`);
const unAdminHandler = require(`${command}/unadmin`);
const leaveCommandHandler = require(`${command}/leave`);
const warnHandler = require(`${command}/warn`);
const unwarnHandler = require(`${command}/unwarn`);
const nowarnsHandler = require(`${command}/nowarns`);
const getWarnsHandler = require(`${command}/getwarns`);
const banHandler = require(`${command}/ban`);
const unbanHandler = require(`${command}/unban`);
const reportHandler = require(`${command}/report`);
const staffHandler = require(`${command}/staff`);
const linkHandler = require(`${command}/link`);
const groupsHandler = require(`${command}/groups`);
const commandReferenceHandler = require(`${command}/commands`);
const addCommandHandler = require(`${command}/addCommand`);
const removeCommandHandler = require(`${command}/removeCommand`);
const helpHandler = require(`${command}/help`);
2017-09-21 13:57:49 +04:30
bot.on('new_chat_members', addedToGroupHandler);
bot.use(leaveUnmanagedHandler);
bot.use(removeCommandsHandler);
bot.use(kickBannedHandler);
bot.on('message',
addUserHandler,
removeLinksHandler,
checkUsernameHandler,
addCustomCmdHandler,
runCustomCmdHandler
);
bot.on('new_chat_members', syncStatusHandler);
bot.on('new_chat_members', antibotHandler);
bot.on([ 'new_chat_members', 'left_chat_member' ], deleteAfter(delTimeout));
2017-09-21 13:57:49 +04:30
bot.command('admin', adminHandler);
bot.command('unadmin', unAdminHandler);
2017-09-28 22:59:35 +02:00
bot.command('leave', leaveCommandHandler);
2017-09-21 13:57:49 +04:30
bot.command('warn', warnHandler);
bot.command('unwarn', unwarnHandler);
2017-09-21 23:47:26 +04:30
bot.command('nowarns', nowarnsHandler);
bot.command('getwarns', getWarnsHandler);
bot.command('ban', banHandler);
bot.command('unban', unbanHandler);
2017-09-23 20:57:32 +02:00
bot.command('report', reportHandler);
2017-10-08 11:40:42 +03:30
bot.hears(/^@admins?\s?/i, reportHandler);
2017-09-24 18:05:16 +02:00
bot.command('staff', staffHandler);
2017-10-02 12:09:44 +03:30
bot.command('link', linkHandler);
2017-09-24 23:23:36 +02:00
bot.command('groups', groupsHandler);
2017-09-27 22:17:07 +02:00
bot.command('commands', commandReferenceHandler);
2017-10-04 20:55:50 +03:30
bot.command('addcommand', addCommandHandler);
bot.command('removecommand', removeCommandHandler);
2017-09-28 15:41:06 +03:30
bot.command([ 'start', 'help' ], helpHandler);
2017-07-24 18:08:31 +02:00
bot.catch(logError);
2017-09-24 18:34:32 +02:00
2017-07-24 17:12:38 +02:00
bot.startPolling();