added parting comman d

This commit is contained in:
Joonas 2023-02-11 19:28:31 +02:00
parent 8bf3e32559
commit c98a59601e
1 changed files with 46 additions and 0 deletions

46
commands/part.js Normal file
View File

@ -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 };