2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-09-05 16:45:18 +00:00
Files
the-guard-bot/handlers/commands/leave.js

37 lines
886 B
JavaScript
Raw Normal View History

2017-09-28 22:59:35 +02:00
'use strict';
const { managesGroup, removeGroup } = require('../../stores/group');
2017-09-28 22:59:35 +02:00
const leaveCommandHandler = async ctx => {
const { chat, message, telegram, state, replyWithHTML } = ctx;
const { isMaster } = state;
if (!isMaster) return null;
const groupName = message.text.split(' ').slice(1).join(' ');
if (groupName) {
const group = /^-?\d+/.test(groupName)
? { id: Number(groupName) }
: { title: groupName };
console.log(group);
const isGroup = await managesGroup(group);
if (!isGroup) {
return replyWithHTML(
' <b>Couldn\'t find a group with that ID/name.</b>'
);
}
await Promise.all([
removeGroup(isGroup),
telegram.leaveChat(isGroup.id)
]);
return replyWithHTML(
'✅ <b>I no longer manage that group.</b>'
);
}
await removeGroup(chat);
return telegram.leaveChat(chat.id);
2017-09-28 22:59:35 +02:00
};
module.exports = leaveCommandHandler;