diff --git a/commands/Utilities/TopChart.js b/commands/Utilities/TopChart.js new file mode 100644 index 00000000..298edec1 --- /dev/null +++ b/commands/Utilities/TopChart.js @@ -0,0 +1,50 @@ +const { EmbedBuilder } = require("discord.js"); +const { Database } = require("st.db"); +const ytsr = require("@distube/ytsr"); + +const SStats = new Database("./settings/models/chart.json", { databaseInObject: true }); + +module.exports = { + name: ["topchart"], + description: "Display top song most recent playable.", + category: "Utilities", + run: async (client, interaction) => { + await interaction.deferReply({ ephemeral: false }); + + const all = SStats.all().slice(0, 10); + + all.sort((a, b) => { + return b.data - a.data; + }); + + var index = 0; + + for (let i = 0; i < all.length; i++) { + const total = all[i].data; + index = (index + total) + } + + const TopChart = []; + for (let i = 0; i < all.length; i++) { + const format = `https://youtu.be/${all[i].ID}`; + const search = await ytsr(format); + const track = search.items[0]; + + TopChart.push( + `**${i + 1}.** [${track.name}](${track.url}) | **Playable:** \`${all[i].data}\` + `) + } + + const str = TopChart.join(''); + + const embed = new EmbedBuilder() + .setColor(client.color) + .setAuthor({ name: `Top Charts`, iconURL: interaction.guild.iconURL({ dynamic: true })}) + .setThumbnail(client.user.displayAvatarURL({ dynamic: true, size: 2048 })) + .setDescription(`${str == '' ? ' No Playable' : '\n' + str}`) + .setFooter({ text: `Total Song • ${SStats.all().length} | Total Playable • ${index}` }) + + + return interaction.editReply({ embeds: [embed] }) + } +} \ No newline at end of file diff --git a/commands/Utilities/UsableStats.js b/commands/Utilities/UsableStats.js new file mode 100644 index 00000000..b8cc2ae8 --- /dev/null +++ b/commands/Utilities/UsableStats.js @@ -0,0 +1,48 @@ +const { EmbedBuilder } = require("discord.js"); +const { Database } = require("st.db"); + +const BStats = new Database("./settings/models/stats.json", { databaseInObject: true }); + +module.exports = { + name: ["usablestats"], + description: "Display all commands stats usable.", + category: "Utilities", + run: async (client, interaction) => { + await interaction.deferReply({ ephemeral: false }); + + const all = BStats.all().slice(0, 10); + + all.sort((a, b) => { + return b.data - a.data; + }); + + var index = 0; + + for (let i = 0; i < all.length; i++) { + const total = all[i].data; + index = (index + total) + } + + const TopUsable = []; + for (let i = 0; i < all.length; i++) { + const name = all[i].ID.UppertoLowerCase(); + const usable = all[i].data; + + TopUsable.push( + `**${i + 1}.** ${name} | **Usable:** \`${usable}\` + `) + } + + const str = TopUsable.join(''); + + const embed = new EmbedBuilder() + .setColor(client.color) + .setAuthor({ name: `Usable Commands!`, iconURL: interaction.guild.iconURL({ dynamic: true })}) + .setThumbnail(client.user.displayAvatarURL({ dynamic: true, size: 2048 })) + .setDescription(`${str == '' ? ' No Usable' : '\n' + str}`) + .setFooter({ text: `Total Command • ${BStats.all().length} | Total Usable • ${index}` }) + + + return interaction.editReply({ embeds: [embed] }) + } +} \ No newline at end of file diff --git a/events/distube/playSong.js b/events/distube/playSong.js index 77d03c66..261d2f37 100644 --- a/events/distube/playSong.js +++ b/events/distube/playSong.js @@ -6,6 +6,7 @@ const GSetup = new Database("./settings/models/setup.json", { databaseInObject: module.exports = async (client, queue, track) => { await client.UpdateQueueMsg(queue); + await client.addChart(track.id); const db = await GSetup.get(queue.textChannel.guild.id); if (db.setup_enable === true) return; diff --git a/events/guild/interactionCreate.js b/events/guild/interactionCreate.js index e8f382a8..ae652bbf 100644 --- a/events/guild/interactionCreate.js +++ b/events/guild/interactionCreate.js @@ -52,6 +52,7 @@ module.exports = async(client, interaction) => { if (!command) return; if (command) { try { + client.addCount(command.name.at(-1)); command.run(client, interaction); } catch (error) { console.log(error); diff --git a/handlers/loadDatabase.js b/handlers/loadDatabase.js index 30af4bf1..0acdd11a 100644 --- a/handlers/loadDatabase.js +++ b/handlers/loadDatabase.js @@ -60,13 +60,23 @@ module.exports = async (client) => { client.createPlay = async function (interaction, message) { const db = new Database("./settings/models/message.json", { databaseInObject: true }); - await db.set(interaction.guild.id, { channel_id: interaction.channel.id, message_id: message }); }; + client.addCount = async function (cmdname) { + const db = new Database("./settings/models/stats.json", { databaseInObject: true }); + await db.add({ key: cmdname, value: 1 }); + } + + client.addChart = async function (id) { + const db = new Database("./settings/models/chart.json", { databaseInObject: true }); + await db.add({ key: id, value: 1 }); + } + + client.interval = null; client.clearInterval = async function (interval) { diff --git a/settings/models/chart.json b/settings/models/chart.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/settings/models/chart.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/settings/models/stats.json b/settings/models/stats.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/settings/models/stats.json @@ -0,0 +1 @@ +{} \ No newline at end of file