From 19c09c5c87c36736603998d3101b7911d2a999df Mon Sep 17 00:00:00 2001 From: nathomp3 Date: Sun, 7 Aug 2022 21:16:12 -0400 Subject: [PATCH] Added verification --- ButtonInteractions/reject.js | 16 ++ ButtonInteractions/verify.js | 22 ++ .../categories.js | 0 {commands => CommandInteractions}/dream.js | 0 {commands => CommandInteractions}/help.js | 0 .../leaderboard.js | 0 {commands => CommandInteractions}/link.js | 0 {commands => CommandInteractions}/ping.js | 0 {commands => CommandInteractions}/search.js | 0 .../unverified.js | 0 {commands => CommandInteractions}/verified.js | 0 GuildCommandInteractions/hypixel.js | 46 +++ .../suggest.js | 4 +- GuildCommandInteractions/verify.js | 77 +++++ SelectMenuInteractions/category.js | 136 +++++++++ SelectMenuInteractions/link.js | 45 +++ guildcommands/hypixel.js | 271 ------------------ index.js | 37 ++- messagecommands/banlist.js | 9 - messagecommands/check.js | 2 - messagecommands/runners.js | 12 - 21 files changed, 372 insertions(+), 305 deletions(-) create mode 100644 ButtonInteractions/reject.js create mode 100644 ButtonInteractions/verify.js rename {commands => CommandInteractions}/categories.js (100%) rename {commands => CommandInteractions}/dream.js (100%) rename {commands => CommandInteractions}/help.js (100%) rename {commands => CommandInteractions}/leaderboard.js (100%) rename {commands => CommandInteractions}/link.js (100%) rename {commands => CommandInteractions}/ping.js (100%) rename {commands => CommandInteractions}/search.js (100%) rename {commands => CommandInteractions}/unverified.js (100%) rename {commands => CommandInteractions}/verified.js (100%) create mode 100644 GuildCommandInteractions/hypixel.js rename {guildcommands => GuildCommandInteractions}/suggest.js (94%) create mode 100644 GuildCommandInteractions/verify.js create mode 100644 SelectMenuInteractions/category.js create mode 100644 SelectMenuInteractions/link.js delete mode 100644 guildcommands/hypixel.js diff --git a/ButtonInteractions/reject.js b/ButtonInteractions/reject.js new file mode 100644 index 0000000..feb1b83 --- /dev/null +++ b/ButtonInteractions/reject.js @@ -0,0 +1,16 @@ +const tokens = require("../index.js"); + +/** + * Returns options depending on previously selected option + */ +module.exports = { + data: 'reject', + async execute(params) { + const { interaction } = params; + interaction.message.embeds[0].fields.push({ name: 'Rejected by:', value: `<@${interaction.user.id}>`}) + await interaction.update({ + embeds: interaction.message.embeds, + components: [] + }) + }, +}; \ No newline at end of file diff --git a/ButtonInteractions/verify.js b/ButtonInteractions/verify.js new file mode 100644 index 0000000..d2ee45b --- /dev/null +++ b/ButtonInteractions/verify.js @@ -0,0 +1,22 @@ +const tokens = require("../index.js"); + +/** + * Returns options depending on previously selected option + */ +module.exports = { + data: 'verify', + async execute(params) { + const { interaction } = params; + const {discordID, srcID} = JSON.parse(interaction.customId); + tokens.db.db("accounts").collection("users").insertOne({ + discordID, + srcID, + minecraftUUIDs: [], + }); + interaction.message.embeds[0].fields.push({ name: 'Verified by:', value: `<@${interaction.user.id}>`}) + await interaction.update({ + embeds: interaction.message.embeds, + components: [] + }) + }, +}; \ No newline at end of file diff --git a/commands/categories.js b/CommandInteractions/categories.js similarity index 100% rename from commands/categories.js rename to CommandInteractions/categories.js diff --git a/commands/dream.js b/CommandInteractions/dream.js similarity index 100% rename from commands/dream.js rename to CommandInteractions/dream.js diff --git a/commands/help.js b/CommandInteractions/help.js similarity index 100% rename from commands/help.js rename to CommandInteractions/help.js diff --git a/commands/leaderboard.js b/CommandInteractions/leaderboard.js similarity index 100% rename from commands/leaderboard.js rename to CommandInteractions/leaderboard.js diff --git a/commands/link.js b/CommandInteractions/link.js similarity index 100% rename from commands/link.js rename to CommandInteractions/link.js diff --git a/commands/ping.js b/CommandInteractions/ping.js similarity index 100% rename from commands/ping.js rename to CommandInteractions/ping.js diff --git a/commands/search.js b/CommandInteractions/search.js similarity index 100% rename from commands/search.js rename to CommandInteractions/search.js diff --git a/commands/unverified.js b/CommandInteractions/unverified.js similarity index 100% rename from commands/unverified.js rename to CommandInteractions/unverified.js diff --git a/commands/verified.js b/CommandInteractions/verified.js similarity index 100% rename from commands/verified.js rename to CommandInteractions/verified.js diff --git a/GuildCommandInteractions/hypixel.js b/GuildCommandInteractions/hypixel.js new file mode 100644 index 0000000..e19f2db --- /dev/null +++ b/GuildCommandInteractions/hypixel.js @@ -0,0 +1,46 @@ +const { ActionRowBuilder, SelectMenuBuilder, ButtonBuilder, InteractionType, ButtonStyle } = require("discord.js"); +const { SlashCommandBuilder } = require("@discordjs/builders"); + +/** + * Function to provide a link to a requested site + */ +module.exports = { + /** + * Builds /hypixel + */ + data: new SlashCommandBuilder() + .setName("hypixel") + .setDescription("Provides helpful links for Hypixel Speedruns"), + async execute(params) { + const { interaction } = params; + const row = new ActionRowBuilder() + .addComponents( + new SelectMenuBuilder() + .setCustomId("category") + .setPlaceholder("Nothing selected") + .addOptions([ + { + label: "General", + description: "Get links to general Hypixel Speedruns Information", + value: "General", + }, + { + label: "Games", + description: "Get links to Hypixel Speedrun Games", + value: "Games", + }, + { + label: "Maps", + description: "Get links to Hypixel Speedrun Maps", + value: "Maps", + }, + { + label: "Speedrun.com", + description: "Links to speedrun.com resources", + value: "Speedrun.com", + }, + ]), + ); + return await interaction.editReply({ content: "Please select a category!", components: [row] }); + }, +}; \ No newline at end of file diff --git a/guildcommands/suggest.js b/GuildCommandInteractions/suggest.js similarity index 94% rename from guildcommands/suggest.js rename to GuildCommandInteractions/suggest.js index 1c127f8..de7d99c 100644 --- a/guildcommands/suggest.js +++ b/GuildCommandInteractions/suggest.js @@ -2,11 +2,11 @@ const { EmbedBuilder } = require("discord.js"); const { SlashCommandBuilder } = require("@discordjs/builders"); /** - * Function to provide a list of categories for the given game + * Function to create a suggestion */ module.exports = { /** - * Builds /categories [string:game] + * Builds /suggest [title:string] [description:string] */ data: new SlashCommandBuilder() .setName("suggest") diff --git a/GuildCommandInteractions/verify.js b/GuildCommandInteractions/verify.js new file mode 100644 index 0000000..661e887 --- /dev/null +++ b/GuildCommandInteractions/verify.js @@ -0,0 +1,77 @@ +const { ActionRowBuilder, SlashCommandBuilder, ButtonBuilder } = require("@discordjs/builders"); +const { EmbedBuilder, ButtonStyle } = require("discord.js"); +const tokens = require("../index.js"); + +/** + * Function to link Discord account and SRC account + */ +module.exports = { + /** + * Builds /verify [username:string] + */ + data: new SlashCommandBuilder() + .setName("verify") + .setDescription("Link your Discord account to your SRC account.") + .addStringOption(option => + option.setName("username") + .setDescription("Speedrun.com username") + .setRequired(true) + ), + async execute(params) { + const { interaction, client } = params; + const channel = await client.channels.cache.get("815040942930919425"); + const username = interaction.options.get("username").value; + const isVerified = !!(await tokens.db.db("accounts").collection("users").findOne({ + discordID: interaction.user.id + })); + if(isVerified) { + await interaction.editReply({ + content: 'You are already verified. Please contact <@168420049462362112> if this is a mistake or to unverify.' + }); + return; + } + const srcAccount = await tokens.fetch(`https://www.speedrun.com/api/v1/users/${username}`); + if(!srcAccount.data) { + interaction.editReply({ + content: `User ${username} not found.` + }); + return; + } + + let date = new Date().toISOString().slice(0, 10); + let embed = new EmbedBuilder() + .setColor("#118855") + .setTitle('User Requesting Verification') + .setFooter({ text: `${date}` }) + .setThumbnail(srcAccount.data.assets.image.uri) + .addFields([ + { name: 'User:', value: `<@${interaction.user.id}>` }, + { name: 'Tag:', value: interaction.user.tag }, + { name: "Speedrun.com account:", value: `[${srcAccount.data.names.international}](${srcAccount.data.weblink})`} + ]); + const verifyId = JSON.stringify({ + discordID: interaction.user.id, + srcID: srcAccount.data.id, + customId: 'verify', + }); + const rejectId = JSON.stringify({ + customId: 'reject' + }); + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId(verifyId) + .setLabel('Accept') + .setStyle(ButtonStyle.Success), + new ButtonBuilder() + .setCustomId(rejectId) + .setLabel('Reject') + .setStyle(ButtonStyle.Danger), + ); + + await channel.send({ embeds: [embed], components: [row] }); + await interaction.editReply({ + content: 'Your request has been submitted. You will receive the verified role when reviewed.' + }); + }, +}; \ No newline at end of file diff --git a/SelectMenuInteractions/category.js b/SelectMenuInteractions/category.js new file mode 100644 index 0000000..655c7a0 --- /dev/null +++ b/SelectMenuInteractions/category.js @@ -0,0 +1,136 @@ +const { ActionRowBuilder, SelectMenuBuilder } = require("discord.js"); +const { SlashCommandBuilder } = require("@discordjs/builders"); + +/** + * Returns options depending on previously selected option + */ +module.exports = { + data: 'category', + async execute(params) { + const { interaction } = params; + let options = { + "General": [ + { + label: "Hypixel Speedruns Discord", + description: "Hypixel Speedruns Discord Link", + value: "Hypixel Speedruns Discord", + }, + { + label: "Hypixel Server Parkour Discord", + description: "Hypixel Server Parkour Discord Link", + value: "Hypixel Server Parkour Discord", + }, + { + label: "Hypixel SkyBlock Speedruns Discord", + description: "Hypixel SkyBlock Speedruns Discord Link", + value: "Hypixel SkyBlock Speedruns Discord", + }, + { + label: "Series", + description: "Hypixel Series Link", + value: "Series", + }, + { + label: "Twitter", + description: "Hypixel Speedruns Twitter", + value: "Twitter", + }, + ], + "Games": [ + { + label: "SkyWars", + value: "SkyWars", + }, + { + label: "BedWars", + value: "BedWars", + }, + { + label: "Category Extensions", + value: "Category Extensions", + }, + { + label: "Arcade Games", + value: "Arcade Games", + }, + { + label: "Classic Games", + value: "Classic Games", + }, + { + label: "SMP", + value: "SMP", + }, + { + label: "The Pit", + value: "The Pit", + }, + { + label: "Server Parkour", + value: "Server Parkour", + }, + ], + "Maps": [ + { + label: "Zombie Apocalypse", + value: "Zombie Apocalypse", + }, + { + label: "Wrath of the Fallen", + value: "Wrath of the Fallen", + }, + { + label: "Herobrine's Mansion", + value: "Herobrine's Mansion", + }, + { + label: "Herobrine's Return", + value: "Herobrine's Return", + }, + { + label: "Minecraft Star Wars", + value: "Minecraft Star Wars", + }, + { + label: "Creeper Dungeon", + value: "Creeper Dungeon", + }, + ], + "Speedrun.com": [ + { + label: "Support Hub", + description: "Speedrun.com support", + value: "Support Hub", + }, + { + label: "Knowledge Base", + description: "Speedrun.com general site information", + value: "Knowledge Base", + }, + { + label: "Speedrun.com Discord", + description: "Speedrun.com general Discord", + value: "Speedrun.com Discord", + }, + { + label: "Graphic Assets", + description: "Speedrun.com Assets", + value: "Graphic Assets", + }, + { + label: "Speedrun.com Twitter", + description: "Speedrun.com general Twitter", + value: "Speedrun.com Twitter", + }, + ] + }[interaction.values[0]]; + const row = new ActionRowBuilder() + .addComponents( + new SelectMenuBuilder() + .setCustomId("link") + .setPlaceholder("Nothing selected") + .addOptions(options), + ); + return await interaction.update({ content: "Please select a link!", components: [row] }); + }, +}; \ No newline at end of file diff --git a/SelectMenuInteractions/link.js b/SelectMenuInteractions/link.js new file mode 100644 index 0000000..fb388aa --- /dev/null +++ b/SelectMenuInteractions/link.js @@ -0,0 +1,45 @@ +const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js"); + +/** + * Returns links for /hypixel + */ +module.exports = { + data: "link", + async execute(params) { + const { interaction } = params; + const url = { + "Hypixel Speedruns Discord": "https://discord.gg/HhNKdB9FJk", + "Hypixel Server Parkour Discord": "https://discord.gg/RJTk7Bv", + "Hypixel SkyBlock Speedruns Discord": "https://discord.gg/vskJtfR", + "Series": "https://www.speedrun.com/hypixel", + "Twitter": "https://twitter.com/HSpeedrunning", + "SkyWars": "https://www.speedrun.com/hypixel_sw", + "BedWars": "https://www.speedrun.com/hypixel_bw", + "Category Extensions": "https://www.speedrun.com/hypixel_ce", + "Arcade Games": "https://www.speedrun.com/hypixel_ag", + "Classic Games": "https://www.speedrun.com/hypixel_cg", + "SMP": "https://www.speedrun.com/hypixel_smp", + "The Pit": "https://www.speedrun.com/hypixel_tp", + "Server Parkour": "https://www.speedrun.com/mcm_hsp", + "Zombie Apocalypse": "https://www.speedrun.com/mcm_za", + "Wrath of the Fallen": "https://www.speedrun.com/mcm_wotf", + "Herobrine's Mansion": "https://www.speedrun.com/mcm_hm", + "Herobrine's Return": "https://www.speedrun.com/mcm_hr", + "Minecraft Star Wars": "https://www.speedrun.com/mcm_sw", + "Creeper Dungeon": "https://www.speedrun.com/mcm_cd", + "Support Hub": "https://www.speedrun.com/knowledgebase/supporthub", + "Knowledge Base": "https://www.speedrun.com/knowledgebase", + "Speedrun.com Discord": "https://discord.gg/0h6sul1ZwHVpXJmK", + "Graphic Assets": "https://www.speedrun.com/knowledgebase/graphic-assets", + "Speedrun.com Twitter": "https://twitter.com/speedruncom", + }[interaction.values[0]]; + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setLabel(interaction.values[0]) + .setStyle(ButtonStyle.Link) + .setURL(url), + ); + await interaction.update({ content: interaction.values[0] + " Link:", components: [row] }); + }, +}; \ No newline at end of file diff --git a/guildcommands/hypixel.js b/guildcommands/hypixel.js deleted file mode 100644 index aa52b3d..0000000 --- a/guildcommands/hypixel.js +++ /dev/null @@ -1,271 +0,0 @@ -const { ActionRowBuilder, SelectMenuBuilder, ButtonBuilder, InteractionType, ButtonStyle } = require("discord.js"); -const { SlashCommandBuilder } = require("@discordjs/builders"); - -/** - * Function to provide a link to a requested site - */ -module.exports = { - /** - * Builds /hypixel - */ - data: new SlashCommandBuilder() - .setName("hypixel") - .setDescription("Provides helpful links for Hypixel Speedruns"), - async execute(params) { - const { interaction } = params; - // Initial running of the command - if(interaction.type === InteractionType.ApplicationCommand) { - const row = new ActionRowBuilder() - .addComponents( - new SelectMenuBuilder() - .setCustomId("type") - .setPlaceholder("Nothing selected") - .addOptions([ - { - label: "General", - description: "Get links to general Hypixel Speedruns Information", - value: "General", - }, - { - label: "Games", - description: "Get links to Hypixel Speedrun Games", - value: "Games", - }, - { - label: "Maps", - description: "Get links to Hypixel Speedrun Maps", - value: "Maps", - }, - { - label: "Speedrun.com", - description: "Links to speedrun.com resources", - value: "Speedrun.com", - }, - ]), - ); - return await interaction.editReply({ content: "Please select a category!", components: [row] }); - } else if (interaction.isSelectMenu()) { - // Second menu - if(interaction.customId == "type") { - let options = ""; - switch(interaction.values[0]) { - case "General": - options = [ - { - label: "Hypixel Speedruns Discord", - description: "Hypixel Speedruns Discord Link", - value: "Hypixel Speedruns Discord", - }, - { - label: "Hypixel Server Parkour Discord", - description: "Hypixel Server Parkour Discord Link", - value: "Hypixel Server Parkour Discord", - }, - { - label: "Hypixel SkyBlock Speedruns Discord", - description: "Hypixel SkyBlock Speedruns Discord Link", - value: "Hypixel SkyBlock Speedruns Discord", - }, - { - label: "Series", - description: "Hypixel Series Link", - value: "Series", - }, - { - label: "Twitter", - description: "Hypixel Speedruns Twitter", - value: "Twitter", - }, - ]; - break; - case "Games": - options = [ - { - label: "SkyWars", - value: "SkyWars", - }, - { - label: "BedWars", - value: "BedWars", - }, - { - label: "Category Extensions", - value: "Category Extensions", - }, - { - label: "Arcade Games", - value: "Arcade Games", - }, - { - label: "Classic Games", - value: "Classic Games", - }, - { - label: "SMP", - value: "SMP", - }, - { - label: "The Pit", - value: "The Pit", - }, - { - label: "Server Parkour", - value: "Server Parkour", - }, - ]; - break; - case "Maps": - options = [ - { - label: "Zombie Apocalypse", - value: "Zombie Apocalypse", - }, - { - label: "Wrath of the Fallen", - value: "Wrath of the Fallen", - }, - { - label: "Herobrine's Mansion", - value: "Herobrine's Mansion", - }, - { - label: "Herobrine's Return", - value: "Herobrine's Return", - }, - { - label: "Minecraft Star Wars", - value: "Minecraft Star Wars", - }, - { - label: "Creeper Dungeon", - value: "Creeper Dungeon", - }, - ]; - break; - case "Speedrun.com": - options = [ - { - label: "Support Hub", - description: "Speedrun.com support", - value: "Support Hub", - }, - { - label: "Knowledge Base", - description: "Speedrun.com general site information", - value: "Knowledge Base", - }, - { - label: "Speedrun.com Discord", - description: "Speedrun.com general Discord", - value: "Speedrun.com Discord", - }, - { - label: "Graphic Assets", - description: "Speedrun.com Assets", - value: "Graphic Assets", - }, - { - label: "Speedrun.com Twitter", - description: "Speedrun.com general Twitter", - value: "Speedrun.com Twitter", - }, - ]; - break; - } - const row = new ActionRowBuilder() - .addComponents( - new SelectMenuBuilder() - .setCustomId("link") - .setPlaceholder("Nothing selected") - .addOptions(options), - ); - return await interaction.update({ content: "Please select a link!", components: [row] }); - } else if(interaction.customId == "link") { - // Third menu - let url; - switch(interaction.values[0]) { - case "Hypixel Speedruns Discord": - url = "https://discord.gg/HhNKdB9FJk"; - break; - case "Hypixel Server Parkour Discord": - url = "https://discord.gg/RJTk7Bv"; - break; - case "Hypixel SkyBlock Speedruns Discord": - url = "https://discord.gg/vskJtfR"; - break; - case "Series": - url = "https://www.speedrun.com/hypixel"; - break; - case "Twitter": - url = "https://twitter.com/HSpeedrunning"; - break; - case "SkyWars": - url = "https://www.speedrun.com/hypixel_sw"; - break; - case "BedWars": - url = "https://www.speedrun.com/hypixel_bw"; - break; - case "Category Extensions": - url = "https://www.speedrun.com/hypixel_ce"; - break; - case "Arcade Games": - url = "https://www.speedrun.com/hypixel_ag"; - break; - case "Classic Games": - url = "https://www.speedrun.com/hypixel_cg"; - break; - case "SMP": - url = "https://www.speedrun.com/hypixel_smp"; - break; - case "The Pit": - url = "https://www.speedrun.com/hypixel_tp"; - break; - case "Server Parkour": - url = "https://www.speedrun.com/mcm_hsp"; - break; - case "Zombie Apocalypse": - url = "https://www.speedrun.com/mcm_za"; - break; - case "Wrath of the Fallen": - url = "https://www.speedrun.com/mcm_wotf"; - break; - case "Herobrine's Mansion": - url = "https://www.speedrun.com/mcm_hm"; - break; - case "Herobrine's Return": - url = "https://www.speedrun.com/mcm_hr"; - break; - case "Minecraft Star Wars": - url = "https://www.speedrun.com/mcm_sw"; - break; - case "Creeper Dungeon": - url = "https://www.speedrun.com/mcm_cd"; - break; - case "Support Hub": - url = "https://www.speedrun.com/knowledgebase/supporthub"; - break; - case "Knowledge Base": - url = "https://www.speedrun.com/knowledgebase"; - break; - case "Speedrun.com Discord": - url = "https://discord.gg/0h6sul1ZwHVpXJmK"; - break; - case "Graphic Assets": - url = "https://www.speedrun.com/knowledgebase/graphic-assets"; - break; - case "Speedrun.com Twitter": - url = "https://twitter.com/speedruncom"; - break; - } - const row = new ActionRowBuilder() - .addComponents( - new ButtonBuilder() - .setLabel(interaction.values[0]) - .setStyle(ButtonStyle.Link) - .setURL(url), - ); - await interaction.update({ content: interaction.values[0] + " Link:", components: [row] }); - } - } - }, -}; \ No newline at end of file diff --git a/index.js b/index.js index f897c53..07ce3c9 100644 --- a/index.js +++ b/index.js @@ -25,17 +25,25 @@ const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBit client.commands = new Collection(); client.msgCommands = new Collection(); client.guildCommands = new Collection(); +client.buttonCommands = new Collection(); +client.selectCommands = new Collection(); -getCommands("./commands", (command) => { +getCommands("./CommandInteractions", (command) => { client.commands.set(command.data.name, command); }); -getCommands("./messagecommands", (command) => { - client.msgCommands.set(command.data.name, command); -}); -getCommands("./guildcommands", (command) => { +getCommands("./GuildCommandInteractions", (command) => { client.guildCommands.set(command.data.name, command); }); -getCommands("./scheduledcommands", (command) => { +getCommands("./ButtonInteractions", (command) => { + client.buttonCommands.set(command.data, command); +}); +getCommands("./SelectMenuInteractions", (command) => { + client.selectCommands.set(command.data, command); +}); +getCommands("./MessageCommands", (command) => { + client.msgCommands.set(command.data.name, command); +}); +getCommands("./ScheduledCommands", (command) => { cron.schedule(command.data.interval, () => { command.execute(client); }); @@ -55,8 +63,8 @@ const rest = new REST({ version: "10" }).setToken(token); // Sets bot activity and announces that bot is ready for use client.once("ready", async () => { client.user.setActivity("speedrun.com | /help", { type: ActivityType.Watching }); - console.log("Ready!"); - + await dbclient.connect(); + try { console.log("Started refreshing application (/) commands."); @@ -116,7 +124,18 @@ client.on("interactionCreate", async interaction => { await interaction.editReply({ content: "There was an error while executing this command!", ephemeral: true }); } } else if(interaction.isSelectMenu()) { - await client.guildCommands.get("hypixel").execute(interaction); + if(!client.selectCommands.has(interaction.customId)) return; + await client.selectCommands.get(interaction.customId).execute({ + interaction, + client + }); + } else if(interaction.isButton()) { + const customId = JSON.parse(interaction.customId).customId; + if(!client.buttonCommands.has(customId)) return; + await client.buttonCommands.get(customId).execute({ + interaction, + client + }); } }); diff --git a/messagecommands/banlist.js b/messagecommands/banlist.js index 6cdc72a..d2ef8ad 100644 --- a/messagecommands/banlist.js +++ b/messagecommands/banlist.js @@ -51,9 +51,7 @@ async function add(id, message) { owner: message.author.id, time: date }; - await token.db.connect(); await token.db.db("banned_runners").collection("mc").insertOne(doc); - await token.db.close(); return await message.reply("Player added to banlist"); } @@ -70,13 +68,10 @@ async function del(id, message) { return await message.reply("Player does not exist"); } const query = { id: player.id }; - await token.db.connect(); const result = await token.db.db("banned_runners").collection("mc").deleteMany(query); if (result.deletedCount >= 1) { - await token.db.close(); return await message.reply("Successfully deleted player."); } else { - await token.db.close(); return await message.reply("Player did not exist in banlist"); } } @@ -87,10 +82,8 @@ async function del(id, message) { * @returns message reply */ async function list(message) { - await token.db.connect(); const cursor = token.db.db("banned_runners").collection("mc").find(); let results = await cursor.toArray(); - await token.db.close(); let str = "```"; for(const player of results) { const player2 = await token.fetchMojang(`https://api.mojang.com/user/profiles/${player.id}/names`); @@ -112,9 +105,7 @@ async function search(id, message) { return await message.reply("Player does not exist"); } const query = { id: player.id }; - await token.db.connect(); const result = await token.db.db("banned_runners").collection("mc").findOne(query); - await token.db.close(); if(!result) { return await message.reply("Player is not in banlist"); } diff --git a/messagecommands/check.js b/messagecommands/check.js index 1003758..881f7d0 100644 --- a/messagecommands/check.js +++ b/messagecommands/check.js @@ -58,10 +58,8 @@ module.exports = { } // Checks if player is in banlist or known runners const query = { id: player.id }; - await token.db.connect(); const searchResult = await token.db.db("banned_runners").collection("mc").findOne(query); const searchResult2 = await token.db.db("known_runners").collection("mc").findOne(query); - await token.db.close(); if(searchResult) { result += "\t" + player.name + " (**Banlist**)\n"; } diff --git a/messagecommands/runners.js b/messagecommands/runners.js index e32c03b..6c03069 100644 --- a/messagecommands/runners.js +++ b/messagecommands/runners.js @@ -63,14 +63,11 @@ async function add(id, account, message) { account: src.data.id }; const query = { id: player.id }; - await token.db.connect(); const result = await token.db.db("known_runners").collection("mc").findOne(query); if(!result) { await token.db.db("known_runners").collection("mc").insertOne(doc); - await token.db.close(); return await message.reply("Player added to known runners"); } - await token.db.close(); return await message.reply("Player already known"); } @@ -90,13 +87,10 @@ async function del(id, message) { return await message.reply("Player does not exist"); } const query = { id: player.id }; - await token.db.connect(); const result = await token.db.db("known_runners").collection("mc").deleteMany(query); if (result.deletedCount >= 1) { - await token.db.close(); return await message.reply("Successfully deleted player."); } else { - await token.db.close(); return await message.reply("Player did not exist in known runners"); } } @@ -107,10 +101,8 @@ async function del(id, message) { * @returns message reply */ async function list(message) { - await token.db.connect(); const cursor = token.db.db("known_runners").collection("mc").find(); let results = await cursor.toArray(); - await token.db.close(); let str = "```"; for(const player of results) { const player2 = await token.fetchMojang(`https://api.mojang.com/user/profiles/${player.id}/names`); @@ -135,9 +127,7 @@ async function search(id, message) { return await message.reply("Player does not exist"); } const query = { id: player.id }; - await token.db.connect(); const result = await token.db.db("known_runners").collection("mc").findOne(query); - await token.db.close(); if(!result) { return await message.reply("Player is not in known runners"); } @@ -171,13 +161,11 @@ async function searchSRC(id, message) { return await message.reply("SRC user does not exist"); } const query = { account: src.data.id }; - await token.db.connect(); const result = await token.db.db("known_runners").collection("mc").find(query); if(!result.hasNext) { return await message.reply("Player is not in known runners"); } const accounts = await result.toArray(); - await token.db.close(); const embed = new EmbedBuilder() .setColor("#118855") .setTitle(`Name: ${src.data.names.international}`)