|
@@ -1,4 +1,5 @@
|
|
const cheerio = require('cheerio');
|
|
const cheerio = require('cheerio');
|
|
|
|
+const {Util, MessageActionRow, MessageButton, Permissions: {FLAGS}} = require('discord.js');
|
|
const help_setup = require('../functions/helpsetup.js');
|
|
const help_setup = require('../functions/helpsetup.js');
|
|
const {limit: {rcgcdw: rcgcdwLimit}} = require('../util/default.json');
|
|
const {limit: {rcgcdw: rcgcdwLimit}} = require('../util/default.json');
|
|
const {got} = require('../util/functions.js');
|
|
const {got} = require('../util/functions.js');
|
|
@@ -30,53 +31,40 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
if ( !msg.isAdmin() ) return msg.reactEmoji('❌');
|
|
if ( !msg.isAdmin() ) return msg.reactEmoji('❌');
|
|
if ( msg.defaultSettings ) return help_setup(lang, msg);
|
|
if ( msg.defaultSettings ) return help_setup(lang, msg);
|
|
|
|
|
|
- db.query( 'SELECT configid, webhook, wiki, lang, display, rcid, postid FROM rcgcdw WHERE guild = $1 ORDER BY configid ASC', [msg.guild.id] ).then( ({rows}) => {
|
|
|
|
|
|
+ db.query( 'SELECT configid, webhook, wiki, lang, display, rcid, postid FROM rcgcdw WHERE guild = $1 ORDER BY configid ASC', [msg.guildId] ).then( ({rows}) => {
|
|
var prefix = process.env.prefix;
|
|
var prefix = process.env.prefix;
|
|
var limit = rcgcdwLimit.default;
|
|
var limit = rcgcdwLimit.default;
|
|
var display = display_types.slice(0, rcgcdwLimit.display + 1);
|
|
var display = display_types.slice(0, rcgcdwLimit.display + 1);
|
|
- if ( patreons[msg.guild.id] ) {
|
|
|
|
- prefix = patreons[msg.guild.id];
|
|
|
|
|
|
+ if ( patreons[msg.guildId] ) {
|
|
|
|
+ prefix = patreons[msg.guildId];
|
|
limit = rcgcdwLimit.patreon;
|
|
limit = rcgcdwLimit.patreon;
|
|
display = display_types.slice();
|
|
display = display_types.slice();
|
|
}
|
|
}
|
|
- var button = {
|
|
|
|
- type: 2,
|
|
|
|
- style: 5,
|
|
|
|
- label: lang.get('settings.button'),
|
|
|
|
- emoji: {
|
|
|
|
- id: '588723255972593672',
|
|
|
|
- name: 'wikibot',
|
|
|
|
- animated: false
|
|
|
|
- },
|
|
|
|
- url: new URL(`/guild/${msg.guild.id}/rcscript`, process.env.dashboard).href,
|
|
|
|
- disabled: false
|
|
|
|
- };
|
|
|
|
|
|
+ var button = null;
|
|
var components = [];
|
|
var components = [];
|
|
- if ( process.env.dashboard ) components.push({
|
|
|
|
- type: 1,
|
|
|
|
- components: [
|
|
|
|
- button
|
|
|
|
- ]
|
|
|
|
- });
|
|
|
|
|
|
+ if ( process.env.dashboard ) {
|
|
|
|
+ button = new MessageButton().setLabel(lang.get('settings.button')).setEmoji('<:wikibot:588723255972593672>').setStyle('LINK').setURL(new URL(`/guild/${msg.guildId}/rcscript`, process.env.dashboard).href);
|
|
|
|
+ components.push(new MessageActionRow().addComponents(button));
|
|
|
|
+ }
|
|
|
|
|
|
if ( args[0] === 'add' ) {
|
|
if ( args[0] === 'add' ) {
|
|
- if ( !msg.channel.permissionsFor(msg.client.user).has('MANAGE_WEBHOOKS') ) {
|
|
|
|
- console.log( msg.guild.id + ': Missing permissions - MANAGE_WEBHOOKS' );
|
|
|
|
|
|
+ if ( !msg.channel.permissionsFor(msg.client.user).has(FLAGS.MANAGE_WEBHOOKS) ) {
|
|
|
|
+ console.log( msg.guildId + ': Missing permissions - MANAGE_WEBHOOKS' );
|
|
return msg.replyMsg( lang.get('general.missingperm') + ' `MANAGE_WEBHOOKS`' );
|
|
return msg.replyMsg( lang.get('general.missingperm') + ' `MANAGE_WEBHOOKS`' );
|
|
}
|
|
}
|
|
- if ( !( msg.channel.permissionsFor(msg.member).has('MANAGE_WEBHOOKS') || ( msg.isOwner() && msg.evalUsed ) ) ) {
|
|
|
|
|
|
+ if ( !( msg.channel.permissionsFor(msg.member).has(FLAGS.MANAGE_WEBHOOKS) || ( msg.isOwner() && msg.evalUsed ) ) ) {
|
|
return msg.replyMsg( lang.get('rcscript.noadmin') );
|
|
return msg.replyMsg( lang.get('rcscript.noadmin') );
|
|
}
|
|
}
|
|
- if ( rows.length >= limit ) return msg.replyMsg( lang.get('rcscript.max_entries'), {}, true );
|
|
|
|
- if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, {}, true );
|
|
|
|
|
|
+ if ( rows.length >= limit ) return msg.replyMsg( lang.get('rcscript.max_entries'), true );
|
|
|
|
+ if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, true );
|
|
|
|
|
|
- button.url = new URL(`/guild/${msg.guild.id}/rcscript/new`, process.env.dashboard).href;
|
|
|
|
|
|
+ button?.setURL(new URL(`/guild/${msg.guildId}/rcscript/new`, button.url).href);
|
|
var wikihelp = '\n`' + prefix + 'rcscript add ' + lang.get('rcscript.new_wiki') + '`\n' + lang.get('rcscript.help_wiki');
|
|
var wikihelp = '\n`' + prefix + 'rcscript add ' + lang.get('rcscript.new_wiki') + '`\n' + lang.get('rcscript.help_wiki');
|
|
var input = args.slice(1).join(' ').toLowerCase().trim().replace( /^<\s*(.*?)\s*>$/, '$1' );
|
|
var input = args.slice(1).join(' ').toLowerCase().trim().replace( /^<\s*(.*?)\s*>$/, '$1' );
|
|
var wikinew = new Wiki(wiki);
|
|
var wikinew = new Wiki(wiki);
|
|
if ( input ) {
|
|
if ( input ) {
|
|
wikinew = Wiki.fromInput(input);
|
|
wikinew = Wiki.fromInput(input);
|
|
- if ( !wikinew ) return msg.replyMsg( lang.get('settings.wikiinvalid') + wikihelp, {components}, true );
|
|
|
|
|
|
+ if ( !wikinew ) return msg.replyMsg( {content: lang.get('settings.wikiinvalid') + wikihelp, components}, true );
|
|
}
|
|
}
|
|
return msg.reactEmoji('⏳', true).then( reaction => got.get( wikinew + 'api.php?&action=query&meta=allmessages|siteinfo&ammessages=custom-RcGcDw|recentchanges&amenableparser=true&siprop=general&titles=Special:RecentChanges&format=json', {
|
|
return msg.reactEmoji('⏳', true).then( reaction => got.get( wikinew + 'api.php?&action=query&meta=allmessages|siteinfo&ammessages=custom-RcGcDw|recentchanges&amenableparser=true&siprop=general&titles=Special:RecentChanges&format=json', {
|
|
responseType: 'text'
|
|
responseType: 'text'
|
|
@@ -100,25 +88,25 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
console.log( '- ' + response.statusCode + ': Error while testing the wiki: ' + body?.error?.info );
|
|
console.log( '- ' + response.statusCode + ': Error while testing the wiki: ' + body?.error?.info );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( body?.error?.info === 'You need read permission to use this module.' ) {
|
|
if ( body?.error?.info === 'You need read permission to use this module.' ) {
|
|
- return msg.replyMsg( lang.get('settings.wikiinvalid_private') + wikihelp, {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('settings.wikiinvalid_private') + wikihelp, components}, true );
|
|
}
|
|
}
|
|
msg.reactEmoji('nowiki', true);
|
|
msg.reactEmoji('nowiki', true);
|
|
- return msg.replyMsg( lang.get('settings.wikiinvalid') + wikihelp, {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('settings.wikiinvalid') + wikihelp, components}, true );
|
|
}
|
|
}
|
|
wikinew.updateWiki(body.query.general);
|
|
wikinew.updateWiki(body.query.general);
|
|
if ( body.query.general.generator.replace( /^MediaWiki 1\.(\d\d).*$/, '$1' ) < 30 ) {
|
|
if ( body.query.general.generator.replace( /^MediaWiki 1\.(\d\d).*$/, '$1' ) < 30 ) {
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- return msg.replyMsg( lang.get('test.MediaWiki', 'MediaWiki 1.30', body.query.general.generator) + '\nhttps://www.mediawiki.org/wiki/MediaWiki_1.30', {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('test.MediaWiki', 'MediaWiki 1.30', body.query.general.generator) + '\nhttps://www.mediawiki.org/wiki/MediaWiki_1.30', components}, true );
|
|
}
|
|
}
|
|
- if ( body.query.allmessages[0]['*'] !== msg.guild.id ) {
|
|
|
|
|
|
+ if ( body.query.allmessages[0]['*'] !== msg.guildId ) {
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- return msg.replyMsg( lang.get('rcscript.sysmessage', 'MediaWiki:Custom-RcGcDw', msg.guild.id) + '\n<' + wikinew.toLink('MediaWiki:Custom-RcGcDw', 'action=edit') + '>', {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('rcscript.sysmessage', 'MediaWiki:Custom-RcGcDw', msg.guildId) + '\n<' + wikinew.toLink('MediaWiki:Custom-RcGcDw', 'action=edit') + '>', components}, true );
|
|
}
|
|
}
|
|
return db.query( 'SELECT reason FROM blocklist WHERE wiki = $1', [wikinew.href] ).then( ({rows:[block]}) => {
|
|
return db.query( 'SELECT reason FROM blocklist WHERE wiki = $1', [wikinew.href] ).then( ({rows:[block]}) => {
|
|
if ( block ) {
|
|
if ( block ) {
|
|
console.log( '- This wiki is blocked: ' + block.reason );
|
|
console.log( '- This wiki is blocked: ' + block.reason );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- return msg.replyMsg( ( block.reason ? lang.get('rcscript.blocked_reason', block.reason) : lang.get('rcscript.blocked') ), {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: ( block.reason ? lang.get('rcscript.blocked_reason', block.reason) : lang.get('rcscript.blocked') ), components}, true );
|
|
}
|
|
}
|
|
if ( wikinew.isFandom(false) ) return got.get( wikinew + 'wikia.php?controller=DiscussionPost&method=getPosts&includeCounters=false&limit=1&format=json&cache=' + Date.now(), {
|
|
if ( wikinew.isFandom(false) ) return got.get( wikinew + 'wikia.php?controller=DiscussionPost&method=getPosts&includeCounters=false&limit=1&format=json&cache=' + Date.now(), {
|
|
headers: {
|
|
headers: {
|
|
@@ -154,19 +142,19 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
if ( new_configid === i ) new_configid++;
|
|
if ( new_configid === i ) new_configid++;
|
|
else break;
|
|
else break;
|
|
}
|
|
}
|
|
- db.query( 'INSERT INTO rcgcdw(guild, configid, webhook, wiki, lang, display, postid) VALUES($1, $2, $3, $4, $5, $6, $7)', [msg.guild.id, new_configid, webhook.id + '/' + webhook.token, wikinew.href, webhook_lang.lang, ( msg.showEmbed() ? 1 : 0 ), ( enableFeeds ? null : '-1' )] ).then( () => {
|
|
|
|
|
|
+ db.query( 'INSERT INTO rcgcdw(guild, configid, webhook, wiki, lang, display, postid) VALUES($1, $2, $3, $4, $5, $6, $7)', [msg.guildId, new_configid, webhook.id + '/' + webhook.token, wikinew.href, webhook_lang.lang, ( msg.showEmbed() ? 1 : 0 ), ( enableFeeds ? null : '-1' )] ).then( () => {
|
|
console.log( '- RcGcDw successfully added.' );
|
|
console.log( '- RcGcDw successfully added.' );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- msg.replyMsg( lang.get('rcscript.added') + ' <' + wikinew + '>\n`' + prefix + 'rcscript' + ( rows.length ? ' ' + new_configid : '' ) + '`', {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('rcscript.added') + ' <' + wikinew + '>\n`' + prefix + 'rcscript' + ( rows.length ? ' ' + new_configid : '' ) + '`', components}, true );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while adding the RcGcDw: ' + dberror );
|
|
console.log( '- Error while adding the RcGcDw: ' + dberror );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- msg.replyMsg( lang.get('settings.save_failed'), {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('settings.save_failed'), components}, true );
|
|
} );
|
|
} );
|
|
}, error => {
|
|
}, error => {
|
|
console.log( '- Error while creating the webhook: ' + error );
|
|
console.log( '- Error while creating the webhook: ' + error );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- msg.replyMsg( lang.get('rcscript.webhook_failed'), {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('rcscript.webhook_failed'), components}, true );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
}, dberror => {
|
|
}, dberror => {
|
|
@@ -178,14 +166,14 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( error.message?.startsWith( 'connect ECONNREFUSED ' ) || error.message?.startsWith( 'Hostname/IP does not match certificate\'s altnames: ' ) || error.message === 'certificate has expired' || error.message === 'self signed certificate' ) {
|
|
if ( error.message?.startsWith( 'connect ECONNREFUSED ' ) || error.message?.startsWith( 'Hostname/IP does not match certificate\'s altnames: ' ) || error.message === 'certificate has expired' || error.message === 'self signed certificate' ) {
|
|
console.log( '- Error while testing the wiki: No HTTPS' );
|
|
console.log( '- Error while testing the wiki: No HTTPS' );
|
|
- return msg.replyMsg( lang.get('settings.wikiinvalid_http') + wikihelp, {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('settings.wikiinvalid_http') + wikihelp, components}, true );
|
|
}
|
|
}
|
|
console.log( '- Error while testing the wiki: ' + error );
|
|
console.log( '- Error while testing the wiki: ' + error );
|
|
if ( error.message === `Timeout awaiting 'request' for ${got.defaults.options.timeout.request}ms` ) {
|
|
if ( error.message === `Timeout awaiting 'request' for ${got.defaults.options.timeout.request}ms` ) {
|
|
- return msg.replyMsg( lang.get('settings.wikiinvalid_timeout') + wikihelp, {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('settings.wikiinvalid_timeout') + wikihelp, components}, true );
|
|
}
|
|
}
|
|
msg.reactEmoji('nowiki', true);
|
|
msg.reactEmoji('nowiki', true);
|
|
- return msg.replyMsg( lang.get('settings.wikiinvalid') + wikihelp, {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('settings.wikiinvalid') + wikihelp, components}, true );
|
|
} ) );
|
|
} ) );
|
|
}
|
|
}
|
|
|
|
|
|
@@ -205,10 +193,10 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
let cmd = prefix + 'rcscript' + ( rows.length === 1 ? '' : ' ' + selected_row.configid );
|
|
let cmd = prefix + 'rcscript' + ( rows.length === 1 ? '' : ' ' + selected_row.configid );
|
|
|
|
|
|
if ( args[0] === 'delete' && !args[1] ) {
|
|
if ( args[0] === 'delete' && !args[1] ) {
|
|
- if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, {}, true );
|
|
|
|
|
|
+ if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, true );
|
|
return msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
return msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
- var channel = msg.guild.channels.cache.get(webhook.channelID);
|
|
|
|
- if ( !channel || !channel.permissionsFor(msg.member).has('MANAGE_WEBHOOKS') ) {
|
|
|
|
|
|
+ var channel = msg.guild.channels.cache.get(webhook.channelId);
|
|
|
|
+ if ( !channel || !channel.permissionsFor(msg.member).has(FLAGS.MANAGE_WEBHOOKS) ) {
|
|
return msg.replyMsg( lang.get('rcscript.noadmin') );
|
|
return msg.replyMsg( lang.get('rcscript.noadmin') );
|
|
}
|
|
}
|
|
db.query( 'DELETE FROM rcgcdw WHERE webhook = $1', [selected_row.webhook] ).then( () => {
|
|
db.query( 'DELETE FROM rcgcdw WHERE webhook = $1', [selected_row.webhook] ).then( () => {
|
|
@@ -216,38 +204,38 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
webhook.send( webhook_lang.get('deleted') ).catch(log_error).finally( () => {
|
|
webhook.send( webhook_lang.get('deleted') ).catch(log_error).finally( () => {
|
|
webhook.delete(lang.get('rcscript.audit_reason_delete')).catch(log_error);
|
|
webhook.delete(lang.get('rcscript.audit_reason_delete')).catch(log_error);
|
|
} );
|
|
} );
|
|
- msg.replyMsg( lang.get('rcscript.deleted'), {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('rcscript.deleted'), components}, true );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while removing the RcGcDw: ' + dberror );
|
|
console.log( '- Error while removing the RcGcDw: ' + dberror );
|
|
- button.url = new URL(`/guild/${msg.guild.id}/rcscript/${selected_row.configid}`, process.env.dashboard).href;
|
|
|
|
- msg.replyMsg( lang.get('settings.save_failed'), {components}, true );
|
|
|
|
|
|
+ button?.setURL(new URL(`/guild/${msg.guildId}/rcscript/${selected_row.configid}`, button.url).href);
|
|
|
|
+ msg.replyMsg( {content: lang.get('settings.save_failed'), components}, true );
|
|
} );
|
|
} );
|
|
}, error => {
|
|
}, error => {
|
|
log_error(error);
|
|
log_error(error);
|
|
if ( error.name === 'DiscordAPIError' && ['Unknown Webhook', 'Invalid Webhook Token'].includes( error.message ) ) {
|
|
if ( error.name === 'DiscordAPIError' && ['Unknown Webhook', 'Invalid Webhook Token'].includes( error.message ) ) {
|
|
- button.url = new URL(`/guild/${msg.guild.id}/rcscript/${selected_row.configid}`, process.env.dashboard).href;
|
|
|
|
- return msg.replyMsg( lang.get('settings.save_failed'), {components}, true );
|
|
|
|
|
|
+ button?.setURL(new URL(`/guild/${msg.guildId}/rcscript/${selected_row.configid}`, button.url).href);
|
|
|
|
+ return msg.replyMsg( {content: lang.get('settings.save_failed'), components}, true );
|
|
}
|
|
}
|
|
db.query( 'DELETE FROM rcgcdw WHERE webhook = $1', [selected_row.webhook] ).then( () => {
|
|
db.query( 'DELETE FROM rcgcdw WHERE webhook = $1', [selected_row.webhook] ).then( () => {
|
|
console.log( '- RcGcDw successfully removed.' );
|
|
console.log( '- RcGcDw successfully removed.' );
|
|
- msg.replyMsg( lang.get('rcscript.deleted'), {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('rcscript.deleted'), components}, true );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while removing the RcGcDw: ' + dberror );
|
|
console.log( '- Error while removing the RcGcDw: ' + dberror );
|
|
- button.url = new URL(`/guild/${msg.guild.id}/rcscript/${selected_row.configid}`, process.env.dashboard).href;
|
|
|
|
- msg.replyMsg( lang.get('settings.save_failed'), {components}, true );
|
|
|
|
|
|
+ button?.setURL(new URL(`/guild/${msg.guildId}/rcscript/${selected_row.configid}`, button.url).href);
|
|
|
|
+ msg.replyMsg( {content: lang.get('settings.save_failed'), components}, true );
|
|
} );
|
|
} );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
- button.url = new URL(`/guild/${msg.guild.id}/rcscript/${selected_row.configid}`, process.env.dashboard).href;
|
|
|
|
|
|
+ button?.setURL(new URL(`/guild/${msg.guildId}/rcscript/${selected_row.configid}`, button.url).href);
|
|
if ( args[0] === 'wiki' ) {
|
|
if ( args[0] === 'wiki' ) {
|
|
if ( !args[1] ) {
|
|
if ( !args[1] ) {
|
|
- return msg.replyMsg( lang.get('rcscript.current_wiki') + ' <' + selected_row.wiki + '>\n`' + cmd + ' wiki ' + lang.get('rcscript.new_wiki') + '`\n' + lang.get('rcscript.help_wiki'), {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('rcscript.current_wiki') + ' <' + selected_row.wiki + '>\n`' + cmd + ' wiki ' + lang.get('rcscript.new_wiki') + '`\n' + lang.get('rcscript.help_wiki'), components}, true );
|
|
}
|
|
}
|
|
- if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, {}, true );
|
|
|
|
|
|
+ if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, true );
|
|
|
|
|
|
var wikihelp = '\n`' + cmd + ' wiki ' + lang.get('rcscript.new_wiki') + '`\n' + lang.get('rcscript.help_wiki');
|
|
var wikihelp = '\n`' + cmd + ' wiki ' + lang.get('rcscript.new_wiki') + '`\n' + lang.get('rcscript.help_wiki');
|
|
var wikinew = Wiki.fromInput(args[1]);
|
|
var wikinew = Wiki.fromInput(args[1]);
|
|
- if ( !wikinew ) return msg.replyMsg( lang.get('settings.wikiinvalid') + wikihelp, {components}, true );
|
|
|
|
|
|
+ if ( !wikinew ) return msg.replyMsg( {content: lang.get('settings.wikiinvalid') + wikihelp, components}, true );
|
|
return msg.reactEmoji('⏳', true).then( reaction => got.get( wikinew + 'api.php?&action=query&meta=allmessages|siteinfo&ammessages=custom-RcGcDw&amenableparser=true&siprop=general&titles=Special:RecentChanges&format=json', {
|
|
return msg.reactEmoji('⏳', true).then( reaction => got.get( wikinew + 'api.php?&action=query&meta=allmessages|siteinfo&ammessages=custom-RcGcDw&amenableparser=true&siprop=general&titles=Special:RecentChanges&format=json', {
|
|
responseType: 'text'
|
|
responseType: 'text'
|
|
} ).then( response => {
|
|
} ).then( response => {
|
|
@@ -270,26 +258,26 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
console.log( '- ' + response.statusCode + ': Error while testing the wiki: ' + body?.error?.info );
|
|
console.log( '- ' + response.statusCode + ': Error while testing the wiki: ' + body?.error?.info );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( body?.error?.info === 'You need read permission to use this module.' ) {
|
|
if ( body?.error?.info === 'You need read permission to use this module.' ) {
|
|
- return msg.replyMsg( lang.get('settings.wikiinvalid_private') + wikihelp, {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('settings.wikiinvalid_private') + wikihelp, components}, true );
|
|
}
|
|
}
|
|
msg.reactEmoji('nowiki', true);
|
|
msg.reactEmoji('nowiki', true);
|
|
- return msg.replyMsg( lang.get('settings.wikiinvalid') + wikihelp, {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('settings.wikiinvalid') + wikihelp, components}, true );
|
|
}
|
|
}
|
|
wikinew.updateWiki(body.query.general);
|
|
wikinew.updateWiki(body.query.general);
|
|
if ( body.query.general.generator.replace( /^MediaWiki 1\.(\d\d).*$/, '$1' ) <= 30 ) {
|
|
if ( body.query.general.generator.replace( /^MediaWiki 1\.(\d\d).*$/, '$1' ) <= 30 ) {
|
|
console.log( '- This wiki is using ' + body.query.general.generator + '.' );
|
|
console.log( '- This wiki is using ' + body.query.general.generator + '.' );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- return msg.replyMsg( lang.get('test.MediaWiki', 'MediaWiki 1.30', body.query.general.generator) + '\nhttps://www.mediawiki.org/wiki/MediaWiki_1.30', {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('test.MediaWiki', 'MediaWiki 1.30', body.query.general.generator) + '\nhttps://www.mediawiki.org/wiki/MediaWiki_1.30', components}, true );
|
|
}
|
|
}
|
|
- if ( body.query.allmessages[0]['*'] !== msg.guild.id ) {
|
|
|
|
|
|
+ if ( body.query.allmessages[0]['*'] !== msg.guildId ) {
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- return msg.replyMsg( lang.get('rcscript.sysmessage', 'MediaWiki:Custom-RcGcDw', msg.guild.id) + '\n<' + wikinew.toLink('MediaWiki:Custom-RcGcDw', 'action=edit') + '>', {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('rcscript.sysmessage', 'MediaWiki:Custom-RcGcDw', msg.guildId) + '\n<' + wikinew.toLink('MediaWiki:Custom-RcGcDw', 'action=edit') + '>', components}, true );
|
|
}
|
|
}
|
|
return db.query( 'SELECT reason FROM blocklist WHERE wiki = $1', [wikinew.href] ).then( ({rows:[block]}) => {
|
|
return db.query( 'SELECT reason FROM blocklist WHERE wiki = $1', [wikinew.href] ).then( ({rows:[block]}) => {
|
|
if ( block ) {
|
|
if ( block ) {
|
|
console.log( '- This wiki is blocked: ' + block.reason );
|
|
console.log( '- This wiki is blocked: ' + block.reason );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- return msg.replyMsg( ( block.reason ? lang.get('rcscript.blocked_reason', block.reason) : lang.get('rcscript.blocked') ), {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: ( block.reason ? lang.get('rcscript.blocked_reason', block.reason) : lang.get('rcscript.blocked') ), components}, true );
|
|
}
|
|
}
|
|
if ( wikinew.isFandom(false) ) return got.get( wikinew + 'wikia.php?controller=DiscussionPost&method=getPosts&includeCounters=false&limit=1&format=json&cache=' + Date.now(), {
|
|
if ( wikinew.isFandom(false) ) return got.get( wikinew + 'wikia.php?controller=DiscussionPost&method=getPosts&includeCounters=false&limit=1&format=json&cache=' + Date.now(), {
|
|
headers: {
|
|
headers: {
|
|
@@ -319,11 +307,11 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
db.query( 'UPDATE rcgcdw SET wiki = $1, rcid = $2, postid = $3 WHERE webhook = $4', [wikinew.href, null, ( enableFeeds ? null : '-1' ), selected_row.webhook] ).then( () => {
|
|
db.query( 'UPDATE rcgcdw SET wiki = $1, rcid = $2, postid = $3 WHERE webhook = $4', [wikinew.href, null, ( enableFeeds ? null : '-1' ), selected_row.webhook] ).then( () => {
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- msg.replyMsg( lang.get('rcscript.updated_wiki') + ' <' + wikinew + '>\n`' + cmd + '`', {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('rcscript.updated_wiki') + ' <' + wikinew + '>\n`' + cmd + '`', components}, true );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- msg.replyMsg( lang.get('settings.save_failed'), {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('settings.save_failed'), components}, true );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
}, dberror => {
|
|
}, dberror => {
|
|
@@ -335,43 +323,43 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( error.message?.startsWith( 'connect ECONNREFUSED ' ) || error.message?.startsWith( 'Hostname/IP does not match certificate\'s altnames: ' ) || error.message === 'certificate has expired' || error.message === 'self signed certificate' ) {
|
|
if ( error.message?.startsWith( 'connect ECONNREFUSED ' ) || error.message?.startsWith( 'Hostname/IP does not match certificate\'s altnames: ' ) || error.message === 'certificate has expired' || error.message === 'self signed certificate' ) {
|
|
console.log( '- Error while testing the wiki: No HTTPS' );
|
|
console.log( '- Error while testing the wiki: No HTTPS' );
|
|
- return msg.replyMsg( lang.get('settings.wikiinvalid_http') + wikihelp, {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('settings.wikiinvalid_http') + wikihelp, components}, true );
|
|
}
|
|
}
|
|
console.log( '- Error while testing the wiki: ' + error );
|
|
console.log( '- Error while testing the wiki: ' + error );
|
|
if ( error.message === `Timeout awaiting 'request' for ${got.defaults.options.timeout.request}ms` ) {
|
|
if ( error.message === `Timeout awaiting 'request' for ${got.defaults.options.timeout.request}ms` ) {
|
|
- return msg.replyMsg( lang.get('settings.wikiinvalid_timeout') + wikihelp, {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('settings.wikiinvalid_timeout') + wikihelp, components}, true );
|
|
}
|
|
}
|
|
msg.reactEmoji('nowiki', true);
|
|
msg.reactEmoji('nowiki', true);
|
|
- return msg.replyMsg( lang.get('settings.wikiinvalid') + wikihelp, {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('settings.wikiinvalid') + wikihelp, components}, true );
|
|
} ) );
|
|
} ) );
|
|
}
|
|
}
|
|
if ( args[0] === 'lang' || args[0] === 'language' ) {
|
|
if ( args[0] === 'lang' || args[0] === 'language' ) {
|
|
if ( !args[1] ) {
|
|
if ( !args[1] ) {
|
|
- return msg.replyMsg( lang.get('rcscript.current_lang') + ' `' + allLangs.names[selected_row.lang] + '`\n`' + cmd + ' lang ' + lang.get('rcscript.new_lang') + '`\n' + lang.get('rcscript.help_lang') + ' `' + Object.values(allLangs.names).join('`, `') + '`', {files:( msg.uploadFiles() ? [`./RcGcDb/locale/widgets/${selected_row.lang}.png`] : [] ),components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('rcscript.current_lang') + ' `' + allLangs.names[selected_row.lang] + '`\n`' + cmd + ' lang ' + lang.get('rcscript.new_lang') + '`\n' + lang.get('rcscript.help_lang') + ' `' + Object.values(allLangs.names).join('`, `') + '`', files: ( msg.uploadFiles() ? [`./RcGcDb/locale/widgets/${selected_row.lang}.png`] : [] ), components}, true );
|
|
}
|
|
}
|
|
- if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, {}, true );
|
|
|
|
|
|
+ if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, true );
|
|
if ( !allLangs.map.hasOwnProperty(args[1]) ) {
|
|
if ( !allLangs.map.hasOwnProperty(args[1]) ) {
|
|
- return msg.replyMsg( lang.get('settings.langinvalid') + '\n`' + cmd + ' lang ' + lang.get('rcscript.new_lang') + '`\n' + lang.get('rcscript.help_lang') + ' `' + Object.values(allLangs.names).join('`, `') + '`', {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('settings.langinvalid') + '\n`' + cmd + ' lang ' + lang.get('rcscript.new_lang') + '`\n' + lang.get('rcscript.help_lang') + ' `' + Object.values(allLangs.names).join('`, `') + '`', components}, true );
|
|
}
|
|
}
|
|
|
|
|
|
msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
- webhook.send( new Lang(allLangs.map[args[1]], 'rcscript.webhook').get('updated_lang', allLangs.names[allLangs.map[args[1]]]), {files:[`./RcGcDb/locale/widgets/${allLangs.map[args[1]]}.png`]} ).catch(log_error);
|
|
|
|
|
|
+ webhook.send( {content: new Lang(allLangs.map[args[1]], 'rcscript.webhook').get('updated_lang', allLangs.names[allLangs.map[args[1]]]), files: [`./RcGcDb/locale/widgets/${allLangs.map[args[1]]}.png`]} ).catch(log_error);
|
|
}, log_error );
|
|
}, log_error );
|
|
return db.query( 'UPDATE rcgcdw SET lang = $1 WHERE webhook = $2', [allLangs.map[args[1]], selected_row.webhook] ).then( () => {
|
|
return db.query( 'UPDATE rcgcdw SET lang = $1 WHERE webhook = $2', [allLangs.map[args[1]], selected_row.webhook] ).then( () => {
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
- msg.replyMsg( lang.get('rcscript.updated_lang') + ' `' + allLangs.names[allLangs.map[args[1]]] + '`\n`' + cmd + '`', {files:( msg.uploadFiles() ? [`./RcGcDb/locale/widgets/${allLangs.map[args[1]]}.png`] : [] ),components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('rcscript.updated_lang') + ' `' + allLangs.names[allLangs.map[args[1]]] + '`\n`' + cmd + '`', files: ( msg.uploadFiles() ? [`./RcGcDb/locale/widgets/${allLangs.map[args[1]]}.png`] : [] ), components}, true );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
- msg.replyMsg( lang.get('settings.save_failed'), {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('settings.save_failed'), components}, true );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
if ( args[0] === 'display' ) {
|
|
if ( args[0] === 'display' ) {
|
|
if ( !args[1] || !display_types.includes( args[1] ) ) {
|
|
if ( !args[1] || !display_types.includes( args[1] ) ) {
|
|
- return msg.replyMsg( lang.get('rcscript.current_display') + ' `' + display_types[selected_row.display] + '`\n`' + cmd + ' display (' + display.join('|') + ')`\n' + display.map( display_type => '`' + display_type + '`: ' + lang.get('rcscript.help_display_' + display_type) ).join('\n'), {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('rcscript.current_display') + ' `' + display_types[selected_row.display] + '`\n`' + cmd + ' display (' + display.join('|') + ')`\n' + display.map( display_type => '`' + display_type + '`: ' + lang.get('rcscript.help_display_' + display_type) ).join('\n'), components}, true );
|
|
}
|
|
}
|
|
- if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, {}, true );
|
|
|
|
|
|
+ if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, true );
|
|
if ( !display.includes( args[1] ) ) {
|
|
if ( !display.includes( args[1] ) ) {
|
|
- return msg.replyMsg( lang.get('general.patreon') + '\n<' + process.env.patreon + '>', {}, true );
|
|
|
|
|
|
+ return msg.replyMsg( lang.get('general.patreon') + '\n<' + process.env.patreon + '>', true );
|
|
}
|
|
}
|
|
|
|
|
|
msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
@@ -379,14 +367,14 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
}, log_error );
|
|
}, log_error );
|
|
return db.query( 'UPDATE rcgcdw SET display = $1 WHERE webhook = $2', [display_types.indexOf(args[1]), selected_row.webhook] ).then( () => {
|
|
return db.query( 'UPDATE rcgcdw SET display = $1 WHERE webhook = $2', [display_types.indexOf(args[1]), selected_row.webhook] ).then( () => {
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
- msg.replyMsg( lang.get('rcscript.updated_display') + ' `' + args[1] + '`\n`' + cmd + '`', {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('rcscript.updated_display') + ' `' + args[1] + '`\n`' + cmd + '`', components}, true );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
- msg.replyMsg( lang.get('settings.save_failed'), {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('settings.save_failed'), components}, true );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
if ( new Wiki(selected_row.wiki).isFandom(false) && args[0] === 'feeds' ) {
|
|
if ( new Wiki(selected_row.wiki).isFandom(false) && args[0] === 'feeds' ) {
|
|
- if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, {}, true );
|
|
|
|
|
|
+ if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, true );
|
|
if ( args[1] === 'only' ) {
|
|
if ( args[1] === 'only' ) {
|
|
if ( selected_row.rcid === -1 ) {
|
|
if ( selected_row.rcid === -1 ) {
|
|
msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
@@ -394,41 +382,41 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
}, log_error );
|
|
}, log_error );
|
|
return db.query( 'UPDATE rcgcdw SET rcid = $1 WHERE webhook = $2', [null, selected_row.webhook] ).then( () => {
|
|
return db.query( 'UPDATE rcgcdw SET rcid = $1 WHERE webhook = $2', [null, selected_row.webhook] ).then( () => {
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
- msg.replyMsg( lang.get('rcscript.enabled_rc') + '\n`' + cmd + '`', {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('rcscript.enabled_rc') + '\n`' + cmd + '`', components}, true );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
- msg.replyMsg( lang.get('settings.save_failed'), {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('settings.save_failed'), components}, true );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
|
|
|
|
if ( selected_row.postid === '-1' ) {
|
|
if ( selected_row.postid === '-1' ) {
|
|
- return msg.replyMsg( lang.get('rcscript.all_inactive') + '\n\n' + lang.get('rcscript.delete') + '\n`' + cmd + ' delete`', {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('rcscript.all_inactive') + '\n\n' + lang.get('rcscript.delete') + '\n`' + cmd + ' delete`', components}, true );
|
|
}
|
|
}
|
|
msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
webhook.send( webhook_lang.get('disabled_rc') ).catch(log_error);
|
|
webhook.send( webhook_lang.get('disabled_rc') ).catch(log_error);
|
|
}, log_error );
|
|
}, log_error );
|
|
return db.query( 'UPDATE rcgcdw SET rcid = $1 WHERE webhook = $2', [-1, selected_row.webhook] ).then( () => {
|
|
return db.query( 'UPDATE rcgcdw SET rcid = $1 WHERE webhook = $2', [-1, selected_row.webhook] ).then( () => {
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
- msg.replyMsg( lang.get('rcscript.disabled_rc') + '\n`' + cmd + '`', {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('rcscript.disabled_rc') + '\n`' + cmd + '`', components}, true );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
- msg.replyMsg( lang.get('settings.save_failed'), {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('settings.save_failed'), components}, true );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
|
|
|
|
if ( selected_row.postid !== '-1' ) {
|
|
if ( selected_row.postid !== '-1' ) {
|
|
if ( selected_row.rcid === -1 ) {
|
|
if ( selected_row.rcid === -1 ) {
|
|
- return msg.replyMsg( lang.get('rcscript.all_inactive') + '\n\n' + lang.get('rcscript.delete') + '\n`' + cmd + ' delete`', {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('rcscript.all_inactive') + '\n\n' + lang.get('rcscript.delete') + '\n`' + cmd + ' delete`', components}, true );
|
|
}
|
|
}
|
|
msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
webhook.send( webhook_lang.get('disabled_feeds') ).catch(log_error);
|
|
webhook.send( webhook_lang.get('disabled_feeds') ).catch(log_error);
|
|
}, log_error );
|
|
}, log_error );
|
|
return db.query( 'UPDATE rcgcdw SET postid = $1 WHERE webhook = $2', ['-1', selected_row.webhook] ).then( () => {
|
|
return db.query( 'UPDATE rcgcdw SET postid = $1 WHERE webhook = $2', ['-1', selected_row.webhook] ).then( () => {
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
- msg.replyMsg( lang.get('rcscript.disabled_feeds') + '\n`' + cmd + '`', {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('rcscript.disabled_feeds') + '\n`' + cmd + '`', components}, true );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
- msg.replyMsg( lang.get('settings.save_failed'), {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('settings.save_failed'), components}, true );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
|
|
|
|
@@ -441,7 +429,7 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
if ( dsresponse.statusCode !== 200 || !dsbody || dsbody.status === 404 ) {
|
|
if ( dsresponse.statusCode !== 200 || !dsbody || dsbody.status === 404 ) {
|
|
if ( dsbody?.status !== 404 ) console.log( '- ' + dsresponse.statusCode + ': Error while checking for discussions: ' + dsbody?.title );
|
|
if ( dsbody?.status !== 404 ) console.log( '- ' + dsresponse.statusCode + ': Error while checking for discussions: ' + dsbody?.title );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- return msg.replyMsg( lang.get('rcscript.no_feeds'), {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('rcscript.no_feeds'), components}, true );
|
|
}
|
|
}
|
|
msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
webhook.send( webhook_lang.get('enabled_feeds') + '\n<' + selected_row.wiki + 'f>' ).catch(log_error);
|
|
webhook.send( webhook_lang.get('enabled_feeds') + '\n<' + selected_row.wiki + 'f>' ).catch(log_error);
|
|
@@ -449,21 +437,21 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
db.query( 'UPDATE rcgcdw SET postid = $1 WHERE webhook = $2', [null, selected_row.webhook] ).then( () => {
|
|
db.query( 'UPDATE rcgcdw SET postid = $1 WHERE webhook = $2', [null, selected_row.webhook] ).then( () => {
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
console.log( '- RcGcDw successfully updated.' );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- msg.replyMsg( lang.get('rcscript.enabled_feeds') + '\n`' + cmd + '`', {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('rcscript.enabled_feeds') + '\n`' + cmd + '`', components}, true );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
console.log( '- Error while updating the RcGcDw: ' + dberror );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- msg.replyMsg( lang.get('settings.save_failed'), {components}, true );
|
|
|
|
|
|
+ msg.replyMsg( {content: lang.get('settings.save_failed'), components}, true );
|
|
} );
|
|
} );
|
|
}, error => {
|
|
}, error => {
|
|
console.log( '- Error while checking for discussions: ' + error );
|
|
console.log( '- Error while checking for discussions: ' + error );
|
|
if ( reaction ) reaction.removeEmoji();
|
|
if ( reaction ) reaction.removeEmoji();
|
|
- return msg.replyMsg( lang.get('rcscript.no_feeds'), {components}, true );
|
|
|
|
|
|
+ return msg.replyMsg( {content: lang.get('rcscript.no_feeds'), components}, true );
|
|
} ) );
|
|
} ) );
|
|
}
|
|
}
|
|
|
|
|
|
if ( rows.length > 1 ) return msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
if ( rows.length > 1 ) return msg.client.fetchWebhook(...selected_row.webhook.split('/')).then( webhook => {
|
|
- return webhook.channelID;
|
|
|
|
|
|
+ return webhook.channelId;
|
|
}, error => {
|
|
}, error => {
|
|
log_error(error);
|
|
log_error(error);
|
|
if ( error.name === 'DiscordAPIError' && ['Unknown Webhook', 'Invalid Webhook Token'].includes( error.message ) ) {
|
|
if ( error.name === 'DiscordAPIError' && ['Unknown Webhook', 'Invalid Webhook Token'].includes( error.message ) ) {
|
|
@@ -477,7 +465,7 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
return;
|
|
return;
|
|
} ).then( channel => {
|
|
} ).then( channel => {
|
|
var text = lang.get('rcscript.current_selected', selected_row.configid);
|
|
var text = lang.get('rcscript.current_selected', selected_row.configid);
|
|
- if ( process.env.dashboard ) text += `\n<${button.url}>\n`;
|
|
|
|
|
|
+ if ( button ) text += `\n<${button.url}>\n`;
|
|
text += '\n' + lang.get('rcscript.channel') + ' <#' + channel + '>\n';
|
|
text += '\n' + lang.get('rcscript.channel') + ' <#' + channel + '>\n';
|
|
text += '\n' + lang.get('rcscript.wiki') + ' <' + selected_row.wiki + '>';
|
|
text += '\n' + lang.get('rcscript.wiki') + ' <' + selected_row.wiki + '>';
|
|
text += '\n`' + cmd + ' wiki ' + lang.get('rcscript.new_wiki') + '`\n';
|
|
text += '\n`' + cmd + ' wiki ' + lang.get('rcscript.new_wiki') + '`\n';
|
|
@@ -494,12 +482,12 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
text += '\n' + lang.get('rcscript.help_feeds') + '\n`' + cmd + ' feeds` ' + lang.get('rcscript.toggle') + '\n';
|
|
text += '\n' + lang.get('rcscript.help_feeds') + '\n`' + cmd + ' feeds` ' + lang.get('rcscript.toggle') + '\n';
|
|
}
|
|
}
|
|
text += '\n' + lang.get('rcscript.delete') + '\n`' + cmd + ' delete`\n';
|
|
text += '\n' + lang.get('rcscript.delete') + '\n`' + cmd + ' delete`\n';
|
|
- msg.replyMsg( text, {components}, true );
|
|
|
|
- }, () => msg.replyMsg( lang.get('rcscript.deleted'), {components}, true ) );
|
|
|
|
|
|
+ msg.replyMsg( {content: text, components}, true );
|
|
|
|
+ }, () => msg.replyMsg( {content: lang.get('rcscript.deleted'), components}, true ) );
|
|
}
|
|
}
|
|
|
|
|
|
Promise.all(rows.map( row => msg.client.fetchWebhook(...row.webhook.split('/')).then( webhook => {
|
|
Promise.all(rows.map( row => msg.client.fetchWebhook(...row.webhook.split('/')).then( webhook => {
|
|
- return webhook.channelID;
|
|
|
|
|
|
+ return webhook.channelId;
|
|
}, error => {
|
|
}, error => {
|
|
log_error(error);
|
|
log_error(error);
|
|
if ( error.name === 'DiscordAPIError' && ['Unknown Webhook', 'Invalid Webhook Token'].includes( error.message ) ) {
|
|
if ( error.name === 'DiscordAPIError' && ['Unknown Webhook', 'Invalid Webhook Token'].includes( error.message ) ) {
|
|
@@ -520,7 +508,7 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
var text = '';
|
|
var text = '';
|
|
if ( rows.length ) {
|
|
if ( rows.length ) {
|
|
text += lang.get('rcscript.current');
|
|
text += lang.get('rcscript.current');
|
|
- if ( process.env.dashboard ) text += `\n<${button.url}>`;
|
|
|
|
|
|
+ if ( button ) text += `\n<${button.url}>`;
|
|
text += rows.map( row => {
|
|
text += rows.map( row => {
|
|
var cmd = prefix + 'rcscript' + ( only ? '' : ' ' + row.configid );
|
|
var cmd = prefix + 'rcscript' + ( only ? '' : ' ' + row.configid );
|
|
var row_text = '\n';
|
|
var row_text = '\n';
|
|
@@ -547,10 +535,10 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
text += lang.get('rcscript.missing');
|
|
text += lang.get('rcscript.missing');
|
|
- if ( process.env.dashboard ) text += `\n<${button.url}>`;
|
|
|
|
|
|
+ if ( button ) text += `\n<${button.url}>`;
|
|
}
|
|
}
|
|
if ( rows.length < limit ) text += '\n\n' + lang.get('rcscript.add_more') + '\n`' + prefix + 'rcscript add ' + lang.get('rcscript.new_wiki') + '`';
|
|
if ( rows.length < limit ) text += '\n\n' + lang.get('rcscript.add_more') + '\n`' + prefix + 'rcscript add ' + lang.get('rcscript.new_wiki') + '`';
|
|
- msg.replyMsg( text, {split:true,components}, true );
|
|
|
|
|
|
+ Util.splitMessage( text ).forEach( textpart => msg.replyMsg( {content: textpart, components}, true ) );
|
|
} );
|
|
} );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while getting the RcGcDw: ' + dberror );
|
|
console.log( '- Error while getting the RcGcDw: ' + dberror );
|
|
@@ -564,19 +552,19 @@ function cmd_rcscript(lang, msg, args, line, wiki) {
|
|
* @param {String[]} args - The command arguments.
|
|
* @param {String[]} args - The command arguments.
|
|
*/
|
|
*/
|
|
function blocklist(msg, args) {
|
|
function blocklist(msg, args) {
|
|
- var prefix = ( patreons[msg?.guild?.id] || process.env.prefix );
|
|
|
|
|
|
+ var prefix = ( patreons[msg?.guildId] || process.env.prefix );
|
|
if ( args[0] === 'add' ) {
|
|
if ( args[0] === 'add' ) {
|
|
- if ( !args[1] ) return msg.replyMsg( '`' + prefix + 'rcscript block add <wiki> [<reason>]`', {}, true );
|
|
|
|
- if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, {}, true );
|
|
|
|
|
|
+ if ( !args[1] ) return msg.replyMsg( '`' + prefix + 'rcscript block add <wiki> [<reason>]`', true );
|
|
|
|
+ if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, true );
|
|
let input = args[1].toLowerCase().replace( /^<(.*?)>$/, '$1' );
|
|
let input = args[1].toLowerCase().replace( /^<(.*?)>$/, '$1' );
|
|
let wiki = Wiki.fromInput(input);
|
|
let wiki = Wiki.fromInput(input);
|
|
- if ( !wiki ) return msg.replyMsg( '`' + prefix + 'rcscript block add <wiki> [<reason>]`', {}, true );
|
|
|
|
|
|
+ if ( !wiki ) return msg.replyMsg( '`' + prefix + 'rcscript block add <wiki> [<reason>]`', true );
|
|
let reason = ( args.slice(2).join(' ').trim() || null );
|
|
let reason = ( args.slice(2).join(' ').trim() || null );
|
|
return db.query( 'INSERT INTO blocklist(wiki, reason) VALUES($1, $2)', [wiki.href, reason] ).then( () => {
|
|
return db.query( 'INSERT INTO blocklist(wiki, reason) VALUES($1, $2)', [wiki.href, reason] ).then( () => {
|
|
console.log( '- Successfully added to the blocklist.' );
|
|
console.log( '- Successfully added to the blocklist.' );
|
|
db.query( 'DELETE FROM rcgcdw WHERE wiki = $1 RETURNING webhook, lang', [wiki.href] ).then( ({rows}) => {
|
|
db.query( 'DELETE FROM rcgcdw WHERE wiki = $1 RETURNING webhook, lang', [wiki.href] ).then( ({rows}) => {
|
|
console.log( '- Successfully removed ' + rows.length + ' webhooks.' );
|
|
console.log( '- Successfully removed ' + rows.length + ' webhooks.' );
|
|
- msg.replyMsg( 'I added `' + wiki + '` to the blocklist for `' + reason + '` and removed ' + rows.length + ' webhooks.', {}, true );
|
|
|
|
|
|
+ msg.replyMsg( 'I added `' + wiki + '` to the blocklist for `' + reason + '` and removed ' + rows.length + ' webhooks.', true );
|
|
if ( rows.length ) rows.forEach( row => {
|
|
if ( rows.length ) rows.forEach( row => {
|
|
msg.client.fetchWebhook(...row.webhook.split('/')).then( webhook => {
|
|
msg.client.fetchWebhook(...row.webhook.split('/')).then( webhook => {
|
|
var lang = new Lang(row.lang, 'rcscript.webhook');
|
|
var lang = new Lang(row.lang, 'rcscript.webhook');
|
|
@@ -587,50 +575,50 @@ function blocklist(msg, args) {
|
|
} );
|
|
} );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while removing the webhooks: ' + dberror );
|
|
console.log( '- Error while removing the webhooks: ' + dberror );
|
|
- msg.replyMsg( 'I added `' + wiki + '` to the blocklist for `' + reason + '` but got an error while removing the webhooks: ' + dberror, {}, true );
|
|
|
|
|
|
+ msg.replyMsg( 'I added `' + wiki + '` to the blocklist for `' + reason + '` but got an error while removing the webhooks: ' + dberror, true );
|
|
} );
|
|
} );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
if ( dberror.message === 'duplicate key value violates unique constraint "blocklist_wiki_key"' ) {
|
|
if ( dberror.message === 'duplicate key value violates unique constraint "blocklist_wiki_key"' ) {
|
|
- return msg.replyMsg( '`' + wiki + '` is already on the blocklist.\n`' + prefix + 'rcscript block <' + wiki + '>`', {}, true );
|
|
|
|
|
|
+ return msg.replyMsg( '`' + wiki + '` is already on the blocklist.\n`' + prefix + 'rcscript block <' + wiki + '>`', true );
|
|
}
|
|
}
|
|
console.log( '- Error while adding to the blocklist: ' + dberror );
|
|
console.log( '- Error while adding to the blocklist: ' + dberror );
|
|
- msg.replyMsg( 'I got an error while adding to the blocklist: ' + dberror, {}, true );
|
|
|
|
|
|
+ msg.replyMsg( 'I got an error while adding to the blocklist: ' + dberror, true );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
if ( args[0] === 'remove' ) {
|
|
if ( args[0] === 'remove' ) {
|
|
let input = args.slice(1).join(' ').toLowerCase().trim().replace( /^<\s*(.*?)\s*>$/, '$1' );
|
|
let input = args.slice(1).join(' ').toLowerCase().trim().replace( /^<\s*(.*?)\s*>$/, '$1' );
|
|
let wiki = Wiki.fromInput(input);
|
|
let wiki = Wiki.fromInput(input);
|
|
- if ( !wiki ) return msg.replyMsg( '`' + prefix + 'rcscript block remove <wiki>`', {}, true );
|
|
|
|
- if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, {}, true );
|
|
|
|
|
|
+ if ( !wiki ) return msg.replyMsg( '`' + prefix + 'rcscript block remove <wiki>`', true );
|
|
|
|
+ if ( process.env.READONLY ) return msg.replyMsg( lang.get('general.readonly') + '\n' + process.env.invite, true );
|
|
return db.query( 'DELETE FROM blocklist WHERE wiki = $1', [wiki.href] ).then( ({rowCount}) => {
|
|
return db.query( 'DELETE FROM blocklist WHERE wiki = $1', [wiki.href] ).then( ({rowCount}) => {
|
|
if ( rowCount ) {
|
|
if ( rowCount ) {
|
|
console.log( '- Successfully removed from the blocklist.' );
|
|
console.log( '- Successfully removed from the blocklist.' );
|
|
- msg.replyMsg( 'I removed `' + wiki + '` from the blocklist.', {}, true );
|
|
|
|
|
|
+ msg.replyMsg( 'I removed `' + wiki + '` from the blocklist.', true );
|
|
}
|
|
}
|
|
- else msg.replyMsg( '`' + wiki + '` was not on the blocklist.', {}, true );
|
|
|
|
|
|
+ else msg.replyMsg( '`' + wiki + '` was not on the blocklist.', true );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while removing from the blocklist: ' + dberror );
|
|
console.log( '- Error while removing from the blocklist: ' + dberror );
|
|
- msg.replyMsg( 'I got an error while removing from the blocklist: ' + dberror, {}, true );
|
|
|
|
|
|
+ msg.replyMsg( 'I got an error while removing from the blocklist: ' + dberror, true );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
if ( args.length ) {
|
|
if ( args.length ) {
|
|
let input = args.join(' ').toLowerCase().trim().replace( /^<\s*(.*?)\s*>$/, '$1' );
|
|
let input = args.join(' ').toLowerCase().trim().replace( /^<\s*(.*?)\s*>$/, '$1' );
|
|
let wiki = Wiki.fromInput(input);
|
|
let wiki = Wiki.fromInput(input);
|
|
- if ( !wiki ) return msg.replyMsg( '`' + prefix + 'rcscript block <wiki>`\n`' + prefix + 'rcscript block add <wiki> [<reason>]`\n`' + prefix + 'rcscript block remove <wiki>`', {}, true );
|
|
|
|
|
|
+ if ( !wiki ) return msg.replyMsg( '`' + prefix + 'rcscript block <wiki>`\n`' + prefix + 'rcscript block add <wiki> [<reason>]`\n`' + prefix + 'rcscript block remove <wiki>`', true );
|
|
return db.query( 'SELECT reason FROM blocklist WHERE wiki = $1', [wiki.href] ).then( ({rows:[row]}) => {
|
|
return db.query( 'SELECT reason FROM blocklist WHERE wiki = $1', [wiki.href] ).then( ({rows:[row]}) => {
|
|
- if ( !row ) return msg.replyMsg( '`' + wiki + '` is currently not on the blocklist.\n`' + prefix + 'rcscript block add <' + wiki + '> [<reason>]`', {}, true );
|
|
|
|
- msg.replyMsg( '`' + wiki + '` is currently on the blocklist ' + ( row.reason ? 'for `' + row.reason + '`' : 'with no reason provided' ) + '.\n`' + prefix + 'rcscript block remove <' + wiki + '>`', {}, true );
|
|
|
|
|
|
+ if ( !row ) return msg.replyMsg( '`' + wiki + '` is currently not on the blocklist.\n`' + prefix + 'rcscript block add <' + wiki + '> [<reason>]`', true );
|
|
|
|
+ msg.replyMsg( '`' + wiki + '` is currently on the blocklist ' + ( row.reason ? 'for `' + row.reason + '`' : 'with no reason provided' ) + '.\n`' + prefix + 'rcscript block remove <' + wiki + '>`', true );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while checking the blocklist: ' + dberror );
|
|
console.log( '- Error while checking the blocklist: ' + dberror );
|
|
- msg.replyMsg( 'I got an error while checking the blocklist: ' + dberror, {}, true );
|
|
|
|
|
|
+ msg.replyMsg( 'I got an error while checking the blocklist: ' + dberror, true );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
db.query( 'SELECT wiki, reason FROM blocklist' ).then( ({rows}) => {
|
|
db.query( 'SELECT wiki, reason FROM blocklist' ).then( ({rows}) => {
|
|
- if ( !rows.length ) return msg.replyMsg( 'there are currently no wikis on the blocklist.\n`' + prefix + 'rcscript block add <wiki> [<reason>]`', {}, true );
|
|
|
|
- msg.replyMsg( 'there are currently ' + row.length + ' wikis the blocklist:\n' + rows.map( row => '`' + row.wiki + '` – ' + ( row.reason ? '`' + row.reason + '`' : 'No reason provided.' ) ).join('\n') + '\n`' + prefix + 'rcscript block remove <wiki>`', {split:true}, true );
|
|
|
|
|
|
+ if ( !rows.length ) return msg.replyMsg( 'There are currently no wikis on the blocklist.\n`' + prefix + 'rcscript block add <wiki> [<reason>]`', true );
|
|
|
|
+ Util.splitMessage( 'There are currently ' + row.length + ' wikis the blocklist:\n' + rows.map( row => '`' + row.wiki + '` – ' + ( row.reason ? '`' + row.reason + '`' : 'No reason provided.' ) ).join('\n') + '\n`' + prefix + 'rcscript block remove <wiki>`' ).forEach( textpart => msg.replyMsg( textpart, true ) );
|
|
}, dberror => {
|
|
}, dberror => {
|
|
console.log( '- Error while checking the blocklist: ' + dberror );
|
|
console.log( '- Error while checking the blocklist: ' + dberror );
|
|
- msg.replyMsg( 'I got an error while checking the blocklist: ' + dberror, {}, true );
|
|
|
|
|
|
+ msg.replyMsg( 'I got an error while checking the blocklist: ' + dberror, true );
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
|
|
|