Skip to content

Commit

Permalink
Stats cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabwhy committed Mar 2, 2021
1 parent f266b76 commit 8dce377
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require("dotenv").config() // Get .env

cmdUses = 0;

// Init discord.js
const Discord = require('discord.js');
const client = new Discord.Client();
Expand Down Expand Up @@ -40,6 +42,8 @@ client.on('message', async msg => {
let args = parsed[2]
let startTime = new Date().getTime()

cmdUses++;

if(cmd.type == 'script') { // If command is set as script type
let { cmdFunc } = require('./'+cmd.path) // Gets function of command
setImmediate(async () => {
Expand Down
5 changes: 5 additions & 0 deletions commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ dog:
path: commands/misc/dog.js
category: Misc
description: "Gets a random dog image"
stats:
type: script
path: commands/misc/stats.js
category: Misc
description: "Shows bot stats"

pixelate:
type: image
Expand Down
41 changes: 41 additions & 0 deletions commands/misc/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require("dotenv").config();
const { formatDuration } = require("../../modules/utils")

async function cmdFunc(msg, args, startTime) {
// Send the stats embed
msg.channel.send({
"embed": {
"title": `Stats`,
"color": Number(process.env.EMBED_COLOUR),
"footer": {
"text": `FrogeBot v${process.env.npm_package_version}`
},
"fields": [
{
"name": "Uptime",
"value": `${formatDuration(msg.client.uptime)}`
},
{
"name": "Discord API ping",
"value": `${msg.client.ws.ping}ms`
},
{
"name": "Command uses (resets on restart)",
"value": `${cmdUses}`
},
{
"name": "GitHub",
"value": "[View source code](https://github.com/FrogeBot/frogeBot)"
},
],
"author": {
"name": process.env.BOT_NAME,
"icon_url": msg.client.user.displayAvatarURL()
}
}
})
}

module.exports = {
cmdFunc,
};

0 comments on commit 8dce377

Please sign in to comment.