From e27b46ac6abcfd3f5888a8a09ee4b34e9e10e3c9 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Sat, 26 Jan 2019 18:46:30 +0100 Subject: [PATCH] Added Rich Embeds - rich embed for `queue` - rich embed for `uptime` --- bot.js | 12 +++++++++++- lib/guilding.js | 15 ++++++++------- lib/music.js | 12 ------------ lib/utils.js | 15 +++++++++++++++ test/test.js | 13 +++++++++++-- 5 files changed, 45 insertions(+), 22 deletions(-) diff --git a/bot.js b/bot.js index 761ad8f..e5ab685 100644 --- a/bot.js +++ b/bot.js @@ -169,7 +169,14 @@ function registerCommands() { // returns the time the bot is running cmd.createGlobalCommand(prefix + 'uptime', () => { - return `Uptime: \`${client.uptime / 1000} s\`` + let uptime = utils.getSplitDuration(client.uptime); + return new Discord.RichEmbed().setDescription(` + **${uptime.days}** days + **${uptime.hours}** hours + **${uptime.minutes}** minutes + **${uptime.seconds}** seconds + **${uptime.milliseconds}** milliseconds + `).setTitle('Uptime'); }, [], 'Returns the uptime of the bot', 'owner'); // returns the numbe of guilds, the bot has joined @@ -178,6 +185,9 @@ function registerCommands() { }, [], 'Returns the number of guilds the bot has joined', 'owner'); } +/** + * changes the presence of the bot by using one stored in the presences array + */ function rotatePresence() { let pr = presences.shift(); presences.push(pr); diff --git a/lib/guilding.js b/lib/guilding.js index 76568b2..9ec2d28 100644 --- a/lib/guilding.js +++ b/lib/guilding.js @@ -263,14 +263,15 @@ exports.GuildHandler = class { // playlist command this.servant.createCommand(servercmd.music.playlist, () => { - let songs = this.dj.playlist; - logger.debug(`found ${songs.length} songs`); - let songlist = `**${songs.length} Songs in playlist**\n`; - for (let i = 0; i < songs.length; i++) { - if (i > 10) break; - songlist += songs[i] + '\n'; + logger.debug(`found ${this.dj.queue.length} songs`); + let describtion = ''; + for (let i = 0; i < Math.min(this.dj.queue.length, 9); i++) { + let entry = this.dj.queue[i]; + describtion += `[${entry.title}](${entry.url})\n`; } - return songlist; + return new Discord.RichEmbed() + .setTitle(`${this.dj.queue.length} songs in queue`) + .setDescription(describtion); }); // np command diff --git a/lib/music.js b/lib/music.js index 9d76d24..0039739 100644 --- a/lib/music.js +++ b/lib/music.js @@ -276,18 +276,6 @@ exports.DJ = class { } } - /** - * Returns the title for each song saved in the queue - * @returns {Array} - */ - get playlist() { - let songs = []; - this.queue.forEach((entry) => { - songs.push(entry.title); - }); - return songs; - } - /** * Returns the song saved in the private variable 'current' * @returns {null|*} diff --git a/lib/utils.js b/lib/utils.js index a691ed3..6c92e3c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -79,6 +79,21 @@ exports.Cleanup = function Cleanup(callback) { }); }; +exports.getSplitDuration = function (duration) { + let dur = duration; + let retObj = {}; + retObj.milliseconds = dur % 1000; + dur = Math.round(dur / 1000); + retObj.seconds = dur % 60; + dur = Math.round(dur / 60); + retObj.minutes = dur % 60; + dur = Math.round(dur / 60); + retObj.hours = dur % 24; + dur = Math.round(dur / 24); + retObj.days = dur; + return retObj; +}; + /* FS */ exports.dirExistence = function (path, callback) { diff --git a/test/test.js b/test/test.js index fd080d1..924568a 100644 --- a/test/test.js +++ b/test/test.js @@ -15,6 +15,15 @@ mockobjects.mockLogger = { describe('lib/utils', function() { const utils = require('../lib/utils.js'); + describe('#getSplitDuration', function() { + it('returns an object from milliseconds', function() { + assert(utils.getSplitDuration(1000).seconds === 1); + assert(utils.getSplitDuration(360000).minutes === 6); + assert(utils.getSplitDuration(3600000).hours === 1); + assert(utils.getSplitDuration(100).milliseconds === 100); + }); + }); + describe('#getExtension', function() { it('returns the correct extension for a filename', function(done) { assert(utils.getExtension('test.txt') === '.txt'); @@ -295,7 +304,7 @@ describe('lib/music', function() { 'url': 'http://www.youtube.com/watch?v=ABCDEFGHIJK'}]; assert(dj.playlist.length > 0); done(); - }); + }).catch(() => done()); }); it('clears the queue', function(done) { @@ -309,7 +318,7 @@ describe('lib/music', function() { dj.clear(); assert(dj.queue.length === 0); done(); - }); + }).catch(() => done()); }) }); });