From 23ac36c8192197501be92fae375770e9c5f6d1ed Mon Sep 17 00:00:00 2001 From: ry Date: Mon, 20 Jan 2020 00:35:54 +0100 Subject: [PATCH] added stats command --- DiscordEvents/message.js | 4 +-- DiscordModules/General/stats.js | 63 +++++++++++++++++++++++++++++++++ run.bat | 5 --- src/client/Client.js | 13 ++++--- utils/src/shortlinks.js | 1 + 5 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 DiscordModules/General/stats.js delete mode 100644 run.bat diff --git a/DiscordEvents/message.js b/DiscordEvents/message.js index 26ca62c..f3128b0 100755 --- a/DiscordEvents/message.js +++ b/DiscordEvents/message.js @@ -111,10 +111,10 @@ module.exports = { setTimeout(() => timestamps.delete(msg.author.id), cooldownAmount); cmd.command(ctx).then(async () => { - ctx.client.channels.find(c => c.id === vars.logs.usage).send(`${ctx.utils.format.bold(ctx.author.tag)} (${ctx.utils.format.code(ctx.author.id)}) used ${ctx.utils.format.code(cmd.name)} in ${ctx.utils.format.bold(ctx.guild.name)} (${ctx.utils.format.code(ctx.guild.id)}) `).catch(e => console.log(e)) + if (!ctx.config.type.beta) ctx.client.channels.find(c => c.id === vars.logs.usage).send(`${ctx.utils.format.bold(ctx.author.tag)} (${ctx.utils.format.code(ctx.author.id)}) used ${ctx.utils.format.code(cmd.name)} in ${ctx.utils.format.bold(ctx.guild.name)} (${ctx.utils.format.code(ctx.guild.id)}) `).catch(e => console.log(e)) await ctx.db.backend.add(`usage.${cmd.name}`, 1) }).catch((err) => { - if (!cmd.name.includes('e926') || !cmd.name.includes('e621')) { + if (!cmd.name === 'e926' || !cmd.name === 'e621') { trello .addCard( cmd.name + ' | ' + err.message, diff --git a/DiscordModules/General/stats.js b/DiscordModules/General/stats.js new file mode 100644 index 0000000..fef7e65 --- /dev/null +++ b/DiscordModules/General/stats.js @@ -0,0 +1,63 @@ +const Command = require('../../src/structures/Command'); +const { + MessageEmbed: Embed +} = require('discord.js') +module.exports = class Statistics extends Command { + constructor() { + super({ + name: 'statistics', + description: 'Get in-depth bot Stats', + aliases: ['stats'], + module: 'General', + cooldown: 5, + guildOnly: false, + developerOnly: false, + nsfw: false + }); + } + + + async command(ctx) { + let StatisticsEmbed = new Embed().setTitle(`${ctx.vars.name} v${ctx.vars.version} Statistics`).setColor(ctx.vars.color) + var SortUsage = []; + var SortSL = []; + var SortSF = []; + let usage = ctx.db.backend.get('usage') + let Shortlink = ctx.db.backend.get('Shortlink') + let SourceFynnder = ctx.db.backend.get('SourceFynnder') + // change data value to the one you showed in pic + for (var type in usage) { + SortUsage.push([type, usage[type]]); + } + for (var type in Shortlink) { + SortSL.push([type, Shortlink[type]]); + } + for (var type in SourceFynnder) { + SortSF.push([type, SourceFynnder[type]]); + } + + let usages = SortUsage.sort((a, b) => b[1] - a[1]) + let SLs = SortSL.sort((a, b) => b[1] - a[1]) + let SFs = SortSF.sort((a, b) => b[1] - a[1]) + + let UsageStats = '' + let SLStats = '' + let SFStats = '' + usages.forEach(use => { + UsageStats += `${ctx.utils.format.bold(use[0])} - \`${use[1]}\`\n` + }) + SLs.forEach(SL => { + SLStats += `${ctx.utils.format.bold(SL[0])} - \`${SL[1]}\`\n` + }) + SFs.forEach(SF => { + SFStats += `${ctx.utils.format.bold(SF[0]).replace(/found/g,'Found w/')} - \`${SF[1]}\`\n` + }) + StatisticsEmbed.addField("Uptime", `${ctx.utils.format.uptime(process.uptime())}`, true) + .addField("Servers", ctx.client.guilds.size, true) + .addField("Users", ctx.client.users.size, true) + .addField('Command Usage', UsageStats, true) + .addField('Shortlink Usage', SLStats, true) + .addField('SourceFynnder Usage', SFStats.replace(/Found w\//, 'Total'), true) + ctx.send(StatisticsEmbed) + } +} \ No newline at end of file diff --git a/run.bat b/run.bat deleted file mode 100644 index ea7e914..0000000 --- a/run.bat +++ /dev/null @@ -1,5 +0,0 @@ -@echo off -title Discord: Thaldrin v3 -:start -node index.js -goto start \ No newline at end of file diff --git a/src/client/Client.js b/src/client/Client.js index fa3b60a..c7e49a3 100755 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -1,12 +1,17 @@ -const { Client, Collection } = require('discord.js'); -const { readdirSync: read } = require('fs'); +const { + Client, + Collection +} = require('discord.js'); +const { + readdirSync: read +} = require('fs'); const server = require('../../Dashboard/server'); module.exports = class Thaldrin extends Client { constructor(config, shards) { super({ disableEveryone: true, - disabledEvents: [ 'TYPING_START' ], + disabledEvents: ['TYPING_START'], shardCount: shards, totalShardCount: shards }); @@ -53,4 +58,4 @@ module.exports = class Thaldrin extends Client { }); }); } -}; +}; \ No newline at end of file diff --git a/utils/src/shortlinks.js b/utils/src/shortlinks.js index c052f07..c50321a 100755 --- a/utils/src/shortlinks.js +++ b/utils/src/shortlinks.js @@ -72,6 +72,7 @@ module.exports = async function Shortlink(enabled, msg) { url = ShortLinks[x].replace('$link$', url); links.push(`<${url}>`); await backend.add(`Shortlink.${ShortLinkDirs[x]}`, 1); + await backend.add(`Shortlink.total`, 1); } }