From af1728f71ba35bbcb32759b6193ce7c1117f2464 Mon Sep 17 00:00:00 2001 From: Joonas Date: Sat, 11 Feb 2023 19:11:02 +0200 Subject: [PATCH] join command persistance and ping refactoring --- commands/join.js | 33 +++++++++++++++++++++++++-------- commands/ping.js | 2 +- commands/repo.js | 14 ++++++++++++++ 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 commands/repo.js diff --git a/commands/join.js b/commands/join.js index 9bb7303..39a3ac9 100644 --- a/commands/join.js +++ b/commands/join.js @@ -1,3 +1,5 @@ +const prisma = require("../clients/prisma"); + const command = { name: "join", desc: "make the bot listen to a channel", @@ -18,6 +20,21 @@ const command = { return; } + const storeChannel = await prisma.channel.create({ + data: { + name: msg.senderUsername, + }, + }); + + if (!storeChannel) { + await client.say( + msg.channelName, + `${msg.displayName}, something went wrong saving` + ); + + return; + } + await client .join(msg.senderUsername) .then( @@ -26,14 +43,14 @@ const command = { msg.channelName, `${msg.displayName}, joined ${msg.senderUsername} BroBalt` ) - ) - .then(() => client.say(msg.senderUsername, "MrDestructoid")) - .catch( - async () => - await client.say( - msg.channelName, - `${msg.displayName}, the bot is probably in your chat, but can't speak because of phone number etc verification` - ) + ); + + await client + .say(msg.senderUsername, "MrDestructoid") + .catch((err) => + console.error( + `The bot can't speak in the newly joined channel! Error: ${err.message}` + ) ); }, }; diff --git a/commands/ping.js b/commands/ping.js index 31f54b8..02a58a7 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -17,7 +17,7 @@ const command = { os.totalmem() / 1024 / 1024 )}mb Joined channels count: ${ client.joinedChannels.size - } Megis drinkers count: ${await prisma.user.count()}` + } Megis drinkers count: ${await prisma.megis.count()}` ); }, }; diff --git a/commands/repo.js b/commands/repo.js new file mode 100644 index 0000000..82e4f85 --- /dev/null +++ b/commands/repo.js @@ -0,0 +1,14 @@ +const command = { + name: "repo", + desc: "get the git repo of bot", + restricted: false, + mod: false, + run: async (client, msg) => { + await client.say( + msg.channelName, + `${msg.displayName}, https://git.disroot.org/qwertyasdfgh/twitch_bot Author: juuuuuuuuuuuuunas` + ); + }, +}; + +module.exports = { command };