From 89c7fe952b79faaa5d277840fd0c0e0c86976d91 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 13 Dec 2022 14:16:41 +0100 Subject: [PATCH 1/3] refactor: :coffin: Fixed some code smells Fixed some code smells from https://deepsource.io/gh/ZynerOrg/xyter/run/8058c521-9330-4c14-94b2-0c3a7d9d824b/javascript/ --- src/commands/reputation/modules/check/index.ts | 6 +++--- src/commands/utils/modules/about/index.ts | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/commands/reputation/modules/check/index.ts b/src/commands/reputation/modules/check/index.ts index fc80d53..1e6008f 100644 --- a/src/commands/reputation/modules/check/index.ts +++ b/src/commands/reputation/modules/check/index.ts @@ -72,7 +72,7 @@ export default { logger.silly(createGuildMember); - const reputationType = async (reputation: number) => { + const reputationType = (reputation: number) => { if (reputation < 0) return `negative reputation of ${reputation}`; if (reputation > 0) return `positive reputation of ${reputation}`; return "neutral reputation"; @@ -86,10 +86,10 @@ export default { ) .setDescription( optionAccount - ? `${optionAccount} have a ${await reputationType( + ? `${optionAccount} have a ${reputationType( createGuildMember.user.reputationsEarned )}` - : `You have a ${await reputationType( + : `You have a ${reputationType( createGuildMember.user.reputationsEarned )}` ) diff --git a/src/commands/utils/modules/about/index.ts b/src/commands/utils/modules/about/index.ts index dc71f10..4412df5 100644 --- a/src/commands/utils/modules/about/index.ts +++ b/src/commands/utils/modules/about/index.ts @@ -46,8 +46,6 @@ export default { const minutes = Math?.floor(totalSeconds / 60); const seconds = Math?.floor(totalSeconds % 60); - const uptime = `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`; - // // Initialize a storage for the user ids // const userIds = new Set(); // // Iterate over all guilds (always cached) From c6d6547881a76cb1dae0b441c665e19523926607 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 13 Dec 2022 14:19:58 +0100 Subject: [PATCH 2/3] refactor: :coffin: Fixed code smells Fixed some more code smells --- src/commands/utils/modules/about/index.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/commands/utils/modules/about/index.ts b/src/commands/utils/modules/about/index.ts index 4412df5..ea8ba26 100644 --- a/src/commands/utils/modules/about/index.ts +++ b/src/commands/utils/modules/about/index.ts @@ -36,16 +36,6 @@ export default { interaction.guild ); - const { client } = interaction; - if (client?.uptime === null) return; - let totalSeconds = client?.uptime / 1000; - const days = Math?.floor(totalSeconds / 86400); - totalSeconds %= 86400; - const hours = Math?.floor(totalSeconds / 3600); - totalSeconds %= 3600; - const minutes = Math?.floor(totalSeconds / 60); - const seconds = Math?.floor(totalSeconds % 60); - // // Initialize a storage for the user ids // const userIds = new Set(); // // Iterate over all guilds (always cached) From 0f8ea8ad2bd64f97398e1d0916261a2cafb38547 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 13 Dec 2022 14:27:00 +0100 Subject: [PATCH 3/3] refactor: :recycle: Fixed more code smells I have fixed more code smells --- src/commands/config/modules/welcome/index.ts | 1 - src/commands/shop/modules/cpgg/index.ts | 1 - src/events/messageCreate/modules/counters/index.ts | 9 ++++++--- src/events/messageDelete/modules/counter.ts | 2 +- src/events/messageUpdate/index.ts | 1 + src/events/messageUpdate/modules/counter.ts | 3 ++- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/commands/config/modules/welcome/index.ts b/src/commands/config/modules/welcome/index.ts index e59fff6..40ad6fa 100644 --- a/src/commands/config/modules/welcome/index.ts +++ b/src/commands/config/modules/welcome/index.ts @@ -142,6 +142,5 @@ export default { await interaction?.editReply({ embeds: [interactionEmbed], }); - return; }, }; diff --git a/src/commands/shop/modules/cpgg/index.ts b/src/commands/shop/modules/cpgg/index.ts index c48b4dd..c87c580 100644 --- a/src/commands/shop/modules/cpgg/index.ts +++ b/src/commands/shop/modules/cpgg/index.ts @@ -188,7 +188,6 @@ export default { await interaction?.editReply({ embeds: [interactionEmbed], }); - return; }); }); }, diff --git a/src/events/messageCreate/modules/counters/index.ts b/src/events/messageCreate/modules/counters/index.ts index 072b544..ea712a4 100644 --- a/src/events/messageCreate/modules/counters/index.ts +++ b/src/events/messageCreate/modules/counters/index.ts @@ -22,7 +22,10 @@ export default { }, }); - if (!channelCounter) return logger.debug("No counters found in channel."); + if (!channelCounter) { + logger.debug("No counters found in channel."); + return false; + } if ( lastMessage?.author.id === author.id && @@ -32,7 +35,7 @@ export default { `${author.username} sent the last message therefor not allowing again.` ); await message.delete(); - return; + return false; } if (content !== channelCounter.triggerWord) { @@ -41,7 +44,7 @@ export default { ); await message.delete(); - return; + return false; } const updateGuildCounter = await prisma.guildCounter.update({ diff --git a/src/events/messageDelete/modules/counter.ts b/src/events/messageDelete/modules/counter.ts index bbb058c..989db4e 100644 --- a/src/events/messageDelete/modules/counter.ts +++ b/src/events/messageDelete/modules/counter.ts @@ -32,7 +32,7 @@ export default async (message: Message) => { channel?.send(`${author} said **${channelCounter.triggerWord}**.`); logger?.silly(`${author} said ${channelCounter.triggerWord} in ${channel}`); - return logger?.silly( + logger?.silly( `User: ${author?.tag} (${author?.id}) in guild: ${guild?.name} (${guild?.id}) said the counter word: ${channelCounter.triggerWord}` ); }; diff --git a/src/events/messageUpdate/index.ts b/src/events/messageUpdate/index.ts index 80d3c06..77f434c 100644 --- a/src/events/messageUpdate/index.ts +++ b/src/events/messageUpdate/index.ts @@ -25,4 +25,5 @@ export const execute = async (oldMessage: Message, newMessage: Message) => { if (author?.bot) return logger?.silly(`Message update event fired by bot`); await counter(newMessage); + return; }; diff --git a/src/events/messageUpdate/modules/counter.ts b/src/events/messageUpdate/modules/counter.ts index be33a02..b5be703 100644 --- a/src/events/messageUpdate/modules/counter.ts +++ b/src/events/messageUpdate/modules/counter.ts @@ -1,4 +1,4 @@ -// Dependencies +1; // Dependencies import { Message } from "discord.js"; // Models import prisma from "../../../handlers/database"; @@ -38,4 +38,5 @@ export default async (message: Message) => { .catch((error) => { logger.error(error); }); + return; };