File tree Expand file tree Collapse file tree 5 files changed +24
-1
lines changed
Expand file tree Collapse file tree 5 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 22 <img src =" http://imageupload.co.uk/images/2017/09/28/zzzzz.png " width =" 180 " height =" 180 " >
33 <h1 align =" center " >The Guard Bot</h1 >
44</p >
5- The Guard is a Telegram bot made to help admins manage their groups.
5+ The Guard is a Telegram bot made to help admins manage their groups.
66
77Initially created to moderate [ The Devs Network] ( https://thedevs.network ) .
88
@@ -24,6 +24,7 @@ Command | Rule | Description
2424-------- | ------ | -----------
2525` /admin ` | _ Master_ | Makes the user admin.
2626` /unadmin ` | _ Master_ | Demotes the user from admin list.
27+ ` /leave ` | _ Master_ | Makes the bot leave the group cleanly.
2728` /warn <reason> ` | _ Admin_ | Warns the user.
2829` /unwarn ` | _ Admin_ | Removes the last warn from the user.
2930` /nowarns ` | _ Admin_ | Clears warns for the user.
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const commandReference = `\
44<b>Master commands</b>:
55<code>/admin</code> - Makes the user admin.
66<code>/unadmin</code> - Demotes the user from admin list.
7+ <code>/leave</code> - Makes the bot leave the group cleanly.
78
89<b>Admin commands</b>:
910<code>/warn <reason></code> - Warns the user.
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const { masterID } = require ( '../../config.json' ) ;
4+
5+ const { removeGroup } = require ( '../../stores/group' ) ;
6+
7+ const leaveCommandHandler = async ctx => {
8+ if ( ctx . from . id !== masterID ) {
9+ return null ;
10+ }
11+ await removeGroup ( ctx . chat ) ;
12+ return ctx . telegram . leaveChat ( ctx . chat . id ) ;
13+ } ;
14+
15+ module . exports = leaveCommandHandler ;
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ const addedToGroupHandler = require('./handlers/middlewares/addedToGroup');
2323// Commmands Handlers
2424const adminHandler = require ( './handlers/commands/admin' ) ;
2525const unAdminHandler = require ( './handlers/commands/unadmin' ) ;
26+ const leaveCommandHandler = require ( './handlers/commands/leave' ) ;
2627const warnHandler = require ( './handlers/commands/warn' ) ;
2728const unwarnHandler = require ( './handlers/commands/unwarn' ) ;
2829const nowarnsHandler = require ( './handlers/commands/nowarns' ) ;
@@ -45,6 +46,7 @@ bot.on('new_chat_members', antibotHandler);
4546bot . on ( [ 'new_chat_members' , 'left_chat_member' ] , deleteAfter ( 10 * 60 * 1000 ) ) ;
4647bot . command ( 'admin' , adminHandler ) ;
4748bot . command ( 'unadmin' , unAdminHandler ) ;
49+ bot . command ( 'leave' , leaveCommandHandler ) ;
4850bot . command ( 'warn' , warnHandler ) ;
4951bot . command ( 'unwarn' , unwarnHandler ) ;
5052bot . command ( 'nowarns' , nowarnsHandler ) ;
Original file line number Diff line number Diff line change @@ -21,8 +21,12 @@ const listGroups = () =>
2121const managesGroup = group =>
2222 Group . findOne ( { id : group . id } ) ;
2323
24+ const removeGroup = ( { id } ) =>
25+ Group . remove ( { id } ) ;
26+
2427module . exports = {
2528 addGroup,
2629 listGroups,
2730 managesGroup,
31+ removeGroup,
2832} ;
You can’t perform that action at this time.
0 commit comments