mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-23 02:17:47 +00:00
111 lines
3.5 KiB
JavaScript
111 lines
3.5 KiB
JavaScript
'use strict';
|
|
|
|
// Utils
|
|
const { deleteAfter } = require('./utils/tg');
|
|
const { logError } = require('./utils/log');
|
|
|
|
/**
|
|
* @type {Telegraf}
|
|
* Bot
|
|
*/
|
|
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`);
|
|
|
|
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));
|
|
bot.command('admin', adminHandler);
|
|
bot.command('unadmin', unAdminHandler);
|
|
bot.command('leave', leaveCommandHandler);
|
|
bot.command('warn', warnHandler);
|
|
bot.command('unwarn', unwarnHandler);
|
|
bot.command('nowarns', nowarnsHandler);
|
|
bot.command('getwarns', getWarnsHandler);
|
|
bot.command('ban', banHandler);
|
|
bot.command('unban', unbanHandler);
|
|
bot.command('report', reportHandler);
|
|
bot.hears(/^@admins?\s?/i, reportHandler);
|
|
bot.command('staff', staffHandler);
|
|
bot.command('link', linkHandler);
|
|
bot.command('groups', groupsHandler);
|
|
bot.command('commands', commandReferenceHandler);
|
|
bot.command('addcommand', addCommandHandler);
|
|
bot.command('removecommand', removeCommandHandler);
|
|
bot.command([ 'start', 'help' ], helpHandler);
|
|
|
|
bot.catch(logError);
|
|
|
|
bot.startPolling();
|