From cd06b7ca3379744363c897f03da0959c9e7cf9ae Mon Sep 17 00:00:00 2001 From: Leon <64979109+ItsLeon15@users.noreply.github.com> Date: Tue, 27 Dec 2022 21:56:52 +0000 Subject: [PATCH] Reduced overcomplicated code --- src/commands/autosetup/fun.js | 61 ++++++++++------------------------ src/commands/autosetup/logs.js | 51 ++++++++++++---------------- src/commands/music/seek.js | 23 ++++--------- 3 files changed, 45 insertions(+), 90 deletions(-) diff --git a/src/commands/autosetup/fun.js b/src/commands/autosetup/fun.js index 2e5581cb..128e0a4a 100644 --- a/src/commands/autosetup/fun.js +++ b/src/commands/autosetup/fun.js @@ -9,49 +9,22 @@ const StarBoard = require("../../database/models/starboardChannels"); module.exports = async (client, interaction, args) => { const choice = interaction.options.getString('setup'); - if (choice == "birthdays") { - interaction.guild.channels.create({ - name: "birthdays", - type: Discord.ChannelType.GuildText - }).then((ch) => { - client.createChannelSetup(Birthdays, ch, interaction) - }) - } - - if (choice == "chatbot") { - interaction.guild.channels.create({ - name: "chatbot", - type: Discord.ChannelType.GuildText - }).then((ch) => { - client.createChannelSetup(Chatbot, ch, interaction) - }) - } - - if (choice == "reviews") { - interaction.guild.channels.create({ - name: "reviews", - type: Discord.ChannelType.GuildText - }).then((ch) => { - client.createChannelSetup(Review, ch, interaction) - }) - } - - if (choice == "suggestions") { - interaction.guild.channels.create({ - name: "suggestions", - type: Discord.ChannelType.GuildText - }).then((ch) => { - client.createChannelSetup(Suggestion, ch, interaction) - }) - } - - if (choice == "starboard") { - interaction.guild.channels.create({ - name: "starboard", - type: Discord.ChannelType.GuildText - }).then((ch) => { - client.createChannelSetup(StarBoard, ch, interaction) - }) + const channelOptions = [ + ["birthdays", Birthdays], + ["chatbot", Chatbot], + ["reviews", Review], + ["suggestions", Suggestion], + ["starboard", StarBoard] + ]; + + for (const [name, setup] of channelOptions) { + if (choice == name) { + interaction.guild.channels.create({ + name: name, + type: Discord.ChannelType.GuildText + }).then((ch) => { + client.createChannelSetup(setup, ch, interaction); + }); + } } } - diff --git a/src/commands/autosetup/logs.js b/src/commands/autosetup/logs.js index 25e2d781..ceeb84a5 100644 --- a/src/commands/autosetup/logs.js +++ b/src/commands/autosetup/logs.js @@ -7,37 +7,28 @@ const levelLogs = require("../../database/models/levelChannels"); module.exports = async (client, interaction, args) => { const choice = interaction.options.getString('setup'); - if (choice == "serverLogs") { - interaction.guild.channels.create({ - name: "server-logs", - permissionOverwrites: [ - { - deny: [Discord.PermissionsBitField.Flags.ViewChannel], - id: interaction.guild.id - }, - ], - type: Discord.ChannelType.GuildText - }).then((ch) => { - client.createChannelSetup(logs, ch, interaction) - }) - } - - if (choice == "levelLogs") { - interaction.guild.channels.create({ - name: "level-logs", - type: Discord.ChannelType.GuildText - }).then((ch) => { - client.createChannelSetup(levelLogs, ch, interaction) - }) - } + const channelOptions = [ + ["serverLogs", "server-logs", logs, { + deny: [Discord.PermissionsBitField.Flags.ViewChannel], + id: interaction.guild.id + }], + ["levelLogs", "level-logs", levelLogs, {}], // No permissions needed + ["boostLogs", "boosts", boostLogs, {}] + ]; - if (choice == "boostLogs") { - interaction.guild.channels.create({ - name: "boosts", - type: Discord.ChannelType.GuildText - }).then((ch) => { - client.createChannelSetup(boostLogs, ch, interaction) - }) + for (const [choiceName, channelName, setup, permissions] of channelOptions) { // For each channel option + if (choice == choiceName) { + const options = { + name: channelName, + type: Discord.ChannelType.GuildText + }; + if (permissions.id) { // If permissions are needed + options.permissionOverwrites = [permissions]; + } + interaction.guild.channels.create(options).then((ch) => { // Create the channel + client.createChannelSetup(setup, ch, interaction); + }); + } } } diff --git a/src/commands/music/seek.js b/src/commands/music/seek.js index f1d3c65b..07210fba 100644 --- a/src/commands/music/seek.js +++ b/src/commands/music/seek.js @@ -53,23 +53,15 @@ async function createProgressBar(total, current, size = 10, line = '▬', slider const percentage = current / total; const progress = Math.round((size * percentage)); - if (progress > 1 && progress < 10) { + if (progress < 1) { + return [slider + line.repeat(9)]; + } else if (progress > 9) { + return [line.repeat(9) + slider]; + } else { const emptyProgress = size - progress; const progressText = line.repeat(progress).replace(/.$/, slider); const emptyProgressText = line.repeat(emptyProgress); - const bar = progressText + emptyProgressText; - return [bar]; - } - else if (progress < 1 || progress == 1) { - const emptyProgressText = line.repeat(9); - const bar = "🔘" + emptyProgressText; - return [bar]; - } - - else if (progress > 10 || progress == 10) { - const emptyProgressText = line.repeat(9); - const bar = emptyProgressText + "🔘"; - return [bar]; + return [progressText + emptyProgressText]; } } } @@ -79,11 +71,10 @@ function format(millis) { var h = Math.floor(millis / 3600000), m = Math.floor(millis / 60000), s = ((millis % 60000) / 1000).toFixed(0); - if (h < 1) return (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s ; + if (h < 1) return (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s; else return (h < 10 ? "0" : "") + h + ":" + (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s; } catch (e) { console.log(String(e.stack).bgRed) } } - \ No newline at end of file