2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-28 04:37:52 +00:00
Wojciech Pawlik 1fc8938ed4
Misc
2020-04-04 14:01:03 +02:00

36 lines
967 B
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// @ts-check
'use strict';
const { isMaster } = require('../../utils/config');
const { managesGroup, removeGroup } = require('../../stores/group');
/** @param { import('../../typings/context').ExtendedContext } ctx */
const leaveCommandHandler = async ctx => {
const { chat, message, telegram, replyWithHTML } = ctx;
if (!isMaster(ctx.from)) return null;
const groupName = message.text.split(' ').slice(1).join(' ');
if (groupName) {
const group = /^-?\d+/.test(groupName)
? { id: Number(groupName) }
: { title: groupName };
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);
};
module.exports = leaveCommandHandler;