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:
@@ -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.
|
||||
|
@@ -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 <reason></code> - Warns the user.
|
||||
|
15
handlers/commands/leave.js
Normal file
15
handlers/commands/leave.js
Normal 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;
|
2
index.js
2
index.js
@@ -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);
|
||||
|
@@ -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,
|
||||
};
|
||||
|
Reference in New Issue
Block a user