From 059072e67e2cf95ddd81b06db3da167ecb650374 Mon Sep 17 00:00:00 2001 From: dragonfire535 Date: Wed, 15 Mar 2017 16:10:30 -0400 Subject: [PATCH] Moment for Uptime and Memory Usage --- commands/botinfo/info.js | 22 +++++++--------------- commands/botinfo/uptime.js | 14 +++----------- package.json | 2 ++ 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/commands/botinfo/info.js b/commands/botinfo/info.js index 65a555a9..f8bec668 100644 --- a/commands/botinfo/info.js +++ b/commands/botinfo/info.js @@ -1,6 +1,8 @@ const commando = require('discord.js-commando'); const Discord = require('discord.js'); const config = require("../../config.json"); +const moment = require('moment'); +require('moment-duration-format'); class InfoCommand extends commando.Command { constructor(Client){ @@ -20,16 +22,6 @@ class InfoCommand extends commando.Command { if(!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return; } console.log("[Command] " + message.content); - const toHHMMSS = seconds => { - let secNum = parseInt(seconds, 10); - let hours = Math.floor(secNum / 3600); - let minutes = Math.floor((secNum - (hours * 3600)) / 60); - seconds = secNum - (hours * 3600) - (minutes * 60); - if (hours < 10) hours = "0" + hours; - if (minutes < 10) minutes = "0" + minutes; - if (seconds < 10) seconds = "0" + seconds; - return hours + ":" + minutes + ":" + seconds; - }; let guilds = this.client.guilds.size; let users = this.client.users.size; this.client.shard.fetchClientValues('guilds.size').then(results => { @@ -52,15 +44,15 @@ class InfoCommand extends commando.Command { .addField('Owner', "dragonfire535#8081", true) .addField('Uptime', - toHHMMSS(process.uptime()), true) + moment.duration(this.client.uptime).format('d[ days], h[ hours], m[ minutes, and ]s[ seconds]'), true) .addField('Source Code', "[View Here](https://github.com/dragonfire535/xiaobot)", true) - .addField('Node Version', - "7.7.2", true) - .addField('Lib', + .addField('Memory Usage', + `${Math.round(process.memoryUsage().heapUsed / 1024 / 1024)}MB`, true) + .addField('Library', "[discord.js](https://discord.js.org/#/)", true) .addField('Modules', - "[Commando](https://github.com/Gawdl3y/discord.js-commando), [cleverbot-node](https://github.com/fojas/cleverbot-node), [pirate-speak](https://github.com/mikewesthad/pirate-speak), [JIMP](https://github.com/oliver-moran/jimp), [google-translate-api](https://github.com/matheuss/google-translate-api), [urban](https://github.com/mvrilo/urban), [zalgoize](https://github.com/clux/zalgolize), [hepburn](https://github.com/lovell/hepburn), [yahoo-weather](https://github.com/mamal72/node-yahoo-weather), [imdb-api](https://github.com/worr/node-imdb-api), [request-promise](https://github.com/request/request-promise), [mathjs](http://mathjs.org/), [string-to-binary](https://www.npmjs.com/package/string-to-binary), [google](https://github.com/jprichardson/node-google), [roman-numeral-converter-mmxvi](https://github.com/Cein-Markey/roman-numeral-conversion-library), [cowsay](https://github.com/piuccio/cowsay)") + "[Commando](https://github.com/Gawdl3y/discord.js-commando), [cleverbot-node](https://github.com/fojas/cleverbot-node), [pirate-speak](https://github.com/mikewesthad/pirate-speak), [JIMP](https://github.com/oliver-moran/jimp), [google-translate-api](https://github.com/matheuss/google-translate-api), [urban](https://github.com/mvrilo/urban), [zalgoize](https://github.com/clux/zalgolize), [hepburn](https://github.com/lovell/hepburn), [yahoo-weather](https://github.com/mamal72/node-yahoo-weather), [imdb-api](https://github.com/worr/node-imdb-api), [request-promise](https://github.com/request/request-promise), [mathjs](http://mathjs.org/), [string-to-binary](https://www.npmjs.com/package/string-to-binary), [google](https://github.com/jprichardson/node-google), [roman-numeral-converter-mmxvi](https://github.com/Cein-Markey/roman-numeral-conversion-library), [cowsay](https://github.com/piuccio/cowsay), [moment-duration-format](https://github.com/jsmreese/moment-duration-format)") .addField('Other Credit', "[Cleverbot API](https://www.cleverbot.com/api/), [Wattpad API](https://developer.wattpad.com/docs/api), [Wordnik API](http://developer.wordnik.com/docs.html), [osu! API](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link/), [Yugioh Prices API](http://docs.yugiohprices.apiary.io/#), [YouTube Data API](https://developers.google.com/youtube/v3/), [Yoda Speak API](https://market.mashape.com/ismaelc/yoda-speak), [Discord Bots API](https://bots.discord.pw/api), [Today in History API](http://history.muffinlabs.com/), [Heroku](https://www.heroku.com/)") .addField('My Server', diff --git a/commands/botinfo/uptime.js b/commands/botinfo/uptime.js index 0a10de5f..ccc05431 100644 --- a/commands/botinfo/uptime.js +++ b/commands/botinfo/uptime.js @@ -1,4 +1,6 @@ const commando = require('discord.js-commando'); +const moment = require('moment'); +require('moment-duration-format'); class UptimeCommand extends commando.Command { constructor(Client){ @@ -17,18 +19,8 @@ class UptimeCommand extends commando.Command { if(!message.channel.permissionsFor(this.client.user).hasPermission('READ_MESSAGES')) return; } console.log("[Command] " + message.content); - const toHHMMSS = seconds => { - let secNum = parseInt(seconds, 10); - let hours = Math.floor(secNum / 3600); - let minutes = Math.floor((secNum - (hours * 3600)) / 60); - seconds = secNum - (hours * 3600) - (minutes * 60); - if (hours < 10) hours = "0" + hours; - if (minutes < 10) minutes = "0" + minutes; - if (seconds < 10) seconds = "0" + seconds; - return hours + " Hours, " + minutes + " Minutes, and " + seconds + " Seconds"; - }; let guilds = this.client.guilds.array().length; - message.channel.sendMessage("I've been active on this shard for: **" + toHHMMSS(process.uptime()) + "** in a total of " + guilds + " Servers."); + message.channel.sendMessage("I've been active on this shard for: **" + moment.duration(this.client.uptime).format('d[ days], h[ hours], m[ minutes, and ]s[ seconds]') + "** in a total of " + guilds + " Servers."); } } diff --git a/package.json b/package.json index 6bd6a52d..812f1304 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "imdb-api": "^2.2.1", "jimp": "^0.2.27", "mathjs": "^3.10.0", + "moment": "^2.17.1", + "moment-duration-format": "^1.3.0", "pirate-speak": "^1.0.1", "request-promise": "^4.1.1", "roman-numeral-converter-mmxvi": "^1.0.5",