2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-30 05:37:59 +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

@ -2,7 +2,7 @@
<img src="http://imageupload.co.uk/images/2017/09/28/zzzzz.png" width="180" height="180">
<h1 align="center">The Guard Bot</h1>
</p>
The Guard is a Telegram bot made to help admins manage their groups.
The Guard is a Telegram bot made to help admins manage their groups.
Initially created to moderate [The Devs Network](https://thedevs.network).
@ -24,6 +24,7 @@ Command | Rule | Description
-------- | ------ | -----------
`/admin` | _Master_ | Makes the user admin.
`/unadmin` | _Master_ | Demotes the user from admin list.
`/leave` | _Master_ | Makes the bot leave the group cleanly.
`/warn <reason>` | _Admin_ | Warns the user.
`/unwarn` | _Admin_ | Removes the last warn from the user.
`/nowarns` | _Admin_ | Clears warns for the user.

View File

@ -4,6 +4,7 @@ const commandReference = `\
<b>Master commands</b>:
<code>/admin</code> - Makes the user admin.
<code>/unadmin</code> - Demotes the user from admin list.
<code>/leave</code> - Makes the bot leave the group cleanly.
<b>Admin commands</b>:
<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
const adminHandler = require('./handlers/commands/admin');
const unAdminHandler = require('./handlers/commands/unadmin');
const leaveCommandHandler = require('./handlers/commands/leave');
const warnHandler = require('./handlers/commands/warn');
const unwarnHandler = require('./handlers/commands/unwarn');
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.command('admin', adminHandler);
bot.command('unadmin', unAdminHandler);
bot.command('leave', leaveCommandHandler);
bot.command('warn', warnHandler);
bot.command('unwarn', unwarnHandler);
bot.command('nowarns', nowarnsHandler);

View File

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