3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-19 07:20:00 +00:00
zeppelin/backend/src/plugins/BotControl/commands/LeaveServerCmd.ts

36 lines
1 KiB
TypeScript
Raw Normal View History

2020-07-30 03:21:07 +03:00
import { command } from "knub";
import { BotControlPluginType } from "../types";
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { commandTypeHelpers as ct } from "../../../commandTypes";
export const LeaveServerCmd = command<BotControlPluginType>()({
trigger: ["leave_server", "leave_guild"],
permission: null,
config: {
preFilters: [isOwnerPreFilter],
},
signature: {
guildId: ct.string(),
},
async run({ pluginData, message: msg, args }) {
if (!pluginData.client.guilds.has(args.guildId)) {
sendErrorMessage(pluginData, msg.channel, "I am not in that guild");
return;
}
const guildToLeave = pluginData.client.guilds.get(args.guildId);
const guildName = guildToLeave.name;
try {
await pluginData.client.leaveGuild(args.guildId);
} catch (e) {
sendErrorMessage(pluginData, msg.channel, `Failed to leave guild: ${e.message}`);
return;
}
sendSuccessMessage(pluginData, msg.channel, `Left guild **${guildName}**`);
},
});