From d8c2513954639265a37c92eb4e468c5a95ba0278 Mon Sep 17 00:00:00 2001 From: Joonas Date: Sun, 12 Feb 2023 01:01:34 +0200 Subject: [PATCH] various fixes and refactorings --- .eslintrc.js | 33 +++++++++++++-------------------- clients/twitch.js | 10 +++++++--- commands/google.js | 4 ++-- commands/part.js | 8 ++++++++ 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 1809442..930f5ae 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,21 +1,14 @@ module.exports = { - "env": { - "browser": true, - "commonjs": true, - "es2021": true - }, - "extends": [ - "eslint:recommended", - "plugin:react/recommended" - ], - "overrides": [ - ], - "parserOptions": { - "ecmaVersion": "latest" - }, - "plugins": [ - "react" - ], - "rules": { - } -} + env: { + node: true, + commonjs: true, + es2021: true, + }, + extends: ["eslint:recommended", "plugin:react/recommended"], + overrides: [], + parserOptions: { + ecmaVersion: "latest", + }, + plugins: ["react"], + rules: {}, +}; diff --git a/clients/twitch.js b/clients/twitch.js index 686a61c..35c8ef2 100644 --- a/clients/twitch.js +++ b/clients/twitch.js @@ -20,13 +20,17 @@ client.commands = getCommands(); console.log("Commands loaded"); client.on("ready", async () => { - console.log("connected to chat"); - const channels = await prisma.channel.findMany(); + console.log("Connected to chat"); + + console.log("Joining bots channel: " + process.env.TWITCH_USERNAME); client.join(process.env.TWITCH_USERNAME); + + const channels = await prisma.channel.findMany(); for (let channel of channels) { console.log("Joining channel: " + channel.name); client.join(channel.name); } + console.log("Joined channels"); }); @@ -48,7 +52,7 @@ client.on("PRIVMSG", async (msg) => { if (splitted[0] === process.env.BOT_PREFIX) { try { - if (!client.commands.hasOwnProperty(splitted[1])) { + if (!(splitted[1] in client.commands)) { await client.say(msg.channelName, `${msg.displayName}, not a command`); return; } diff --git a/commands/google.js b/commands/google.js index 1a6359a..289cf3b 100644 --- a/commands/google.js +++ b/commands/google.js @@ -5,7 +5,7 @@ const command = { mod: false, run: async (client, msg, splitted) => { const data = await fetch( - `https://librex.nekus.gay/api.php?q="${encodeURIComponent( + `https://search.femboy.hu/api.php?q="${encodeURIComponent( splitted.slice(2).join(" ") )}"` ) @@ -29,7 +29,7 @@ const command = { `${msg.displayName}, First result for query ${splitted .slice(2) .join(" ")}: ${ - data.hasOwnProperty("special_response") + "special_response" in data ? `${data.special_response.response.replaceAll("\n", "")} - ${ data.special_response.source }` diff --git a/commands/part.js b/commands/part.js index 9a2c971..ff7729f 100644 --- a/commands/part.js +++ b/commands/part.js @@ -6,6 +6,14 @@ const command = { restricted: false, mod: false, run: async (client, msg) => { + if (msg.channelName !== process.env.TWITCH_USERNAME) { + await client.say( + msg.channelName, + `${msg.displayName}, command only available in bot chat` + ); + return; + } + if (!client.joinedChannels.has(msg.senderUsername)) { await client.say( msg.channelName,