mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-23 10:28:09 +00:00
26 lines
762 B
TypeScript
26 lines
762 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;
|
|
|
|
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;
|