Fixes and Features

- fixed guilds first command problem
- switched from markdown to rich embed for displaying saved songs/playlists
pull/18/head
Trivernis 6 years ago
parent 84b27b9f8a
commit 443570f8d6

@ -14,7 +14,7 @@ let logger = require('winston'),
/** /**
* @type {Servant} * @type {Servant}
*/ */
module.exports.Servant = class { exports.Servant = class {
constructor(prefix) { constructor(prefix) {
this.commands = {}; this.commands = {};
this.prefix = prefix; this.prefix = prefix;
@ -61,7 +61,7 @@ module.exports.Servant = class {
*/ */
createCommand(template, call) { createCommand(template, call) {
if (!template.name) { if (!template.name) {
logger.debug(`Name of command template is null or undef. Failed creating command.`) logger.debug(`Name of command template is null or undef. Failed creating command.`);
return; return;
} }
this.commands[this.prefix + template.name] = { this.commands[this.prefix + template.name] = {
@ -117,7 +117,7 @@ module.exports.Servant = class {
* Getting the logger * Getting the logger
* @param {Object} newLogger * @param {Object} newLogger
*/ */
module.exports.setLogger = function (newLogger) { exports.setLogger = function (newLogger) {
logger = newLogger; logger = newLogger;
}; };
@ -129,7 +129,7 @@ module.exports.setLogger = function (newLogger) {
* @param description * @param description
* @param role * @param role
*/ */
module.exports.createGlobalCommand = function (command, call, args, description, role) { exports.createGlobalCommand = function (command, call, args, description, role) {
globCommands[command] = { globCommands[command] = {
'args': args || [], 'args': args || [],
'description': description, 'description': description,
@ -145,14 +145,14 @@ module.exports.createGlobalCommand = function (command, call, args, description,
* @param msg * @param msg
* @returns {boolean|*} * @returns {boolean|*}
*/ */
module.exports.parseMessage = function (msg) { exports.parseMessage = function (msg) {
return parseGlobalCommand(msg); return parseGlobalCommand(msg);
}; };
/** /**
* Initializes the module by creating a help command * Initializes the module by creating a help command
*/ */
module.exports.init = function (prefix) { exports.init = function (prefix) {
logger.verbose("Created help command"); logger.verbose("Created help command");
this.createGlobalCommand(((prefix || config.prefix) + 'help'), (msg) => { this.createGlobalCommand(((prefix || config.prefix) + 'help'), (msg) => {
let helpstr = "```markdown\n"; let helpstr = "```markdown\n";

@ -24,13 +24,26 @@ exports.GuildHandler = class {
this.mention = false; this.mention = false;
this.prefix = prefix || config.prefix; this.prefix = prefix || config.prefix;
this.servant = new cmd.Servant(this.prefix); this.servant = new cmd.Servant(this.prefix);
this.ready = false;
this.msgsQueue = [];
// checking if the data direcotry exists and if the gdb directory exists and creates them if they don't
utils.dirExistence('./data', () => { utils.dirExistence('./data', () => {
utils.dirExistence('./data/gdb', () => { utils.dirExistence('./data/gdb', () => {
this.db = new sqlite3.Database(`./data/gdb/${guild}.db`); this.db = new sqlite3.Database(`./data/gdb/${guild}.db`, (err) => {
if (err)
logger.error(err.message);
logger.debug(`Connected to the database for ${guild}`);
this.createTables(); this.createTables();
// register commands
this.registerMusicCommands();
this.ready = true;
// handle all messages that have been received while not being ready
for (let i = 0; i < this.msgsQueue.length; i++) {
this.handleMessage(this.msgsQueue.shift());
}
});
}) })
}); });
this.registerMusicCommands();
} }
destroy(){ destroy(){
@ -67,6 +80,7 @@ exports.GuildHandler = class {
* @param msg * @param msg
*/ */
handleMessage(msg) { handleMessage(msg) {
if (this.ready) {
if (this.db) { if (this.db) {
this.db.run( this.db.run(
'INSERT INTO messages (author, creation_timestamp, author_name, content) values (?, ?, ?, ?)', 'INSERT INTO messages (author, creation_timestamp, author_name, content) values (?, ?, ?, ?)',
@ -84,6 +98,9 @@ exports.GuildHandler = class {
} else { } else {
msg.channel.send(answer); msg.channel.send(answer);
} }
} else {
this.msgsQueue.push(msg);
}
} }
/** /**
@ -279,18 +296,22 @@ exports.GuildHandler = class {
// saved command - prints out saved playlists // saved command - prints out saved playlists
this.servant.createCommand(servercmd.music.saved, (msg) => { this.servant.createCommand(servercmd.music.saved, (msg) => {
let response = '```markdown\nSaved Playlists:\n==\n'; let response = '';
this.db.all('SELECT name, url FROM playlists', (err, rows) => { this.db.all('SELECT name, url FROM playlists', (err, rows) => {
if (err) if (err)
logger.error(err.message); logger.error(err.message);
for (let row of rows) { for (let row of rows) {
response += `${row.name.padEnd(10, ' ')}: ${row.url} \n\n`; response += `[${row.name}](${row.url})\n`;
} }
response += '```'; if (rows.length === 0) {
if (rows.length === 0)
msg.channel.send(servercmd.music.saved.response.no_saved); msg.channel.send(servercmd.music.saved.response.no_saved);
else } else {
msg.channel.send(response); msg.channel.send('', {embed: {
"title": "Saved Songs and Playlists",
"description": response,
"fields": []
}});
}
}); });
}); });
} }
@ -302,7 +323,8 @@ exports.GuildHandler = class {
* @returns {GuildHandler} * @returns {GuildHandler}
*/ */
exports.getHandler = function (guild, prefix) { exports.getHandler = function (guild, prefix) {
if (!handlers[guild.id]) handlers[guild.id] = new this.GuildHandler(guild, prefix); if (!handlers[guild.id])
handlers[guild.id] = new this.GuildHandler(guild, prefix);
return handlers[guild.id]; return handlers[guild.id];
}; };

Loading…
Cancel
Save