|
@@ -45,11 +45,8 @@ async function cmd_eval(lang, msg, args, line, wiki) {
|
|
* @param {String[]} [sqlargs] - The command arguments.
|
|
* @param {String[]} [sqlargs] - The command arguments.
|
|
*/
|
|
*/
|
|
function database(sql, sqlargs = []) {
|
|
function database(sql, sqlargs = []) {
|
|
- return new Promise( function (resolve, reject) {
|
|
|
|
- db.all( sql, sqlargs, function(error, rows) {
|
|
|
|
- if (error) reject.call(this, error);
|
|
|
|
- else resolve.call(this, rows);
|
|
|
|
- } );
|
|
|
|
|
|
+ return db.query( sql, sqlargs ).then( ({rows}) => {
|
|
|
|
+ return rows;
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
|
|
|
|
@@ -109,10 +106,10 @@ function checkWiki(wiki) {
|
|
result.activity.push(`${rc.length} edits in${text}`);
|
|
result.activity.push(`${rc.length} edits in${text}`);
|
|
}
|
|
}
|
|
return Promise.all([
|
|
return Promise.all([
|
|
- database('SELECT guild, lang, display, rcid, postid FROM rcgcdw WHERE wiki = ?', [result.wiki]).then( rows => {
|
|
|
|
|
|
+ db.query( 'SELECT guild, lang, display, rcid, postid FROM rcgcdw WHERE wiki = $1', [result.wiki] ).then( ({rows}) => {
|
|
result.rcgcdb = rows;
|
|
result.rcgcdb = rows;
|
|
- }, error => {
|
|
|
|
- result.rcgcdb = error.toString();
|
|
|
|
|
|
+ }, dberror => {
|
|
|
|
+ result.rcgcdb = dberror.toString();
|
|
} ),
|
|
} ),
|
|
( wiki.isFandom() ? got.get( wiki + 'wikia.php?controller=DiscussionPost&method=getPosts&includeCounters=false&sortDirection=descending&sortKey=creation_date&limit=100&format=json&cache=' + Date.now(), {
|
|
( wiki.isFandom() ? got.get( wiki + 'wikia.php?controller=DiscussionPost&method=getPosts&includeCounters=false&sortDirection=descending&sortKey=creation_date&limit=100&format=json&cache=' + Date.now(), {
|
|
headers: {
|
|
headers: {
|
|
@@ -169,91 +166,96 @@ function checkWiki(wiki) {
|
|
* @param {Discord.Message} msg - The Discord message.
|
|
* @param {Discord.Message} msg - The Discord message.
|
|
*/
|
|
*/
|
|
function removePatreons(guild, msg) {
|
|
function removePatreons(guild, msg) {
|
|
- try {
|
|
|
|
- if ( !( typeof guild === 'string' || msg instanceof Discord.Message ) ) {
|
|
|
|
- return 'removePatreons(guild, msg) – No guild or message provided!';
|
|
|
|
- }
|
|
|
|
- db.get( 'SELECT lang, inline FROM discord WHERE guild = ? AND channel IS NULL', [guild], (dberror, row) => {
|
|
|
|
- try {
|
|
|
|
- if ( dberror ) {
|
|
|
|
- console.log( '- Error while getting the guild: ' + dberror );
|
|
|
|
- msg.replyMsg( 'I got an error while searching for the guild!', {}, true );
|
|
|
|
- return dberror;
|
|
|
|
|
|
+ if ( !( typeof guild === 'string' || msg instanceof Discord.Message ) ) {
|
|
|
|
+ return 'removePatreons(guild, msg) – No guild or message provided!';
|
|
|
|
+ }
|
|
|
|
+ var messages = [];
|
|
|
|
+ db.connect().then( client => {
|
|
|
|
+ client.query( 'SELECT lang, inline FROM discord WHERE guild = $1 AND channel IS NULL', [guild] ).then( ({rows:[row]}) => {
|
|
|
|
+ if ( !row ) {
|
|
|
|
+ messages.push('The guild doesn\'t exist!');
|
|
|
|
+ return Promise.reject();
|
|
|
|
+ }
|
|
|
|
+ return client.query( 'UPDATE discord SET lang = $1, inline = $2, prefix = $3, patreon = NULL WHERE guild = $4', [row.lang, row.inline, process.env.prefix, guild] ).then( ({rowCount}) => {
|
|
|
|
+ if ( rowCount ) {
|
|
|
|
+ console.log( '- Guild successfully updated.' );
|
|
|
|
+ messages.push('Guild successfully updated.');
|
|
}
|
|
}
|
|
- if ( !row ) {
|
|
|
|
- msg.replyMsg( 'that guild doesn\'t exist!', {}, true );
|
|
|
|
- return;
|
|
|
|
|
|
+ msg.client.shard.broadcastEval( `delete global.patreons['${guild}']`);
|
|
|
|
+ }, dberror => {
|
|
|
|
+ console.log( '- Error while updating the guild: ' + dberror );
|
|
|
|
+ messages.push('Error while updating the guild: ' + dberror);
|
|
|
|
+ return Promise.reject();
|
|
|
|
+ } );
|
|
|
|
+ }, dberror => {
|
|
|
|
+ console.log( '- Error while getting the guild: ' + dberror );
|
|
|
|
+ messages.push('Error while getting the guild: ' + dberror);
|
|
|
|
+ return Promise.reject();
|
|
|
|
+ } ).then( () => {
|
|
|
|
+ return client.query( 'DELETE FROM discord WHERE guild = $1 AND channel LIKE $2', [guild, '#%'] ).then( ({rowCount}) => {
|
|
|
|
+ if ( rowCount ) {
|
|
|
|
+ console.log( '- Channel categories successfully deleted.' );
|
|
|
|
+ messages.push('Channel categories successfully deleted.');
|
|
}
|
|
}
|
|
- db.run( 'UPDATE discord SET lang = ?, inline = ?, prefix = ?, patreon = NULL WHERE guild = ?', [row.lang, row.inline, process.env.prefix, guild], function (error) {
|
|
|
|
- try {
|
|
|
|
- if ( error ) {
|
|
|
|
- console.log( '- Error while updating the guild: ' + error );
|
|
|
|
- msg.replyMsg( 'I got an error while updating the guild!', {}, true );
|
|
|
|
- return error;
|
|
|
|
- }
|
|
|
|
- console.log( '- Guild successfully updated.' );
|
|
|
|
- msg.client.shard.broadcastEval( `delete global.patreons['${guild}']`);
|
|
|
|
- msg.replyMsg( 'the patreon features are now disabled on that guild.', {}, true );
|
|
|
|
- }
|
|
|
|
- catch ( tryerror ) {
|
|
|
|
- console.log( '- Error while removing the patreon features: ' + tryerror );
|
|
|
|
- }
|
|
|
|
- } );
|
|
|
|
- }
|
|
|
|
- catch ( tryerror ) {
|
|
|
|
- console.log( '- Error while removing the patreon features: ' + tryerror );
|
|
|
|
- }
|
|
|
|
- } );
|
|
|
|
- db.run( 'DELETE FROM discord WHERE guild = ? AND channel LIKE ?', [guild, '#%'], function (dberror) {
|
|
|
|
- if ( dberror ) {
|
|
|
|
|
|
+ }, dberror => {
|
|
console.log( '- Error while deleting the channel categories: ' + dberror );
|
|
console.log( '- Error while deleting the channel categories: ' + dberror );
|
|
- return dberror;
|
|
|
|
- }
|
|
|
|
- if ( this.changes ) console.log( '- Channel categories successfully deleted.' );
|
|
|
|
- } );
|
|
|
|
- db.all( 'SELECT configid FROM verification WHERE guild = ? ORDER BY configid ASC', [guild], (dberror, rows) => {
|
|
|
|
- if ( dberror ) {
|
|
|
|
- console.log( '- Error while getting the verifications: ' + dberror );
|
|
|
|
- return dberror;
|
|
|
|
- }
|
|
|
|
- var ids = rows.slice(verificationLimit.default).map( row => row.configid );
|
|
|
|
- if ( ids.length ) db.run( 'DELETE FROM verification WHERE guild = ? AND configid IN (' + ids.map( configid => '?' ).join(', ') + ')', [guild, ...ids], function (error) {
|
|
|
|
- if ( error ) {
|
|
|
|
- console.log( '- Error while deleting the verifications: ' + error );
|
|
|
|
- return error;
|
|
|
|
|
|
+ messages.push('Error while deleting the channel categories: ' + dberror);
|
|
|
|
+ } );
|
|
|
|
+ } ).then( () => {
|
|
|
|
+ return client.query( 'SELECT configid FROM verification WHERE guild = $1 ORDER BY configid ASC OFFSET $2', [guild, verificationLimit.default] ).then( ({rows}) => {
|
|
|
|
+ if ( rows.length ) {
|
|
|
|
+ return client.query( 'DELETE FROM verification WHERE guild = $1 AND configid IN (' + rows.map( (row, i) => '$' + ( i + 2 ) ).join(', ') + ')', [guild, ...rows.map( row => row.configid )] ).then( () => {
|
|
|
|
+ console.log( '- Verifications successfully deleted.' );
|
|
|
|
+ messages.push('Verifications successfully deleted.');
|
|
|
|
+ }, dberror => {
|
|
|
|
+ console.log( '- Error while deleting the verifications: ' + dberror );
|
|
|
|
+ messages.push('Error while deleting the verifications: ' + dberror);
|
|
|
|
+ } );
|
|
}
|
|
}
|
|
- console.log( '- Verifications successfully deleted.' );
|
|
|
|
|
|
+ }, dberror => {
|
|
|
|
+ console.log( '- Error while getting the verifications: ' + dberror );
|
|
|
|
+ messages.push('Error while getting the verifications: ' + dberror);
|
|
} );
|
|
} );
|
|
- } );
|
|
|
|
- db.all( 'SELECT webhook FROM rcgcdw WHERE guild = ? ORDER BY configid ASC', [guild], (dberror, rows) => {
|
|
|
|
- if ( dberror ) {
|
|
|
|
- console.log( '- Error while getting the RcGcDw: ' + dberror );
|
|
|
|
- return dberror;
|
|
|
|
- }
|
|
|
|
- var webhooks = rows.slice(rcgcdwLimit.default).map( row => row.webhook );
|
|
|
|
- if ( webhooks.length ) db.run( 'DELETE FROM rcgcdw WHERE webhook IN (' + webhooks.map( webhook => '?' ).join(', ') + ')', webhooks, function (error) {
|
|
|
|
- if ( error ) {
|
|
|
|
- console.log( '- Error while deleting the RcGcDw: ' + error );
|
|
|
|
- return error;
|
|
|
|
|
|
+ } ).then( () => {
|
|
|
|
+ return client.query( 'SELECT webhook FROM rcgcdw WHERE guild = $1 ORDER BY configid ASC OFFSET $2', [guild, rcgcdwLimit.default] ).then( ({rows}) => {
|
|
|
|
+ if ( rows.length ) {
|
|
|
|
+ return client.query( 'DELETE FROM rcgcdw WHERE webhook IN (' + rows.map( (row, i) => '$' + ( i + 1 ) ).join(', ') + ')', rows.map( row => row.webhook ) ).then( () => {
|
|
|
|
+ console.log( '- RcGcDw successfully deleted.' );
|
|
|
|
+ messages.push('RcGcDw successfully deleted.');
|
|
|
|
+ rows.forEach( row => msg.client.fetchWebhook(...row.webhook.split('/')).then( webhook => {
|
|
|
|
+ webhook.delete('Removed extra recent changes webhook').catch(log_error);
|
|
|
|
+ }, log_error ) );
|
|
|
|
+ }, dberror => {
|
|
|
|
+ console.log( '- Error while deleting the RcGcDw: ' + dberror );
|
|
|
|
+ messages.push('Error while deleting the RcGcDw: ' + dberror);
|
|
|
|
+ } );
|
|
}
|
|
}
|
|
- console.log( '- RcGcDw successfully deleted.' );
|
|
|
|
- webhooks.forEach( hook => guild.client.fetchWebhook(...hook.split('/')).then( webhook => {
|
|
|
|
- webhook.delete('Removed extra recent changes webhook').catch(log_error);
|
|
|
|
- }, log_error ) );
|
|
|
|
|
|
+ }, dberror => {
|
|
|
|
+ console.log( '- Error while getting the RcGcDw: ' + dberror );
|
|
|
|
+ messages.push('Error while getting the RcGcDw: ' + dberror);
|
|
} );
|
|
} );
|
|
- } );
|
|
|
|
- db.run( 'UPDATE rcgcdw SET display = ? WHERE guild = ? AND display > ?', [rcgcdwLimit.display, guild, rcgcdwLimit.display], function (dberror) {
|
|
|
|
- if ( dberror ) {
|
|
|
|
|
|
+ } ).then( () => {
|
|
|
|
+ return client.query( 'UPDATE rcgcdw SET display = $1 WHERE guild = $2 AND display > $1', [rcgcdwLimit.display, guild] ).then( () => {
|
|
|
|
+ console.log( '- RcGcDw successfully updated.' );
|
|
|
|
+ messages.push('RcGcDw successfully updated.');
|
|
|
|
+ }, dberror => {
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
- return dberror;
|
|
|
|
|
|
+ messages.push('Error while updating the RcGcDw: ' + dberror);
|
|
|
|
+ } );
|
|
|
|
+ } ).then( () => {
|
|
|
|
+ return messages;
|
|
|
|
+ }, error => {
|
|
|
|
+ if ( error ) {
|
|
|
|
+ console.log( '- Error while removing the patreon features: ' + error );
|
|
|
|
+ messages.push('Error while removing the patreon features: ' + error);
|
|
}
|
|
}
|
|
- console.log( '- RcGcDw successfully updated.' );
|
|
|
|
|
|
+ return messages;
|
|
|
|
+ } ).finally( () => {
|
|
|
|
+ client.release();
|
|
} );
|
|
} );
|
|
- }
|
|
|
|
- catch ( tryerror ) {
|
|
|
|
- console.log( '- Error while removing the patreon features: ' + tryerror );
|
|
|
|
- return 'removePatreons(guild, msg) – Error while removing the patreon features: ' + tryerror;
|
|
|
|
- }
|
|
|
|
|
|
+ }, dberror => {
|
|
|
|
+ console.log( '- Error while connecting to the database client: ' + dberror );
|
|
|
|
+ } );
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -261,7 +263,7 @@ function removePatreons(guild, msg) {
|
|
* @param {Discord.Message} msg - The Discord message.
|
|
* @param {Discord.Message} msg - The Discord message.
|
|
*/
|
|
*/
|
|
function removeSettings(msg) {
|
|
function removeSettings(msg) {
|
|
- if ( !msg ) return 'removeSettings(msg) – No message provided!';
|
|
|
|
|
|
+ if ( !( msg instanceof Discord.Message ) ) return 'removeSettings(msg) – No message provided!';
|
|
try {
|
|
try {
|
|
msg.client.shard.broadcastEval( `[
|
|
msg.client.shard.broadcastEval( `[
|
|
[...this.guilds.cache.keys()],
|
|
[...this.guilds.cache.keys()],
|
|
@@ -273,44 +275,41 @@ function removeSettings(msg) {
|
|
var all_channels = results.map( result => result[1] ).reduce( (acc, val) => acc.concat(val), [] );
|
|
var all_channels = results.map( result => result[1] ).reduce( (acc, val) => acc.concat(val), [] );
|
|
var guilds = [];
|
|
var guilds = [];
|
|
var channels = [];
|
|
var channels = [];
|
|
- db.each( 'SELECT guild, channel FROM discord', [], (dberror, row) => {
|
|
|
|
- if ( dberror ) {
|
|
|
|
- console.log( '- Error while getting the setting: ' + dberror );
|
|
|
|
- return dberror;
|
|
|
|
- }
|
|
|
|
- if ( !row.channel && !all_guilds.includes(row.guild) ) {
|
|
|
|
- if ( patreons.hasOwnProperty(row.guild) || voice.hasOwnProperty(row.guild) ) {
|
|
|
|
- msg.client.shard.broadcastEval( `delete global.patreons['${row.guild}'];
|
|
|
|
- delete global.voice['${row.guild}'];` );
|
|
|
|
|
|
+ db.query( 'SELECT guild, channel FROM discord' ).then( ({rows}) => {
|
|
|
|
+ rows.forEach( row => {
|
|
|
|
+ if ( !all_guilds.includes(row.guild) ) {
|
|
|
|
+ if ( !row.channel ) {
|
|
|
|
+ if ( patreons.hasOwnProperty(row.guild) || voice.hasOwnProperty(row.guild) ) {
|
|
|
|
+ msg.client.shard.broadcastEval( `delete global.patreons['${row.guild}'];
|
|
|
|
+ delete global.voice['${row.guild}'];` );
|
|
|
|
+ }
|
|
|
|
+ return guilds.push(row.guild);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return guilds.push(row.guild);
|
|
|
|
- }
|
|
|
|
- if ( row.channel && all_guilds.includes(row.guild) && !all_channels.includes(row.channel) ) return channels.push(row.channel);
|
|
|
|
- }, (error) => {
|
|
|
|
- if ( error ) {
|
|
|
|
- console.log( '- Error while getting the settings: ' + error );
|
|
|
|
- msg.replyMsg( 'I got an error while getting the settings!', {}, true );
|
|
|
|
- return error;
|
|
|
|
- }
|
|
|
|
|
|
+ else if ( row.channel && !all_channels.includes(row.channel) ) {
|
|
|
|
+ return channels.push(row.channel);
|
|
|
|
+ }
|
|
|
|
+ } );
|
|
if ( guilds.length ) {
|
|
if ( guilds.length ) {
|
|
- db.run( 'DELETE FROM discord WHERE main IN (' + guilds.map( guild => '?' ).join(', ') + ')', guilds, function (dberror) {
|
|
|
|
- if ( dberror ) {
|
|
|
|
- console.log( '- Error while removing the guilds: ' + dberror );
|
|
|
|
- msg.replyMsg( 'I got an error while removing the guilds!', {}, true );
|
|
|
|
- return dberror;
|
|
|
|
- }
|
|
|
|
- console.log( '- Guilds successfully removed: ' + this.changes );
|
|
|
|
|
|
+ db.query( 'DELETE FROM discord WHERE main IN (' + guilds.map( (guild, i) => '$' + ( i + 1 ) ).join(', ') + ')', guilds ).then( ({rowCount}) => {
|
|
|
|
+ console.log( '- Guilds successfully removed: ' + rowCount );
|
|
|
|
+ }, dberror => {
|
|
|
|
+ console.log( '- Error while removing the guilds: ' + dberror );
|
|
|
|
+ msg.replyMsg( 'I got an error while removing the guilds!', {}, true );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
- if ( channels.length ) db.run( 'DELETE FROM discord WHERE channel IN (' + channels.map( channel => '?' ).join(', ') + ')', channels, function (dberror) {
|
|
|
|
- if ( dberror ) {
|
|
|
|
|
|
+ if ( channels.length ) {
|
|
|
|
+ db.query( 'DELETE FROM discord WHERE channel IN (' + channels.map( (channel, i) => '$' + ( i + 1 ) ).join(', ') + ')', channels ).then( ({rowCount}) => {
|
|
|
|
+ console.log( '- Channels successfully removed: ' + rowCount );
|
|
|
|
+ }, dberror => {
|
|
console.log( '- Error while removing the channels: ' + dberror );
|
|
console.log( '- Error while removing the channels: ' + dberror );
|
|
msg.replyMsg( 'I got an error while removing the channels!', {}, true );
|
|
msg.replyMsg( 'I got an error while removing the channels!', {}, true );
|
|
- return dberror;
|
|
|
|
- }
|
|
|
|
- console.log( '- Channels successfully removed: ' + this.changes );
|
|
|
|
- } );
|
|
|
|
|
|
+ } );
|
|
|
|
+ }
|
|
if ( !guilds.length && !channels.length ) console.log( '- Settings successfully removed.' );
|
|
if ( !guilds.length && !channels.length ) console.log( '- Settings successfully removed.' );
|
|
|
|
+ }, dberror => {
|
|
|
|
+ console.log( '- Error while getting the settings: ' + dberror );
|
|
|
|
+ msg.replyMsg( 'I got an error while getting the settings!', {}, true );
|
|
} );
|
|
} );
|
|
} );
|
|
} );
|
|
}
|
|
}
|