From c98a59601e36a7829ebb0cf1cd316978674535b2 Mon Sep 17 00:00:00 2001 From: Joonas Date: Sat, 11 Feb 2023 19:28:31 +0200 Subject: [PATCH] added parting comman d --- commands/part.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 commands/part.js diff --git a/commands/part.js b/commands/part.js new file mode 100644 index 0000000..e7c3474 --- /dev/null +++ b/commands/part.js @@ -0,0 +1,46 @@ +const prisma = require("../clients/prisma"); + +const command = { + name: "part", + desc: "part the joined channel", + restricted: false, + mod: false, + run: async (client, msg) => { + if (!client.joinedChannels.has(msg.senderUsername)) { + await client.say( + msg.channelName, + `${msg.displayName}, not currently joined there` + ); + return; + } + + const partChannel = await prisma.channel.delete({ + where: { + name: msg.senderUsername, + }, + }); + + if (!partChannel) { + console.error("Couldn't part channel: " + msg.senderUsername); + await client.say( + msg.channelName, + `${msg.displayName}, couldn't save parting changes` + ); + return; + } + + await client + .part(msg.senderUsername) + .then( + async () => + await client.say(msg.channelName, `${msg.displayName}, parted`) + ) + .catch((err) => + console.error( + "Something went wrong with parting with the channel: " + err.message + ) + ); + }, +}; + +module.exports = { command };