2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-30 13:47:54 +00:00

Added /leave

This commit is contained in:
GingerPlusPlus
2017-09-28 22:59:35 +02:00
parent 36f4180ebe
commit fdfbfa5727
5 changed files with 24 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ Command | Rule | Description
-------- | ------ | ----------- -------- | ------ | -----------
`/admin` | _Master_ | Makes the user admin. `/admin` | _Master_ | Makes the user admin.
`/unadmin` | _Master_ | Demotes the user from admin list. `/unadmin` | _Master_ | Demotes the user from admin list.
`/leave` | _Master_ | Makes the bot leave the group cleanly.
`/warn <reason>` | _Admin_ | Warns the user. `/warn <reason>` | _Admin_ | Warns the user.
`/unwarn` | _Admin_ | Removes the last warn from the user. `/unwarn` | _Admin_ | Removes the last warn from the user.
`/nowarns` | _Admin_ | Clears warns for the user. `/nowarns` | _Admin_ | Clears warns for the user.

View File

@@ -4,6 +4,7 @@ const commandReference = `\
<b>Master commands</b>: <b>Master commands</b>:
<code>/admin</code> - Makes the user admin. <code>/admin</code> - Makes the user admin.
<code>/unadmin</code> - Demotes the user from admin list. <code>/unadmin</code> - Demotes the user from admin list.
<code>/leave</code> - Makes the bot leave the group cleanly.
<b>Admin commands</b>: <b>Admin commands</b>:
<code>/warn &lt;reason&gt;</code> - Warns the user. <code>/warn &lt;reason&gt;</code> - Warns the user.

View File

@@ -0,0 +1,15 @@
'use strict';
const { masterID } = require('../../config.json');
const { removeGroup } = require('../../stores/group');
const leaveCommandHandler = async ctx => {
if (ctx.from.id !== masterID) {
return null;
}
await removeGroup(ctx.chat);
return ctx.telegram.leaveChat(ctx.chat.id);
};
module.exports = leaveCommandHandler;

View File

@@ -23,6 +23,7 @@ const addedToGroupHandler = require('./handlers/middlewares/addedToGroup');
// Commmands Handlers // Commmands Handlers
const adminHandler = require('./handlers/commands/admin'); const adminHandler = require('./handlers/commands/admin');
const unAdminHandler = require('./handlers/commands/unadmin'); const unAdminHandler = require('./handlers/commands/unadmin');
const leaveCommandHandler = require('./handlers/commands/leave');
const warnHandler = require('./handlers/commands/warn'); const warnHandler = require('./handlers/commands/warn');
const unwarnHandler = require('./handlers/commands/unwarn'); const unwarnHandler = require('./handlers/commands/unwarn');
const nowarnsHandler = require('./handlers/commands/nowarns'); const nowarnsHandler = require('./handlers/commands/nowarns');
@@ -45,6 +46,7 @@ bot.on('new_chat_members', antibotHandler);
bot.on([ 'new_chat_members', 'left_chat_member' ], deleteAfter(10 * 60 * 1000)); bot.on([ 'new_chat_members', 'left_chat_member' ], deleteAfter(10 * 60 * 1000));
bot.command('admin', adminHandler); bot.command('admin', adminHandler);
bot.command('unadmin', unAdminHandler); bot.command('unadmin', unAdminHandler);
bot.command('leave', leaveCommandHandler);
bot.command('warn', warnHandler); bot.command('warn', warnHandler);
bot.command('unwarn', unwarnHandler); bot.command('unwarn', unwarnHandler);
bot.command('nowarns', nowarnsHandler); bot.command('nowarns', nowarnsHandler);

View File

@@ -21,8 +21,12 @@ const listGroups = () =>
const managesGroup = group => const managesGroup = group =>
Group.findOne({ id: group.id }); Group.findOne({ id: group.id });
const removeGroup = ({ id }) =>
Group.remove({ id });
module.exports = { module.exports = {
addGroup, addGroup,
listGroups, listGroups,
managesGroup, managesGroup,
removeGroup,
}; };