Added Rich Embeds

- rich embed for `queue`
- rich embed for `uptime`
pull/28/head^2
Trivernis 6 years ago
parent 5d90ff6830
commit e27b46ac6a

@ -169,7 +169,14 @@ function registerCommands() {
// returns the time the bot is running // returns the time the bot is running
cmd.createGlobalCommand(prefix + 'uptime', () => { 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 uptime of the bot', 'owner');
// returns the numbe of guilds, the bot has joined // 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'); }, [], '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() { function rotatePresence() {
let pr = presences.shift(); let pr = presences.shift();
presences.push(pr); presences.push(pr);

@ -263,14 +263,15 @@ exports.GuildHandler = class {
// playlist command // playlist command
this.servant.createCommand(servercmd.music.playlist, () => { this.servant.createCommand(servercmd.music.playlist, () => {
let songs = this.dj.playlist; logger.debug(`found ${this.dj.queue.length} songs`);
logger.debug(`found ${songs.length} songs`); let describtion = '';
let songlist = `**${songs.length} Songs in playlist**\n`; for (let i = 0; i < Math.min(this.dj.queue.length, 9); i++) {
for (let i = 0; i < songs.length; i++) { let entry = this.dj.queue[i];
if (i > 10) break; describtion += `[${entry.title}](${entry.url})\n`;
songlist += songs[i] + '\n';
} }
return songlist; return new Discord.RichEmbed()
.setTitle(`${this.dj.queue.length} songs in queue`)
.setDescription(describtion);
}); });
// np command // np command

@ -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 the song saved in the private variable 'current'
* @returns {null|*} * @returns {null|*}

@ -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 */ /* FS */
exports.dirExistence = function (path, callback) { exports.dirExistence = function (path, callback) {

@ -15,6 +15,15 @@ mockobjects.mockLogger = {
describe('lib/utils', function() { describe('lib/utils', function() {
const utils = require('../lib/utils.js'); 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() { describe('#getExtension', function() {
it('returns the correct extension for a filename', function(done) { it('returns the correct extension for a filename', function(done) {
assert(utils.getExtension('test.txt') === '.txt'); assert(utils.getExtension('test.txt') === '.txt');
@ -295,7 +304,7 @@ describe('lib/music', function() {
'url': 'http://www.youtube.com/watch?v=ABCDEFGHIJK'}]; 'url': 'http://www.youtube.com/watch?v=ABCDEFGHIJK'}];
assert(dj.playlist.length > 0); assert(dj.playlist.length > 0);
done(); done();
}); }).catch(() => done());
}); });
it('clears the queue', function(done) { it('clears the queue', function(done) {
@ -309,7 +318,7 @@ describe('lib/music', function() {
dj.clear(); dj.clear();
assert(dj.queue.length === 0); assert(dj.queue.length === 0);
done(); done();
}); }).catch(() => done());
}) })
}); });
}); });

Loading…
Cancel
Save