2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-30 21:55:17 +00:00
Files
the-guard-bot/handlers/commands/leave.ts
Thomas Rory Gummerson 37974a3d92 Updates
2023-03-08 14:08:57 +01:00

28 lines
858 B
TypeScript

import { managesGroup, removeGroup } from '../../stores/group';
import { ExtendedContext } from '../../typings/context';
import { html } from '../../utils/html';
import { isMaster } from '../../utils/config';
const leaveCommandHandler = async (ctx: ExtendedContext) => {
if (!isMaster(ctx.from)) return null;
if (typeof ctx.message === 'undefined') return null;
if (!('text' in ctx.message)) return null;
const query = ctx.message.text.split(' ').slice(1).join(' ');
const group = query
? await managesGroup(
/^-?\d+/.test(query) ? { id: +query } : { title: query }
)
: ctx.chat;
if (!group) {
return ctx.replyWithHTML('❓ <b>Unknown group.</b>');
}
await removeGroup(group);
await ctx.replyWithHTML(html`✅ <b>I no longer manage ${group.title}.</b>`);
return ctx.telegram.leaveChat(group.id);
};
export = leaveCommandHandler;