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

@ -24,13 +24,26 @@ exports.GuildHandler = class {
this.mention = false;
this.prefix = prefix || config.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/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();
// 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(){
@ -67,6 +80,7 @@ exports.GuildHandler = class {
* @param msg
*/
handleMessage(msg) {
if (this.ready) {
if (this.db) {
this.db.run(
'INSERT INTO messages (author, creation_timestamp, author_name, content) values (?, ?, ?, ?)',
@ -84,6 +98,9 @@ exports.GuildHandler = class {
} else {
msg.channel.send(answer);
}
} else {
this.msgsQueue.push(msg);
}
}
/**
@ -279,18 +296,22 @@ exports.GuildHandler = class {
// saved command - prints out saved playlists
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) => {
if (err)
logger.error(err.message);
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);
else
msg.channel.send(response);
} else {
msg.channel.send('', {embed: {
"title": "Saved Songs and Playlists",
"description": response,
"fields": []
}});
}
});
});
}
@ -302,7 +323,8 @@ exports.GuildHandler = class {
* @returns {GuildHandler}
*/
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];
};

Loading…
Cancel
Save