2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-24 10:58:19 +00:00

26 lines
762 B
TypeScript
Raw Permalink Normal View History

2020-05-08 15:52:59 +02:00
import { managesGroup, removeGroup } from "../../stores/group";
import { ExtendedContext } from "../../typings/context";
2020-05-12 18:03:07 +02:00
import { html } from "../../utils/html";
2020-05-08 15:52:59 +02:00
import { isMaster } from "../../utils/config";
const leaveCommandHandler = async (ctx: ExtendedContext) => {
if (!isMaster(ctx.from)) 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);
2020-05-08 15:52:59 +02:00
};
export = leaveCommandHandler;