|
|
@ -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];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|