From 6533510481aaca4ca0635135f9e106256a736bbe Mon Sep 17 00:00:00 2001 From: admin_rb Date: Mon, 6 Apr 2026 22:31:54 +0200 Subject: [PATCH] Updated more Thumbnails to reliable sources,, fixed quotes leaderboard --- buttons/honor/honors_leaderboard_left.js | 2 +- buttons/honor/honors_leaderboard_right.js | 2 +- buttons/honor/honors_leaderboard_self.js | 2 +- buttons/nuts/nuts_leaderboard_left.js | 2 +- buttons/nuts/nuts_leaderboard_right.js | 2 +- buttons/nuts/nuts_leaderboard_self.js | 2 +- buttons/quotes/quotes_leaderboard_left.js | 75 +++------------ buttons/quotes/quotes_leaderboard_right.js | 71 ++------------ commands/legacy/nuts/nutsLeaderboard.js | 2 +- commands/slash/applications/honors.js | 2 +- commands/slash/applications/quotes.js | 104 ++++++++++++--------- 11 files changed, 91 insertions(+), 175 deletions(-) diff --git a/buttons/honor/honors_leaderboard_left.js b/buttons/honor/honors_leaderboard_left.js index e97e69c..bc40040 100644 --- a/buttons/honor/honors_leaderboard_left.js +++ b/buttons/honor/honors_leaderboard_left.js @@ -23,7 +23,7 @@ module.exports = { }) const embed = new EmbedBuilder() .setTitle('Honors Leaderboard') - .setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png') + .setThumbnail(guild.iconURL({ dynamic: true})) .setDescription(fields.toString()) .setColor('#5865F2') // Discord's blurple color .setFooter({ text: 'Use ◄ ► to navigate' }); diff --git a/buttons/honor/honors_leaderboard_right.js b/buttons/honor/honors_leaderboard_right.js index 55f8878..4c9f05f 100644 --- a/buttons/honor/honors_leaderboard_right.js +++ b/buttons/honor/honors_leaderboard_right.js @@ -21,7 +21,7 @@ module.exports = { }) const embed = new EmbedBuilder() .setTitle('Honors Leaderboard') - .setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png') + .setThumbnail(guild.iconURL({ dynamic: true})) .setDescription(fields.toString()) .setColor('#5865F2') // Discord's blurple color .setFooter({ text: 'Use ◄ ► to navigate' }); diff --git a/buttons/honor/honors_leaderboard_self.js b/buttons/honor/honors_leaderboard_self.js index bea20a5..f357b16 100644 --- a/buttons/honor/honors_leaderboard_self.js +++ b/buttons/honor/honors_leaderboard_self.js @@ -31,7 +31,7 @@ module.exports = { }) const embed = new EmbedBuilder() .setTitle('Honors Leaderboard') - .setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png') + .setThumbnail(guild.iconURL({ dynamic: true})) .setDescription(fields.toString()) .setColor('#5865F2') // Discord's blurple color .setFooter({ text: 'Use ◄ ► to navigate' }); diff --git a/buttons/nuts/nuts_leaderboard_left.js b/buttons/nuts/nuts_leaderboard_left.js index 86908cc..7a557a9 100644 --- a/buttons/nuts/nuts_leaderboard_left.js +++ b/buttons/nuts/nuts_leaderboard_left.js @@ -23,7 +23,7 @@ module.exports = { }) const embed = new EmbedBuilder() .setTitle('Nuts Leaderboard') - .setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png') + .setThumbnail(guild.iconURL({ dynamic: true})) .setDescription(fields.toString()) .setColor('#5865F2') // Discord's blurple color .setFooter({ text: 'Use ◄ ► to navigate' }); diff --git a/buttons/nuts/nuts_leaderboard_right.js b/buttons/nuts/nuts_leaderboard_right.js index 7c41ec1..840a6da 100644 --- a/buttons/nuts/nuts_leaderboard_right.js +++ b/buttons/nuts/nuts_leaderboard_right.js @@ -21,7 +21,7 @@ module.exports = { }) const embed = new EmbedBuilder() .setTitle('Nuts Leaderboard') - .setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png') + .setThumbnail(guild.iconURL({ dynamic: true})) .setDescription(fields.toString()) .setColor('#5865F2') // Discord's blurple color .setFooter({ text: 'Use ◄ ► to navigate' }); diff --git a/buttons/nuts/nuts_leaderboard_self.js b/buttons/nuts/nuts_leaderboard_self.js index edbd454..2eb9fe1 100644 --- a/buttons/nuts/nuts_leaderboard_self.js +++ b/buttons/nuts/nuts_leaderboard_self.js @@ -31,7 +31,7 @@ module.exports = { }) const embed = new EmbedBuilder() .setTitle('Nuts Leaderboard') - .setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png') + .setThumbnail(guild.iconURL({ dynamic: true})) .setDescription(fields.toString()) .setColor('#5865F2') // Discord's blurple color .setFooter({ text: 'Use ◄ ► to navigate' }); diff --git a/buttons/quotes/quotes_leaderboard_left.js b/buttons/quotes/quotes_leaderboard_left.js index 0d6844c..4d8bc23 100644 --- a/buttons/quotes/quotes_leaderboard_left.js +++ b/buttons/quotes/quotes_leaderboard_left.js @@ -1,70 +1,19 @@ -const { EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js'); -const { mClient } = require('../..'); // Adjust the path as needed -function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } +const { quotesLeaderboard } = require("../../commands/slash/applications/quotes"); module.exports = { - name: 'quotes_leaderboard_right', - description: 'Navigate right through the quotes leaderboard', + name: 'quotes_leaderboard_left', + description: 'Navigate left through the quotes leaderboard', async execute(interaction) { - await interaction.deferReply() - const db = mClient.db(process.env.M_DB) - const quotesColl = db.collection('items_quotes') - const maxValue = await quotesColl.countDocuments({ $and: [{ guildID: interaction.guild.id }, { count: { $gt: 0 } }] }) + await interaction.deferReply(); - let skip = interaction.message.embeds[0].data.fields[0].value.split('.') - skip = Number(skip[0]) - 6 - if (skip >= (maxValue - (maxValue % 5))) { - skip = maxValue - (maxValue % 5) - } + // Parse current page from footer + let page = 1; + const footerText = interaction.message.embeds[0]?.footer?.text || ''; + const match = footerText.match(/Page (\d+) of (\d+)/); + if (match) page = Number(match[1]); - const quotesData = await quotesColl.find({ count: { $gt: 0 } }).sort({ count: -1, messageID: -1 }).skip(skip).limit(5).toArray() - const fields = [] + page--; // move to previous page - const guild = await interaction.client.guilds.fetch(interaction.guild.id) - quotesData.forEach(async (data, index) => { - - let channel = await guild.channels.fetch(data.channelID) - let message = await channel.messages.fetch(data.messageID) - await delay(500) - fields.push({ - name: `\u200b`, - value: `${skip + index + 1}. [#${data.messageID}](https://discord.com/channels/${data.guildID}/${data.channelID}/${data.messageID})\r\n**by** <@${data.by}> • ⭐ ${data.count}\r\n${message.content}` - }) - }) - - await delay(5000) - console.log(fields) - const embed = new EmbedBuilder() - .setTitle('- Quotes Leaderboard -') - .setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png') - .setFields(fields) - .setColor('#5865F2') // Discord's blurple color - .setFooter({ text: 'Use ◄ ► to navigate' }); - - const row = new ActionRowBuilder() - .addComponents( - new ButtonBuilder() - .setLabel('◄') - .setStyle(ButtonStyle.Primary) - .setCustomId('quotes_leaderboard_left') - .setDisabled(skip - 6 < 0) - ) - .addComponents( - new ButtonBuilder() - .setLabel('X') - .setStyle(ButtonStyle.Danger) - .setCustomId('abort') - ) - .addComponents( - new ButtonBuilder() - .setLabel('►') - .setStyle(ButtonStyle.Primary) - .setCustomId('quotes_leaderboard_right') - .setDisabled(skip + 4 > maxValue) - ) - await interaction.editReply({ - embeds: [embed], - components: [row] - }) + await quotesLeaderboard(interaction, page); } -}; +}; \ No newline at end of file diff --git a/buttons/quotes/quotes_leaderboard_right.js b/buttons/quotes/quotes_leaderboard_right.js index b5d96e8..81d94e0 100644 --- a/buttons/quotes/quotes_leaderboard_right.js +++ b/buttons/quotes/quotes_leaderboard_right.js @@ -1,70 +1,19 @@ -const { EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js'); -const { mClient } = require('../..'); // Adjust the path as needed -function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } +const { quotesLeaderboard } = require("../../commands/slash/applications/quotes"); module.exports = { name: 'quotes_leaderboard_right', description: 'Navigate right through the quotes leaderboard', async execute(interaction) { - await interaction.deferReply() - const db = mClient.db(process.env.M_DB) - const quotesColl = db.collection('items_quotes') - const maxValue = await quotesColl.countDocuments({ $and: [{ guildID: interaction.guild.id }, { count: { $gt: 0 } }] }) + await interaction.deferReply(); - let skip = interaction.message.embeds[0].data.fields[0].value.split('.') - skip = Number(skip[0]) +4 - if (skip >= (maxValue - (maxValue % 5))) { - skip = maxValue - (maxValue % 5) - } + // Parse current page from footer + let page = 1; + const footerText = interaction.message.embeds[0]?.footer?.text || ''; + const match = footerText.match(/Page (\d+) of (\d+)/); + if (match) page = Number(match[1]); - const quotesData = await quotesColl.find({ count: { $gt: 0 } }).sort({ count: -1, messageID: -1 }).skip(skip).limit(5).toArray() - const fields = [] + page++; // move to next page - const guild = await interaction.client.guilds.fetch(interaction.guild.id) - quotesData.forEach(async (data, index) => { - - let channel = await guild.channels.fetch(data.channelID) - let message = await channel.messages.fetch(data.messageID) - await delay(500) - fields.push({ - name: `\u200b`, - value: `${skip + index + 1}. [#${data.messageID}](https://discord.com/channels/${data.guildID}/${data.channelID}/${data.messageID})\r\n**by** <@${data.by}> • ⭐ ${data.count}\r\n${message.content}` - }) - }) - - await delay(5000) - console.log(fields) - const embed = new EmbedBuilder() - .setTitle('- Quotes Leaderboard -') - .setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png') - .setFields(fields) - .setColor('#5865F2') // Discord's blurple color - .setFooter({ text: 'Use ◄ ► to navigate' }); - - const row = new ActionRowBuilder() - .addComponents( - new ButtonBuilder() - .setLabel('◄') - .setStyle(ButtonStyle.Primary) - .setCustomId('quotes_leaderboard_left') - .setDisabled(skip - 6 < 0) - ) - .addComponents( - new ButtonBuilder() - .setLabel('X') - .setStyle(ButtonStyle.Danger) - .setCustomId('abort') - ) - .addComponents( - new ButtonBuilder() - .setLabel('►') - .setStyle(ButtonStyle.Primary) - .setCustomId('quotes_leaderboard_right') - .setDisabled(skip + 4 > maxValue) - ) - await interaction.editReply({ - embeds: [embed], - components: [row] - }) + await quotesLeaderboard(interaction, page); } -}; +}; \ No newline at end of file diff --git a/commands/legacy/nuts/nutsLeaderboard.js b/commands/legacy/nuts/nutsLeaderboard.js index 724482c..6f47d08 100644 --- a/commands/legacy/nuts/nutsLeaderboard.js +++ b/commands/legacy/nuts/nutsLeaderboard.js @@ -37,7 +37,7 @@ module.exports = { }) const embed = new EmbedBuilder() .setTitle('Nuts Leaderboard') - .setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png') + .setThumbnail(guild.iconURL({ dynamic: true})) .setDescription(fields.toString()) .setColor('#5865F2') // Discord's blurple color .setFooter({ text: 'Use ◄ ► to navigate' }); diff --git a/commands/slash/applications/honors.js b/commands/slash/applications/honors.js index 13651cd..841ccc4 100644 --- a/commands/slash/applications/honors.js +++ b/commands/slash/applications/honors.js @@ -103,7 +103,7 @@ async function honorLeaderboard(interaction) { }) const embed = new EmbedBuilder() .setTitle('- Honors Leaderboard -') - .setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png') + .setThumbnail(guild.iconURL({ dynamic: true})) .setDescription(fields.toString()) .setColor('#5865F2') // Discord's blurple color .setFooter({ text: 'Use ◄ ► to navigate' }); diff --git a/commands/slash/applications/quotes.js b/commands/slash/applications/quotes.js index 61a89c8..ecd1b64 100644 --- a/commands/slash/applications/quotes.js +++ b/commands/slash/applications/quotes.js @@ -267,71 +267,87 @@ async function quotesList(interaction) { }) } -async function quotesLeaderboard(interaction) { - const db = mClient.db(process.env.M_DB) - const quotesColl = db.collection('items_quotes') - let skip = 0 - const minValue = 0 - const maxValue = await quotesColl.countDocuments({ $and: [{ guildID: interaction.guild.id }, { count: { $gt: 0 } }] }) +async function quotesLeaderboard(interaction, page = 1, limit = 5) { + const db = mClient.db(process.env.M_DB); + const quotesColl = db.collection('items_quotes'); - const quotesData = await quotesColl.find({}).sort({ count: -1, messageID: -1 }).skip(skip).limit(5).toArray() - const fields = [] + // Total quotes in the guild + const totalQuotes = await quotesColl.countDocuments({ guildID: interaction.guild.id, count: { $gte: 0 } }); + const totalPages = Math.ceil(totalQuotes / limit); - const guild = await interaction.client.guilds.fetch(interaction.guild.id) - quotesData.forEach(async (data, index) => { + // Clamp page + if (page < 1) page = 1; + if (page > totalPages) page = totalPages; - let channel = await guild.channels.fetch(data.channelID) - let message = await channel.messages.fetch(data.messageID) + const skip = (page - 1) * limit; - await delay(500) - let timestamp = new Date(message.createdTimestamp) - fields.push({ - name: `${index + 1}.`,//`\u200b` , - value: `[#${data.messageID}](https://discord.com/channels/${data.guildID}/${data.channelID}/${data.messageID})\r\n**by** <@${data.by}> • ⭐ ${data.count}\r\n_Posted on **${timestamp}**_\r\n${message.content}` + // Fetch quotes for this page + const quotesData = await quotesColl + .find({ guildID: interaction.guild.id, count: { $gte: 0 } }) + .sort({ count: -1, messageID: -1 }) + .skip(skip) + .limit(limit) + .toArray(); + + // Fallback if no quotes exist + if (!quotesData.length) { + return interaction.editReply({ content: 'No quotes found for this server yet!', components: [] }); + } + + const guild = await interaction.client.guilds.fetch(interaction.guild.id); + + // Fetch all messages concurrently + const fields = await Promise.all( + quotesData.map(async (data, index) => { + try { + const channel = await guild.channels.fetch(data.channelID); + const message = await channel.messages.fetch(data.messageID); + const timestamp = new Date(message.createdTimestamp).toLocaleString('en-US', { + dateStyle: 'medium', + timeStyle: 'short' + }); + + return { + name: `${skip + index + 1}.`, + value: `[#${data.messageID}](https://discord.com/channels/${data.guildID}/${data.channelID}/${data.messageID})\n**by** <@${data.by}> • ⭐ ${data.count}\n_Posted on **${timestamp}**_\n${message.content}` + }; + } catch { + return { + name: `${skip + index + 1}.`, + value: 'Message unavailable.' + }; + } }) + ); - }) - - - await delay(5000) - console.log(fields) - quotesData.sort((a, b) => { - const numA = parseInt(a.name); - const numB = parseInt(b.name); - return numA - numB; - }) - console.log(fields) - + // Build embed const embed = new EmbedBuilder() .setTitle('- Quotes Leaderboard -') - .setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png') + .setThumbnail(guild.iconURL({ dynamic: true })) .setFields(fields) - .setColor('#5865F2') // Discord's blurple color - .setFooter({ text: `Use ◄ ► to navigate\r\n${skip}` }); + .setColor('#5865F2') + .setFooter({ text: `Use ◄ ► to navigate • Page ${page} of ${totalPages}` }); + // Build buttons const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setLabel('◄') .setStyle(ButtonStyle.Primary) .setCustomId('quotes_leaderboard_left') - ) - .addComponents( + .setDisabled(page === 1), new ButtonBuilder() .setLabel('X') .setStyle(ButtonStyle.Danger) - .setCustomId('abort') - ) - .addComponents( + .setCustomId('abort'), new ButtonBuilder() .setLabel('►') .setStyle(ButtonStyle.Primary) .setCustomId('quotes_leaderboard_right') - ) - await interaction.editReply({ - embeds: [embed], - components: [row] - }) + .setDisabled(page === totalPages) + ); + + await interaction.editReply({ embeds: [embed], components: [row] }); } module.exports = { @@ -392,4 +408,6 @@ module.exports = { break; } } -} \ No newline at end of file +}, + +module.exports.quotesLeaderboard = quotesLeaderboard \ No newline at end of file