From 618dc45e8350676a671495a1180987eed7d8771b Mon Sep 17 00:00:00 2001 From: VB2007 Date: Thu, 20 Nov 2025 19:21:00 +0100 Subject: [PATCH 01/20] created word-leaderboard.js command file --- src/commands/fun/word-leaderboard.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/commands/fun/word-leaderboard.js diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js new file mode 100644 index 00000000..9cbd5490 --- /dev/null +++ b/src/commands/fun/word-leaderboard.js @@ -0,0 +1,7 @@ +import { SlashCommandBuilder } from "discord.js"; +import { query } from "../../helpers/db.js"; + +export default { + data: new SlashCommandBuilder(), + async execute(interaction) {}, +}; From b0d96aa6571a631d08d4ca86ff7220d93c7bdd2f Mon Sep 17 00:00:00 2001 From: VB2007 Date: Thu, 20 Nov 2025 19:23:28 +0100 Subject: [PATCH 02/20] created command builder for new command --- src/commands/fun/word-leaderboard.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index 9cbd5490..3653dd9c 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -2,6 +2,19 @@ import { SlashCommandBuilder } from "discord.js"; import { query } from "../../helpers/db.js"; export default { - data: new SlashCommandBuilder(), + data: new SlashCommandBuilder() + .setName("word-leaderboard") + .setDescription( + "Counts a specified word in the current server and sends back a leaderboard with the users who used that word the most." + ) + .addStringOption((option) => + option + .setName("word") + .setDescription("The word that will get counted.") + .setRequired(true) + .setMinLength(2) + .setMaxLength(12) + ) + .setDMPermission(false), async execute(interaction) {}, }; From ad00c9b3980ce528b6d0017f6a8499427d809982 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Thu, 20 Nov 2025 19:24:56 +0100 Subject: [PATCH 03/20] added guild check --- src/commands/fun/word-leaderboard.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index 3653dd9c..9c8b6d42 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -1,4 +1,5 @@ import { SlashCommandBuilder } from "discord.js"; +import { embedReplyPrimaryColor } from "../../helpers/embeds/embed-reply.js"; import { query } from "../../helpers/db.js"; export default { @@ -16,5 +17,12 @@ export default { .setMaxLength(12) ) .setDMPermission(false), - async execute(interaction) {}, + async execute(interaction) { + const guildCheck = checkIfNotInGuild(commandName, interaction); + if (guildCheck) { + return await replyAndLog(interaction, guildCheck); + } + + const targetWord = interaction.options.getString("word"); + }, }; From d394b82b011507e7dd007674a64ec65adb83401d Mon Sep 17 00:00:00 2001 From: VB2007 Date: Thu, 20 Nov 2025 19:25:07 +0100 Subject: [PATCH 04/20] updated packages --- package-lock.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 34701662..1d77c292 100755 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "discordbot", - "version": "4.1.1", + "version": "4.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "discordbot", - "version": "4.1.1", + "version": "4.2.0", "license": "AGPL-3.0-only", "dependencies": { "ajv": "^8.17.1", @@ -1441,9 +1441,9 @@ "license": "MIT" }, "node_modules/baseline-browser-mapping": { - "version": "2.8.29", - "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.29.tgz", - "integrity": "sha512-sXdt2elaVnhpDNRDz+1BDx1JQoJRuNk7oVlAlbGiFkLikHCAQiccexF/9e91zVi6RCgqspl04aP+6Cnl9zRLrA==", + "version": "2.8.30", + "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.30.tgz", + "integrity": "sha512-aTUKW4ptQhS64+v2d6IkPzymEzzhw+G0bA1g3uBRV3+ntkH+svttKseW5IOR4Ed6NUVKqnY7qT3dKvzQ7io4AA==", "dev": true, "license": "Apache-2.0", "bin": { @@ -1553,9 +1553,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001755", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001755.tgz", - "integrity": "sha512-44V+Jm6ctPj7R52Na4TLi3Zri4dWUljJd+RDm+j8LtNCc/ihLCT+X1TzoOAkRETEWqjuLnh9581Tl80FvK7jVA==", + "version": "1.0.30001756", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001756.tgz", + "integrity": "sha512-4HnCNKbMLkLdhJz3TToeVWHSnfJvPaq6vu/eRP0Ahub/07n484XHhBF5AJoSGHdVrS8tKFauUQz8Bp9P7LVx7A==", "dev": true, "funding": [ { @@ -1998,9 +1998,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.256", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.256.tgz", - "integrity": "sha512-uqYq1IQhpXXLX+HgiXdyOZml7spy4xfy42yPxcCCRjswp0fYM2X+JwCON07lqnpLEGVCj739B7Yr+FngmHBMEQ==", + "version": "1.5.258", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.258.tgz", + "integrity": "sha512-rHUggNV5jKQ0sSdWwlaRDkFc3/rRJIVnOSe9yR4zrR07m3ZxhP4N27Hlg8VeJGGYgFTxK5NqDmWI4DSH72vIJg==", "dev": true, "license": "ISC" }, From d2af3193127fecfabee4a0077ff3d27369013f95 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Thu, 20 Nov 2025 20:27:58 +0100 Subject: [PATCH 05/20] started implementation with query, added missing import --- src/commands/fun/word-leaderboard.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index 9c8b6d42..e5a2b054 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -1,12 +1,14 @@ import { SlashCommandBuilder } from "discord.js"; +import { checkIfNotInGuild } from "../../helpers/command-validation/general.js"; import { embedReplyPrimaryColor } from "../../helpers/embeds/embed-reply.js"; import { query } from "../../helpers/db.js"; export default { data: new SlashCommandBuilder() .setName("word-leaderboard") + // Counts a specified word in the current server and sends back a leaderboard with the users who used that word the most. .setDescription( - "Counts a specified word in the current server and sends back a leaderboard with the users who used that word the most." + "Gives back a word count leaderboard with the top users who used that word the most." ) .addStringOption((option) => option @@ -24,5 +26,12 @@ export default { } const targetWord = interaction.options.getString("word"); + const currentServerId = interaction.guild.id; + + const usersQuery = await db.query( + `SELECT COUNT(DISTINCT senderUserId), senderUserName FROM messageLog WHERE serverId = ${currentServerId} AND messageContent LIKE %${targetWord}%` + ); + + console.log(usersQuery); }, }; From 8003525a105d8f7f98ccc3e90dce9e7135859e51 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Thu, 20 Nov 2025 20:29:55 +0100 Subject: [PATCH 06/20] commented out other debug darwin logs --- src/helpers/darwin/darwinCache.js | 4 ++-- src/index.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/darwin/darwinCache.js b/src/helpers/darwin/darwinCache.js index d3b8ca10..b462fe7e 100644 --- a/src/helpers/darwin/darwinCache.js +++ b/src/helpers/darwin/darwinCache.js @@ -32,7 +32,7 @@ export const addToCache = async (directVideoUrl, forumPostUrl, videoTitle) => { try { const exists = await isInCache(directVideoUrl); if (exists) { - console.log(`URL already in cache: ${directVideoUrl}`); + // console.log(`URL already in cache: ${directVideoUrl}`); return true; } @@ -76,7 +76,7 @@ export const addToCache = async (directVideoUrl, forumPostUrl, videoTitle) => { export const isInCache = async (url) => { try { const videoId = extractVideoId(url); - console.log(`Checking "${url}" (ID: ${videoId}) in Darwin's cache`); + // console.log(`Checking "${url}" (ID: ${videoId}) in Darwin's cache`); const result = await query( "SELECT directVideoUrl FROM darwinCache WHERE directVideoUrl = ? OR videoId = ?", diff --git a/src/index.js b/src/index.js index b50936d9..b44fb321 100644 --- a/src/index.js +++ b/src/index.js @@ -79,7 +79,7 @@ client.once(Events.ClientReady, (readyClient) => { setInterval(() => { if (darwinProcessRunning) { - console.log("Darwin process already running, skipping this execution"); + // console.log("Darwin process already running, skipping this execution"); return; } From aab83c07c806ca3abc4b5fb083f173acf4fde664 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Thu, 20 Nov 2025 20:31:21 +0100 Subject: [PATCH 07/20] fixed errors in new command --- src/commands/fun/word-leaderboard.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index e5a2b054..45ec7851 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -3,9 +3,11 @@ import { checkIfNotInGuild } from "../../helpers/command-validation/general.js"; import { embedReplyPrimaryColor } from "../../helpers/embeds/embed-reply.js"; import { query } from "../../helpers/db.js"; +const commandName = "word-leaderboard"; + export default { data: new SlashCommandBuilder() - .setName("word-leaderboard") + .setName(commandName) // Counts a specified word in the current server and sends back a leaderboard with the users who used that word the most. .setDescription( "Gives back a word count leaderboard with the top users who used that word the most." @@ -28,7 +30,7 @@ export default { const targetWord = interaction.options.getString("word"); const currentServerId = interaction.guild.id; - const usersQuery = await db.query( + const usersQuery = await query( `SELECT COUNT(DISTINCT senderUserId), senderUserName FROM messageLog WHERE serverId = ${currentServerId} AND messageContent LIKE %${targetWord}%` ); From f803002144e482ae24ff815ce9fef31d06b2f9d7 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Thu, 20 Nov 2025 21:04:22 +0100 Subject: [PATCH 08/20] fixed sql query --- src/commands/fun/word-leaderboard.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index 45ec7851..c90b1f9c 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -31,7 +31,13 @@ export default { const currentServerId = interaction.guild.id; const usersQuery = await query( - `SELECT COUNT(DISTINCT senderUserId), senderUserName FROM messageLog WHERE serverId = ${currentServerId} AND messageContent LIKE %${targetWord}%` + `SELECT senderUserId, senderUserName, COUNT(*) as wordCount + FROM messageLog + WHERE serverId = ? AND messageContent LIKE ? + GROUP BY senderUserId + ORDER BY wordCount DESC + LIMIT 10`, + [currentServerId, `%${targetWord}%`] ); console.log(usersQuery); From 796a3e71bb646b4bc9666e48c5cccd58352c680f Mon Sep 17 00:00:00 2001 From: VB2007 Date: Thu, 20 Nov 2025 21:11:36 +0100 Subject: [PATCH 09/20] updated imports, started writing embed reply --- src/commands/fun/word-leaderboard.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index c90b1f9c..7725fd30 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -1,7 +1,8 @@ import { SlashCommandBuilder } from "discord.js"; -import { checkIfNotInGuild } from "../../helpers/command-validation/general.js"; import { embedReplyPrimaryColor } from "../../helpers/embeds/embed-reply.js"; import { query } from "../../helpers/db.js"; +import { checkIfNotInGuild } from "../../helpers/command-validation/general.js"; +import { replyAndLog } from "../../helpers/reply.js"; const commandName = "word-leaderboard"; @@ -39,7 +40,10 @@ export default { LIMIT 10`, [currentServerId, `%${targetWord}%`] ); - console.log(usersQuery); + + const embedReply = embedReplyPrimaryColor(`Word Leaderboard: "${targetWord}"`, "", interaction); + + return replyAndLog(interaction, embedReply); }, }; From 457acd09dfb5724c5deb0970654dd0339c75ea2c Mon Sep 17 00:00:00 2001 From: VB2007 Date: Thu, 20 Nov 2025 21:30:16 +0100 Subject: [PATCH 10/20] commented out messageCreate console logs --- src/events/scripts/messageCreate/messageLogging.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/events/scripts/messageCreate/messageLogging.js b/src/events/scripts/messageCreate/messageLogging.js index 01c9bca3..52b52804 100644 --- a/src/events/scripts/messageCreate/messageLogging.js +++ b/src/events/scripts/messageCreate/messageLogging.js @@ -29,9 +29,9 @@ export const logToDB = async (message) => { ] ); - console.log( - `Logged message "${message.content}" to database from ${senderUserName} in ${serverName}.` - ); + // console.log( + // `Logged message "${message.content}" to database from ${senderUserName} in ${serverName}.` + // ); } } } catch (error) { From f8699b96a5fd11a0a3ce45087fed86dd03e04530 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Thu, 20 Nov 2025 21:36:45 +0100 Subject: [PATCH 11/20] added 1st part of the description to embed builder --- src/commands/fun/word-leaderboard.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index 7725fd30..618a5a2a 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -42,7 +42,11 @@ export default { ); console.log(usersQuery); - const embedReply = embedReplyPrimaryColor(`Word Leaderboard: "${targetWord}"`, "", interaction); + const embedReply = embedReplyPrimaryColor( + `Word Leaderboard: "${targetWord}"`, + `${usersQuery.length !== 0 ? `Leaderboard of users whose messages contained the word "${targetWord}" the most:` : `No user has used the word "${targetWord}" in their messages so far.`}`, + interaction + ); return replyAndLog(interaction, embedReply); }, From 31a85b0a2712202aa66a8336af63e622c57fe6b4 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Thu, 20 Nov 2025 21:37:32 +0100 Subject: [PATCH 12/20] updated embed description formatting --- src/commands/fun/word-leaderboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index 618a5a2a..abcb2798 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -44,7 +44,7 @@ export default { const embedReply = embedReplyPrimaryColor( `Word Leaderboard: "${targetWord}"`, - `${usersQuery.length !== 0 ? `Leaderboard of users whose messages contained the word "${targetWord}" the most:` : `No user has used the word "${targetWord}" in their messages so far.`}`, + `${usersQuery.length !== 0 ? `Leaderboard of users whose messages contained the word **${targetWord}** the most:` : `No user has used the word **${targetWord}** in their messages so far.`}`, interaction ); From a893529198d5916f5818858392ed8d010157f261 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Fri, 21 Nov 2025 00:06:47 +0100 Subject: [PATCH 13/20] deleted already executed migration script --- src/sql/darwinCache/migrate-to-new-schema.sql | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/sql/darwinCache/migrate-to-new-schema.sql diff --git a/src/sql/darwinCache/migrate-to-new-schema.sql b/src/sql/darwinCache/migrate-to-new-schema.sql deleted file mode 100644 index 22c9bb2a..00000000 --- a/src/sql/darwinCache/migrate-to-new-schema.sql +++ /dev/null @@ -1,14 +0,0 @@ -ALTER TABLE `darwinCache` -CHANGE COLUMN `videoUrl` `directVideoUrl` VARCHAR(255) NOT NULL; - -ALTER TABLE `darwinCache` -ADD COLUMN `forumPostUrl` VARCHAR(255) NOT NULL DEFAULT '' AFTER `directVideoUrl`, -ADD COLUMN `videoTitle` VARCHAR(180) NOT NULL DEFAULT '' AFTER `videoId`; - -ALTER TABLE `darwinCache` -DROP INDEX `videoUrl`; - -ALTER TABLE `darwinCache` -ADD UNIQUE KEY `directVideoUrl` (`directVideoUrl`); - -DESCRIBE `darwinCache`; From 69e303576a0215f4e2052890b6b2da4aa84722c4 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Fri, 21 Nov 2025 00:15:32 +0100 Subject: [PATCH 14/20] added logic for displaying leaderboard --- src/commands/fun/word-leaderboard.js | 30 +++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index abcb2798..b449c788 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -42,9 +42,37 @@ export default { ); console.log(usersQuery); + let leaderboardContent; + const positionEmojis = { + 1: ":first_place:", + 2: ":second_place:", + 3: ":third_place:", + 4: ":number_4:", + 5: ":number_5:", + 6: ":number_6:", + 7: ":number_7:", + 8: ":number_8:", + 9: ":number_9:", + 10: ":number_10:", + }; + + for (let i = 0; i < usersQuery.length; i++) { + const userResult = usersQuery[i]; + const emoji = positionEmojis[i + 1]; + + const username = + (await interaction.guild.members.fetch(userResult.senderUserId).user.username) || + userResult.senderUserName || + "Unkown username"; + + leaderboardContent += `${emoji} <@${userResult.senderUserId}> (${username}): **#${userResult.wordCount}**\n`; + } + const embedReply = embedReplyPrimaryColor( `Word Leaderboard: "${targetWord}"`, - `${usersQuery.length !== 0 ? `Leaderboard of users whose messages contained the word **${targetWord}** the most:` : `No user has used the word **${targetWord}** in their messages so far.`}`, + usersQuery.length !== 0 + ? `Leaderboard of users whose messages contained the word **${targetWord}** the most:\n\n${leaderboardContent}` + : `No user has used the word **${targetWord}** in their messages so far.`, interaction ); From 47962d3b6e837ba94621c38eb44b51238a4d6fb2 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Fri, 21 Nov 2025 00:15:47 +0100 Subject: [PATCH 15/20] fixed promise error --- src/commands/fun/word-leaderboard.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index b449c788..363dbe28 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -60,10 +60,13 @@ export default { const userResult = usersQuery[i]; const emoji = positionEmojis[i + 1]; - const username = - (await interaction.guild.members.fetch(userResult.senderUserId).user.username) || - userResult.senderUserName || - "Unkown username"; + let username; + try { + const member = await interaction.guild.members.fetch(userResult.senderUserId); + username = member.user.username; + } catch (error) { + username = userResult.senderUserName || "Unknown username"; + } leaderboardContent += `${emoji} <@${userResult.senderUserId}> (${username}): **#${userResult.wordCount}**\n`; } From ef9875c74bc00d7a6818e67207cdb5d456a125cd Mon Sep 17 00:00:00 2001 From: VB2007 Date: Fri, 21 Nov 2025 00:18:04 +0100 Subject: [PATCH 16/20] fixed undefined error --- src/commands/fun/word-leaderboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index 363dbe28..e578b8a0 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -42,7 +42,7 @@ export default { ); console.log(usersQuery); - let leaderboardContent; + let leaderboardContent = ""; const positionEmojis = { 1: ":first_place:", 2: ":second_place:", From e346dcaebcecf3f2f340a10fe9a41d27cdcec414 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Fri, 21 Nov 2025 00:21:02 +0100 Subject: [PATCH 17/20] moved positionEmojis to format helper --- src/commands/fun/word-leaderboard.js | 16 ++-------------- src/helpers/format.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index e578b8a0..50b74521 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -1,8 +1,9 @@ import { SlashCommandBuilder } from "discord.js"; import { embedReplyPrimaryColor } from "../../helpers/embeds/embed-reply.js"; -import { query } from "../../helpers/db.js"; +import { positionEmojis } from "../../helpers/format.js"; import { checkIfNotInGuild } from "../../helpers/command-validation/general.js"; import { replyAndLog } from "../../helpers/reply.js"; +import { query } from "../../helpers/db.js"; const commandName = "word-leaderboard"; @@ -43,19 +44,6 @@ export default { console.log(usersQuery); let leaderboardContent = ""; - const positionEmojis = { - 1: ":first_place:", - 2: ":second_place:", - 3: ":third_place:", - 4: ":number_4:", - 5: ":number_5:", - 6: ":number_6:", - 7: ":number_7:", - 8: ":number_8:", - 9: ":number_9:", - 10: ":number_10:", - }; - for (let i = 0; i < usersQuery.length; i++) { const userResult = usersQuery[i]; const emoji = positionEmojis[i + 1]; diff --git a/src/helpers/format.js b/src/helpers/format.js index a6744d52..a9abded9 100644 --- a/src/helpers/format.js +++ b/src/helpers/format.js @@ -15,3 +15,16 @@ export const formatRouletteColor = (color) => { console.error("The color you've provided for the formatRouletteColor() function is invalid."); } }; + +export const positionEmojis = { + 1: ":first_place:", + 2: ":second_place:", + 3: ":third_place:", + 4: ":number_4:", + 5: ":number_5:", + 6: ":number_6:", + 7: ":number_7:", + 8: ":number_8:", + 9: ":number_9:", + 10: ":number_10:", +}; From ffc3ef56f0b5db22ec788bd226ebcb58c964c1c2 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Fri, 21 Nov 2025 00:35:58 +0100 Subject: [PATCH 18/20] changed reply method to deferReply to avoid timeouts --- src/commands/fun/word-leaderboard.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index 50b74521..6de35bbd 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -2,7 +2,7 @@ import { SlashCommandBuilder } from "discord.js"; import { embedReplyPrimaryColor } from "../../helpers/embeds/embed-reply.js"; import { positionEmojis } from "../../helpers/format.js"; import { checkIfNotInGuild } from "../../helpers/command-validation/general.js"; -import { replyAndLog } from "../../helpers/reply.js"; +import { logToFileAndDatabase } from "../../helpers/logger.js"; import { query } from "../../helpers/db.js"; const commandName = "word-leaderboard"; @@ -24,6 +24,8 @@ export default { ) .setDMPermission(false), async execute(interaction) { + await interaction.deferReply(); + const guildCheck = checkIfNotInGuild(commandName, interaction); if (guildCheck) { return await replyAndLog(interaction, guildCheck); @@ -63,10 +65,11 @@ export default { `Word Leaderboard: "${targetWord}"`, usersQuery.length !== 0 ? `Leaderboard of users whose messages contained the word **${targetWord}** the most:\n\n${leaderboardContent}` - : `No user has used the word **${targetWord}** in their messages so far.`, + : `:x: No user has used the word **${targetWord}** in their messages so far.`, interaction ); - return replyAndLog(interaction, embedReply); + await interaction.editReply({ embeds: [embedReply] }); + await logToFileAndDatabase(interaction, JSON.stringify(embedReply.toJSON())); }, }; From 5368c3928e853fd4ed10c69f282a20df07d3b018 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Fri, 21 Nov 2025 00:40:17 +0100 Subject: [PATCH 19/20] removed debug console logging --- src/commands/fun/word-leaderboard.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/commands/fun/word-leaderboard.js b/src/commands/fun/word-leaderboard.js index 6de35bbd..3f119bd6 100644 --- a/src/commands/fun/word-leaderboard.js +++ b/src/commands/fun/word-leaderboard.js @@ -43,7 +43,6 @@ export default { LIMIT 10`, [currentServerId, `%${targetWord}%`] ); - console.log(usersQuery); let leaderboardContent = ""; for (let i = 0; i < usersQuery.length; i++) { From 80d50cceb7ef7648eb6d59d28ee5e3dc1e9194a1 Mon Sep 17 00:00:00 2001 From: VB2007 Date: Fri, 21 Nov 2025 01:59:07 +0100 Subject: [PATCH 20/20] added word-leaderboard to commandData --- src/data/commandData.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/src/data/commandData.csv b/src/data/commandData.csv index 5881c8d7..14e202d6 100644 --- a/src/data/commandData.csv +++ b/src/data/commandData.csv @@ -37,3 +37,4 @@ 193,cigany,fun,"Says ""fuj"" and sends a random pic of a ""person"" from a specific race." 194,cooldown,economy,Lets you check your or other users economy cooldowns for all or a specified economy command. 195,invite,utility,Gives you back a link for inviting the bot to any server where you have permissions to do so. +652,word-leaderboard,fun,Counts a specified word in the current server and sends back a leaderboard with the users who used that word the most through all their previous messages.