Updated more Thumbnails to reliable sources,, fixed quotes leaderboard
This commit is contained in:
@@ -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' });
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
module.exports.quotesLeaderboard = quotesLeaderboard
|
||||
Reference in New Issue
Block a user