Quellcode durchsuchen

Multiple improvements

close #123
Markus-Rost vor 4 Jahren
Ursprung
Commit
858b660d51
12 geänderte Dateien mit 88 neuen und 81 gelöschten Zeilen
  1. 1 1
      bot.js
  2. 1 1
      cmds/eval.js
  3. 15 10
      cmds/get.js
  4. 5 6
      cmds/patreon.js
  5. 1 1
      cmds/rcscript.js
  6. 2 2
      cmds/wiki/fandom/general.js
  7. 2 5
      cmds/wiki/general.js
  8. 8 9
      cmds/wiki/overview.js
  9. 10 17
      functions/discussion.js
  10. 18 9
      main.js
  11. 22 17
      package-lock.json
  12. 3 3
      package.json

+ 1 - 1
bot.js

@@ -17,7 +17,7 @@ global.got = require('got').extend( {
 	responseType: 'json'
 	responseType: 'json'
 } );
 } );
 
 
-const {defaultSettings, wikiProjects} = require('./util/default.json');
+const {defaultSettings} = require('./util/default.json');
 const Lang = require('./util/i18n.js');
 const Lang = require('./util/i18n.js');
 const newMessage = require('./util/newMessage.js');
 const newMessage = require('./util/newMessage.js');
 global.patreons = {};
 global.patreons = {};

+ 1 - 1
cmds/eval.js

@@ -115,7 +115,7 @@ function checkWiki(wiki) {
 			}, error => {
 			}, error => {
 				result.rcgcdb = error.toString();
 				result.rcgcdb = error.toString();
 			} ),
 			} ),
-			( result.wikiid ? got.get( 'https://services.fandom.com/discussion/' + result.wikiid + '/posts?limit=100&format=json&cache=' + Date.now(), {
+			( wiki.isFandom() ? got.get( wiki + 'wikia.php?controller=DiscussionPost&method=getPosts&limit=100&format=json&cache=' + Date.now(), {
 				headers: {
 				headers: {
 					Accept: 'application/hal+json'
 					Accept: 'application/hal+json'
 				}
 				}

+ 15 - 10
cmds/get.js

@@ -1,4 +1,4 @@
-const {MessageEmbed, Util} = require('discord.js');
+const {MessageEmbed, Util, ShardClientUtil: {shardIDForGuildID}} = require('discord.js');
 const {defaultSettings, defaultPermissions} = require('../util/default.json');
 const {defaultSettings, defaultPermissions} = require('../util/default.json');
 var db = require('../util/database.js');
 var db = require('../util/database.js');
 
 
@@ -24,7 +24,7 @@ async function cmd_get(lang, msg, args, line, wiki) {
 				pause: guild.id in global.pause, voice: guild.id in global.voice,
 				pause: guild.id in global.pause, voice: guild.id in global.voice,
 				shardId: global.shardId
 				shardId: global.shardId
 			} )
 			} )
-		}` ).then( results => results.find( result => result !== null ) );
+		}`, shardIDForGuildID(id, msg.client.shard.count) );
 		if ( guild ) {
 		if ( guild ) {
 			var guildname = ['Guild:', guild.name.escapeFormatting() + ' `' + guild.id + '`' + ( guild.pause ? '\\*' : '' )];
 			var guildname = ['Guild:', guild.name.escapeFormatting() + ' `' + guild.id + '`' + ( guild.pause ? '\\*' : '' )];
 			var guildowner = ['Owner:', ( guild.owner ? guild.owner.escapeFormatting() + ' ' : '' ) + '`' + guild.ownerID + '` <@' + guild.ownerID + '>'];
 			var guildowner = ['Owner:', ( guild.owner ? guild.owner.escapeFormatting() + ' ' : '' ) + '`' + guild.ownerID + '` <@' + guild.ownerID + '>'];
@@ -34,7 +34,7 @@ async function cmd_get(lang, msg, args, line, wiki) {
 			var guildchannel = ['Updates channel:', '`' + guild.channel + '`'];
 			var guildchannel = ['Updates channel:', '`' + guild.channel + '`'];
 			var guildsettings = ['Settings:', '*unknown*'];
 			var guildsettings = ['Settings:', '*unknown*'];
 			
 			
-			return db.all( 'SELECT channel, prefix, lang, wiki, inline FROM discord WHERE guild = ? ORDER BY channel ASC', [guild.id], (dberror, rows) => {
+			return db.all( 'SELECT channel, wiki, lang, role, inline, prefix FROM discord WHERE guild = ? ORDER BY channel ASC', [guild.id], (dberror, rows) => {
 				if ( dberror ) {
 				if ( dberror ) {
 					console.log( '- Error while getting the settings: ' + dberror );
 					console.log( '- Error while getting the settings: ' + dberror );
 				}
 				}
@@ -74,37 +74,40 @@ async function cmd_get(lang, msg, args, line, wiki) {
 				pause: guildID in global.pause,
 				pause: guildID in global.pause,
 				shardId: global.shardId
 				shardId: global.shardId
 			} )
 			} )
-		}` ).then( results => results.find( result => result !== null ) );
+		}` ).then( results => results.find( result => result ) );
 		if ( channel ) {
 		if ( channel ) {
 			var channelguild = ['Guild:', channel.guild.escapeFormatting() + ' `' + channel.guildID + '`' + ( channel.pause ? '\\*' : '' )];
 			var channelguild = ['Guild:', channel.guild.escapeFormatting() + ' `' + channel.guildID + '`' + ( channel.pause ? '\\*' : '' )];
 			var channelname = ['Channel:', '#' + channel.name.escapeFormatting() + ' `' + channel.id + '` <#' + channel.id + '>'];
 			var channelname = ['Channel:', '#' + channel.name.escapeFormatting() + ' `' + channel.id + '` <#' + channel.id + '>'];
 			var channelpermissions = ['Missing permissions:', ( channel.permissions.length ? '`' + channel.permissions.join('`, `') + '`' : '*none*' )];
 			var channelpermissions = ['Missing permissions:', ( channel.permissions.length ? '`' + channel.permissions.join('`, `') + '`' : '*none*' )];
 			var channellang = ['Language:', '*unknown*'];
 			var channellang = ['Language:', '*unknown*'];
 			var channelwiki = ['Default Wiki:', '*unknown*'];
 			var channelwiki = ['Default Wiki:', '*unknown*'];
+			var channelrole = ['Minimal Role:', '*unknown*'];
 			var channelinline = ['Inline commands:', '*unknown*'];
 			var channelinline = ['Inline commands:', '*unknown*'];
 			
 			
-			return db.get( 'SELECT lang, wiki, inline FROM discord WHERE guild = ? AND (channel = ? OR channel IS NULL) ORDER BY channel DESC', [channel.guildID, channel.id], (dberror, row) => {
+			return db.get( 'SELECT wiki, lang, role, inline FROM discord WHERE guild = ? AND (channel = ? OR channel IS NULL) ORDER BY channel DESC', [channel.guildID, channel.id], (dberror, row) => {
 				if ( dberror ) {
 				if ( dberror ) {
 					console.log( '- Error while getting the settings: ' + dberror );
 					console.log( '- Error while getting the settings: ' + dberror );
 				}
 				}
 				else if ( row ) {
 				else if ( row ) {
 					channellang[1] = row.lang;
 					channellang[1] = row.lang;
 					channelwiki[1] = row.wiki;
 					channelwiki[1] = row.wiki;
+					channelrole[1] = row.role;
 					channelinline[1] = ( row.inline ? 'disabled' : 'enabled' );
 					channelinline[1] = ( row.inline ? 'disabled' : 'enabled' );
 				}
 				}
 				else {
 				else {
 					channellang[1] = defaultSettings.lang;
 					channellang[1] = defaultSettings.lang;
 					channelwiki[1] = defaultSettings.wiki;
 					channelwiki[1] = defaultSettings.wiki;
+					channelrole[1] = null;
 					channelinline[1] = 'enabled';
 					channelinline[1] = 'enabled';
 				}
 				}
 				
 				
 				if ( msg.showEmbed() ) {
 				if ( msg.showEmbed() ) {
 					var text = '';
 					var text = '';
-					var embed = new MessageEmbed().addField( channelguild[0], channelguild[1] ).addField( channelname[0], channelname[1] ).addField( channelpermissions[0], channelpermissions[1] ).addField( channellang[0], channellang[1] ).addField( channelwiki[0], channelwiki[1] ).addField( channelinline[0], channelinline[1] );
+					var embed = new MessageEmbed().addField( channelguild[0], channelguild[1] ).addField( channelname[0], channelname[1] ).addField( channelpermissions[0], channelpermissions[1] ).addField( channellang[0], channellang[1] ).addField( channelwiki[0], channelwiki[1] ).addField( channelrole[0], channelrole[1] ).addField( channelinline[0], channelinline[1] );
 				}
 				}
 				else {
 				else {
 					var embed = {};
 					var embed = {};
-					var text = channelguild.join(' ') + '\n' + channelname.join(' ') + '\n' + channelpermissions.join(' ') + '\n' + channellang.join(' ') + '\n' + channelwiki[0] + ' <' + channelwiki[1] + '>\n' + channelinline.join(' ');
+					var text = channelguild.join(' ') + '\n' + channelname.join(' ') + '\n' + channelpermissions.join(' ') + '\n' + channellang.join(' ') + '\n' + channelwiki[0] + ' <' + channelwiki[1] + '>\n' + channelrole.join(' ') + '\n' + channelinline.join(' ');
 				}
 				}
 				msg.sendChannel( text, {embed}, true );
 				msg.sendChannel( text, {embed}, true );
 			} );
 			} );
@@ -122,9 +125,11 @@ async function cmd_get(lang, msg, args, line, wiki) {
 					isAdmin: member.permissions.has('MANAGE_GUILD'),
 					isAdmin: member.permissions.has('MANAGE_GUILD'),
 					shardId: global.shardId
 					shardId: global.shardId
 				}
 				}
-			} )` ).then( results => results.reduce( (acc, val) => acc.concat(val), [] ).map( user_guild => {
-				return user_guild.name.escapeFormatting() + ' `' + user_guild.id + '`' + ( user_guild.isAdmin ? '\\*' : '' );
-			} ) );
+			} )` ).then( results => {
+				return results.reduce( (acc, val) => acc.concat(val), [] ).map( user_guild => {
+					return user_guild.name.escapeFormatting() + ' `' + user_guild.id + '`' + ( user_guild.isAdmin ? '\\*' : '' );
+				} );
+			} );
 			if ( guilds.length ) guildlist[1] = guilds.join('\n');
 			if ( guilds.length ) guildlist[1] = guilds.join('\n');
 			if ( guildlist[1].length > 1000 ) guildlist[1] = guilds.length;
 			if ( guildlist[1].length > 1000 ) guildlist[1] = guilds.length;
 			if ( msg.showEmbed() ) {
 			if ( msg.showEmbed() ) {

+ 5 - 6
cmds/patreon.js

@@ -1,3 +1,4 @@
+const {ShardClientUtil: {shardIDForGuildID}} = require('discord.js');
 const {defaultPermissions, limit: {verification: verificationLimit, rcgcdw: rcgcdwLimit}} = require('../util/default.json');
 const {defaultPermissions, limit: {verification: verificationLimit, rcgcdw: rcgcdwLimit}} = require('../util/default.json');
 var db = require('../util/database.js');
 var db = require('../util/database.js');
 
 
@@ -15,9 +16,8 @@ function cmd_patreon(lang, msg, args, line, wiki) {
 		return;
 		return;
 	}
 	}
 	
 	
-	if ( args[0] === 'enable' && /^\d+$/.test(args.slice(1).join(' ')) ) return msg.client.shard.broadcastEval( `this.guilds.cache.get('${args[1]}')?.name` ).then( results => {
-		var guild = results.find( result => result !== null );
-		if ( guild === undefined ) return msg.client.generateInvite({
+	if ( args[0] === 'enable' && /^\d+$/.test(args.slice(1).join(' ')) ) return msg.client.shard.broadcastEval( `this.guilds.cache.get('${args[1]}')?.name`, shardIDForGuildID(args[1], msg.client.shard.count) ).then( guild => {
+		if ( !guild ) return msg.client.generateInvite({
 			permissions: defaultPermissions,
 			permissions: defaultPermissions,
 			guild: args[1]
 			guild: args[1]
 		}).then( invite => {
 		}).then( invite => {
@@ -56,9 +56,8 @@ function cmd_patreon(lang, msg, args, line, wiki) {
 		} );
 		} );
 	} );
 	} );
 	
 	
-	if ( args[0] === 'disable' && /^\d+$/.test(args.slice(1).join(' ')) ) return msg.client.shard.broadcastEval( `this.guilds.cache.get('${args[1]}')?.name` ).then( results => {
-		var guild = results.find( result => result !== null );
-		if ( guild === undefined ) return msg.replyMsg( 'I\'m not on a server with the id `' + args[1] + '`.', {}, true );
+	if ( args[0] === 'disable' && /^\d+$/.test(args.slice(1).join(' ')) ) return msg.client.shard.broadcastEval( `this.guilds.cache.get('${args[1]}')?.name`, shardIDForGuildID(args[1], msg.client.shard.count) ).then( guild => {
+		if ( !guild ) return msg.replyMsg( 'I\'m not on a server with the id `' + args[1] + '`.', {}, true );
 		if ( !( args[1] in patreons ) ) return msg.replyMsg( '"' + guild + '" doesn\'t have the patreon features enabled.', {}, true );
 		if ( !( args[1] in patreons ) ) return msg.replyMsg( '"' + guild + '" doesn\'t have the patreon features enabled.', {}, true );
 		db.get( 'SELECT lang, inline FROM discord WHERE guild = ? AND patreon = ?', [args[1], msg.author.id], (dberror, row) => {
 		db.get( 'SELECT lang, inline FROM discord WHERE guild = ? AND patreon = ?', [args[1], msg.author.id], (dberror, row) => {
 			if ( dberror ) {
 			if ( dberror ) {

+ 1 - 1
cmds/rcscript.js

@@ -573,7 +573,7 @@ function blocklist(msg, args) {
 				if ( dberror ) return dberror;
 				if ( dberror ) return dberror;
 				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');
-					webhook.send( '**' + ( reason ? lang.get('blocked_reason', reason) : lang.get('blocked') ) + '**' ).catch(log_error).finally( () => {
+					webhook.send( '**' + ( reason ? lang.get('blocked_reason', reason) : lang.get('blocked') ) + '**\n' + lang.get('blocked_help', `<${process.env.invite}>`) ).catch(log_error).finally( () => {
 						webhook.delete().catch(log_error);
 						webhook.delete().catch(log_error);
 					} );
 					} );
 				}, log_error );
 				}, log_error );

+ 2 - 2
cmds/wiki/fandom/general.js

@@ -69,7 +69,7 @@ function fandom_check_wiki(lang, msg, title, wiki, cmd, reaction, spoiler = '',
 		return fn.diff(lang, msg, args, wiki, reaction, spoiler);
 		return fn.diff(lang, msg, args, wiki, reaction, spoiler);
 	}
 	}
 	var noRedirect = ( querystring.getAll('redirect').pop() === 'no' || ( querystring.has('action') && querystring.getAll('action').pop() !== 'view' ) );
 	var noRedirect = ( querystring.getAll('redirect').pop() === 'no' || ( querystring.has('action') && querystring.getAll('action').pop() !== 'view' ) );
-	got.get( wiki + 'api.php?action=query&meta=allmessages|siteinfo&ammessages=description&amenableparser=true&siprop=general|namespaces|specialpagealiases|wikidesc&iwurl=true' + ( noRedirect ? '' : '&redirects=true' ) + '&prop=imageinfo|categoryinfo&converttitles=true&titles=' + encodeURIComponent( title.replace( /\|/g, '\ufffd' ) ) + '&format=json' ).then( response => {
+	got.get( wiki + 'api.php?action=query&meta=allmessages|siteinfo&ammessages=description&amenableparser=true&siprop=general|namespaces|specialpagealiases&iwurl=true' + ( noRedirect ? '' : '&redirects=true' ) + '&prop=imageinfo|categoryinfo&converttitles=true&titles=' + encodeURIComponent( title.replace( /\|/g, '\ufffd' ) ) + '&format=json' ).then( response => {
 		var body = response.body;
 		var body = response.body;
 		if ( body && body.warnings ) log_warn(body.warnings);
 		if ( body && body.warnings ) log_warn(body.warnings);
 		if ( response.statusCode !== 200 || !body || !body.query ) {
 		if ( response.statusCode !== 200 || !body || !body.query ) {
@@ -91,7 +91,7 @@ function fandom_check_wiki(lang, msg, title, wiki, cmd, reaction, spoiler = '',
 			return fn.search(lang, msg, full_title.split(' ').slice(1).join(' '), wiki, body.query, reaction, spoiler);
 			return fn.search(lang, msg, full_title.split(' ').slice(1).join(' '), wiki, body.query, reaction, spoiler);
 		}
 		}
 		if ( aliasInvoke === 'discussion' && !querystring.toString() && !fragment ) {
 		if ( aliasInvoke === 'discussion' && !querystring.toString() && !fragment ) {
-			return fn.discussion(lang, msg, wiki, args.join(' '), body.query, reaction, spoiler);
+			return fn.discussion(lang, msg, wiki, args.join(' '), body.query.general.sitename, reaction, spoiler);
 		}
 		}
 		if ( body.query.pages ) {
 		if ( body.query.pages ) {
 			var querypages = Object.values(body.query.pages);
 			var querypages = Object.values(body.query.pages);

+ 2 - 5
cmds/wiki/general.js

@@ -85,7 +85,7 @@ function gamepedia_check_wiki(lang, msg, title, wiki, cmd, reaction, spoiler = '
 		return fn.diff(lang, msg, args, wiki, reaction, spoiler);
 		return fn.diff(lang, msg, args, wiki, reaction, spoiler);
 	}
 	}
 	var noRedirect = ( querystring.getAll('redirect').pop() === 'no' || ( querystring.has('action') && querystring.getAll('action').pop() !== 'view' ) );
 	var noRedirect = ( querystring.getAll('redirect').pop() === 'no' || ( querystring.has('action') && querystring.getAll('action').pop() !== 'view' ) );
-	got.get( wiki + 'api.php?action=query&meta=siteinfo&siprop=general|namespaces|specialpagealiases' + ( wiki.isFandom() ? '|variables' : '' ) + '&iwurl=true' + ( noRedirect ? '' : '&redirects=true' ) + '&prop=pageimages|categoryinfo|pageprops|extracts&piprop=original|name&ppprop=description|displaytitle|page_image_free|infoboxes&explaintext=true&exsectionformat=raw&exlimit=1&converttitles=true&titles=%1F' + encodeURIComponent( title.replace( /\x1F/g, '\ufffd' ) ) + '&format=json' ).then( response => {
+	got.get( wiki + 'api.php?action=query&meta=siteinfo&siprop=general|namespaces|specialpagealiases&iwurl=true' + ( noRedirect ? '' : '&redirects=true' ) + '&prop=pageimages|categoryinfo|pageprops|extracts&piprop=original|name&ppprop=description|displaytitle|page_image_free|infoboxes&explaintext=true&exsectionformat=raw&exlimit=1&converttitles=true&titles=%1F' + encodeURIComponent( title.replace( /\x1F/g, '\ufffd' ) ) + '&format=json' ).then( response => {
 		var body = response.body;
 		var body = response.body;
 		if ( body && body.warnings ) log_warn(body.warnings);
 		if ( body && body.warnings ) log_warn(body.warnings);
 		if ( response.statusCode !== 200 || !body || body.batchcomplete === undefined || !body.query ) {
 		if ( response.statusCode !== 200 || !body || body.batchcomplete === undefined || !body.query ) {
@@ -113,10 +113,7 @@ function gamepedia_check_wiki(lang, msg, title, wiki, cmd, reaction, spoiler = '
 			return fn.diff(lang, msg, args, wiki, reaction, spoiler);
 			return fn.diff(lang, msg, args, wiki, reaction, spoiler);
 		}
 		}
 		if ( aliasInvoke === 'discussion' && wiki.isFandom(false) && !querystring.toString() && !fragment ) {
 		if ( aliasInvoke === 'discussion' && wiki.isFandom(false) && !querystring.toString() && !fragment ) {
-			body.query.wikidesc = {
-				id: body.query.variables?.find?.( variable => variable?.id === 'wgCityId' )?.['*']
-			};
-			return fn.discussion(lang, msg, wiki, args.join(' '), body.query, reaction, spoiler);
+			return fn.discussion(lang, msg, wiki, args.join(' '), body.query.general.sitename, reaction, spoiler);
 		}
 		}
 		if ( body.query.pages ) {
 		if ( body.query.pages ) {
 			var querypages = Object.values(body.query.pages);
 			var querypages = Object.values(body.query.pages);

+ 8 - 9
cmds/wiki/overview.js

@@ -170,7 +170,7 @@ function gamepedia_overview(lang, msg, wiki, reaction, spoiler) {
 							console.log( '- Error while getting the wiki founder: ' + error );
 							console.log( '- Error while getting the wiki founder: ' + error );
 							founder[1] = 'ID: ' + founder[1];
 							founder[1] = 'ID: ' + founder[1];
 						} ) : founder[1] = ( wiki.isGamepedia() ? null : lang.get('overview.none') ) ),
 						} ) : founder[1] = ( wiki.isGamepedia() ? null : lang.get('overview.none') ) ),
-						got.get( 'https://services.fandom.com/discussion/' + wikiid + '/posts?limit=1&format=json&cache=' + Date.now(), {
+						got.get( wiki + 'wikia.php?controller=DiscussionPost&method=getPosts&limit=1&format=json&cache=' + Date.now(), {
 							headers: {
 							headers: {
 								Accept: 'application/hal+json'
 								Accept: 'application/hal+json'
 							}
 							}
@@ -178,16 +178,15 @@ function gamepedia_overview(lang, msg, wiki, reaction, spoiler) {
 							var dsbody = dsresponse.body;
 							var dsbody = dsresponse.body;
 							if ( dsresponse.statusCode !== 200 || !dsbody || dsbody.title ) {
 							if ( dsresponse.statusCode !== 200 || !dsbody || dsbody.title ) {
 								if ( dsbody?.title !== 'site doesn\'t exists' ) console.log( '- ' + dsresponse.statusCode + ': Error while getting discussions stats: ' + dsbody?.title );
 								if ( dsbody?.title !== 'site doesn\'t exists' ) console.log( '- ' + dsresponse.statusCode + ': Error while getting discussions stats: ' + dsbody?.title );
+								return;
 							}
 							}
-							else {
-								let counts = dsbody?._embedded?.count?.[0];
-								if ( counts?.FORUM || counts?.WALL || counts?.ARTICLE_COMMENT ) {
-									if ( counts?.FORUM ) posts.push(counts.FORUM);
-									if ( counts?.WALL ) walls.push(counts.WALL);
-									if ( counts?.ARTICLE_COMMENT ) comments.push(counts.ARTICLE_COMMENT);
-								}
-								else if ( counts?.total ) posts.push(counts.total);
+							let counts = dsbody?._embedded?.count?.[0];
+							if ( counts?.FORUM || counts?.WALL || counts?.ARTICLE_COMMENT ) {
+								if ( counts?.FORUM ) posts.push(counts.FORUM);
+								if ( counts?.WALL ) walls.push(counts.WALL);
+								if ( counts?.ARTICLE_COMMENT ) comments.push(counts.ARTICLE_COMMENT);
 							}
 							}
+							else if ( counts?.total ) posts.push(counts.total);
 						}, error => {
 						}, error => {
 							console.log( '- Error while getting discussions stats: ' + error );
 							console.log( '- Error while getting discussions stats: ' + error );
 						} )
 						} )

+ 10 - 17
functions/discussion.js

@@ -8,15 +8,15 @@ const {limit: {discussion: discussionLimit}} = require('../util/default.json');
  * @param {import('discord.js').Message} msg - The Discord message.
  * @param {import('discord.js').Message} msg - The Discord message.
  * @param {import('../util/wiki.js')} wiki - The wiki for the page.
  * @param {import('../util/wiki.js')} wiki - The wiki for the page.
  * @param {String} title - The title of the discussion post.
  * @param {String} title - The title of the discussion post.
- * @param {Object} query - The siteinfo from the wiki.
+ * @param {String} sitename - The sitename of the wiki.
  * @param {import('discord.js').MessageReaction} reaction - The reaction on the message.
  * @param {import('discord.js').MessageReaction} reaction - The reaction on the message.
  * @param {String} spoiler - If the response is in a spoiler.
  * @param {String} spoiler - If the response is in a spoiler.
  */
  */
-function fandom_discussion(lang, msg, wiki, title, query, reaction, spoiler) {
+function fandom_discussion(lang, msg, wiki, title, sitename, reaction, spoiler) {
 	var limit = discussionLimit[( msg?.guild?.id in patreons ? 'patreon' : 'default' )];
 	var limit = discussionLimit[( msg?.guild?.id in patreons ? 'patreon' : 'default' )];
 	if ( !title ) {
 	if ( !title ) {
 		var pagelink = wiki + 'f';
 		var pagelink = wiki + 'f';
-		var embed = new MessageEmbed().setAuthor( query.general.sitename ).setTitle( lang.get('discussion.main') ).setURL( pagelink );
+		var embed = new MessageEmbed().setAuthor( sitename ).setTitle( lang.get('discussion.main') ).setURL( pagelink );
 		got.get( wiki + 'f', {
 		got.get( wiki + 'f', {
 			responseType: 'text'
 			responseType: 'text'
 		} ).then( descresponse => {
 		} ).then( descresponse => {
@@ -49,16 +49,9 @@ function fandom_discussion(lang, msg, wiki, title, query, reaction, spoiler) {
 			if ( reaction ) reaction.removeEmoji();
 			if ( reaction ) reaction.removeEmoji();
 		} );
 		} );
 	}
 	}
-	else if ( !query.wikidesc?.id ) {
-		console.log( '- Error while getting the wiki id.' );
-		msg.sendChannelError( spoiler + '<' + wiki + 'f' + '>' + spoiler );
-		
-		if ( reaction ) reaction.removeEmoji();
-		return;
-	}
 	else if ( title.split(' ')[0].toLowerCase() === 'post' || title.split(' ')[0].toLowerCase() === lang.get('discussion.post') ) {
 	else if ( title.split(' ')[0].toLowerCase() === 'post' || title.split(' ')[0].toLowerCase() === lang.get('discussion.post') ) {
 		title = title.split(' ').slice(1).join(' ');
 		title = title.split(' ').slice(1).join(' ');
-		got.get( 'https://services.fandom.com/discussion/' + query.wikidesc.id + '/posts?limit=' + limit + '&format=json&cache=' + Date.now(), {
+		got.get( wiki + 'wikia.php?controller=DiscussionPost&method=getPosts&limit=' + limit + '&format=json&cache=' + Date.now(), {
 			headers: {
 			headers: {
 				Accept: 'application/hal+json'
 				Accept: 'application/hal+json'
 			}
 			}
@@ -72,7 +65,7 @@ function fandom_discussion(lang, msg, wiki, title, query, reaction, spoiler) {
 			}
 			}
 			else if ( body._embedded['doc:posts'].length ) {
 			else if ( body._embedded['doc:posts'].length ) {
 				var posts = body._embedded['doc:posts'];
 				var posts = body._embedded['doc:posts'];
-				var embed = new MessageEmbed().setAuthor( query.general.sitename );
+				var embed = new MessageEmbed().setAuthor( sitename );
 				
 				
 				if ( posts.some( post => post.id === title ) ) {
 				if ( posts.some( post => post.id === title ) ) {
 					discussion_send(lang, msg, wiki, posts.find( post => post.id === title ), embed, spoiler);
 					discussion_send(lang, msg, wiki, posts.find( post => post.id === title ), embed, spoiler);
@@ -80,7 +73,7 @@ function fandom_discussion(lang, msg, wiki, title, query, reaction, spoiler) {
 					if ( reaction ) reaction.removeEmoji();
 					if ( reaction ) reaction.removeEmoji();
 				}
 				}
 				else if ( /^\d+$/.test(title) ) {
 				else if ( /^\d+$/.test(title) ) {
-					got.get( 'https://services.fandom.com/discussion/' + query.wikidesc.id + '/posts/' + title + '?format=json&cache=' + Date.now(), {
+					got.get( wiki + 'wikia.php?controller=DiscussionPost&method=getPost&postId=' + title + '&format=json&cache=' + Date.now(), {
 						headers: {
 						headers: {
 							Accept: 'application/hal+json'
 							Accept: 'application/hal+json'
 						}
 						}
@@ -105,7 +98,7 @@ function fandom_discussion(lang, msg, wiki, title, query, reaction, spoiler) {
 							
 							
 							if ( reaction ) reaction.removeEmoji();
 							if ( reaction ) reaction.removeEmoji();
 						}
 						}
-						else got.get( 'https://services.fandom.com/discussion/' + query.wikidesc.id + '/threads/' + pbody.threadId + '?format=json&cache=' + Date.now(), {
+						else got.get( wiki + 'wikia.php?controller=DiscussionThread&method=getThread&threadId=' + pbody.threadId + '&format=json&cache=' + Date.now(), {
 							headers: {
 							headers: {
 								Accept: 'application/hal+json'
 								Accept: 'application/hal+json'
 							}
 							}
@@ -155,7 +148,7 @@ function fandom_discussion(lang, msg, wiki, title, query, reaction, spoiler) {
 		} );
 		} );
 	}
 	}
 	else {
 	else {
-		got.get( 'https://services.fandom.com/discussion/' + query.wikidesc.id + '/threads?sortKey=trending&limit=' + limit + '&format=json&cache=' + Date.now(), {
+		got.get( wiki + 'wikia.php?controller=DiscussionThread&method=getThreads&sortKey=trending&limit=' + limit + '&format=json&cache=' + Date.now(), {
 			headers: {
 			headers: {
 				Accept: 'application/hal+json'
 				Accept: 'application/hal+json'
 			}
 			}
@@ -169,7 +162,7 @@ function fandom_discussion(lang, msg, wiki, title, query, reaction, spoiler) {
 			}
 			}
 			else if ( body._embedded.threads.length ) {
 			else if ( body._embedded.threads.length ) {
 				var threads = body._embedded.threads;
 				var threads = body._embedded.threads;
-				var embed = new MessageEmbed().setAuthor( query.general.sitename );
+				var embed = new MessageEmbed().setAuthor( sitename );
 				
 				
 				if ( threads.some( thread => thread.id === title ) ) {
 				if ( threads.some( thread => thread.id === title ) ) {
 					discussion_send(lang, msg, wiki, threads.find( thread => thread.id === title ), embed, spoiler);
 					discussion_send(lang, msg, wiki, threads.find( thread => thread.id === title ), embed, spoiler);
@@ -197,7 +190,7 @@ function fandom_discussion(lang, msg, wiki, title, query, reaction, spoiler) {
 					if ( reaction ) reaction.removeEmoji();
 					if ( reaction ) reaction.removeEmoji();
 				}
 				}
 				else if ( /^\d+$/.test(title) ) {
 				else if ( /^\d+$/.test(title) ) {
-					got.get( 'https://services.fandom.com/discussion/' + query.wikidesc.id + '/threads/' + title + '?format=json&cache=' + Date.now(), {
+					got.get( wiki + 'wikia.php?controller=DiscussionThread&method=getThread&threadId=' + title + '&format=json&cache=' + Date.now(), {
 						headers: {
 						headers: {
 							Accept: 'application/hal+json'
 							Accept: 'application/hal+json'
 						}
 						}

+ 18 - 9
main.js

@@ -15,7 +15,7 @@ const got = require('got').extend( {
 	},
 	},
 	responseType: 'json'
 	responseType: 'json'
 } );
 } );
-const {ShardingManager} = require('discord.js');
+const {ShardingManager, ShardClientUtil: {shardIDForGuildID}} = require('discord.js');
 const manager = new ShardingManager( './bot.js', {
 const manager = new ShardingManager( './bot.js', {
 	execArgv: ['--icu-data-dir=node_modules/full-icu'],
 	execArgv: ['--icu-data-dir=node_modules/full-icu'],
 	shardArgs: ( isDebug ? ['debug'] : [] ),
 	shardArgs: ( isDebug ? ['debug'] : [] ),
@@ -94,13 +94,22 @@ if ( process.env.dashboard ) {
 										patreon: guild.id in global.patreons,
 										patreon: guild.id in global.patreons,
 										botPermissions: guild.me.permissions.bitfield,
 										botPermissions: guild.me.permissions.bitfield,
 										channels: guild.channels.cache.filter( channel => {
 										channels: guild.channels.cache.filter( channel => {
-											return channel.isGuild();
+											return ( channel.isGuild() || channel.type === 'category' );
 										} ).sort( (a, b) => {
 										} ).sort( (a, b) => {
-											return a.rawPosition - b.rawPosition;
+											let aVal = a.rawPosition + 1;
+											if ( a.type === 'category' ) aVal *= 1000;
+											else if ( !a.parent ) aVal -= 1000;
+											else aVal += ( a.parent.rawPosition + 1 ) * 1000;
+											let bVal = b.rawPosition + 1;
+											if ( b.type === 'category' ) bVal *= 1000;
+											else if ( !b.parent ) bVal -= 1000;
+											else bVal += ( b.parent.rawPosition + 1 ) * 1000;
+											return aVal - bVal;
 										} ).map( channel => {
 										} ).map( channel => {
 											return {
 											return {
 												id: channel.id,
 												id: channel.id,
 												name: channel.name,
 												name: channel.name,
+												isCategory: ( channel.type === 'category' ),
 												userPermissions: member.permissionsIn(channel).bitfield,
 												userPermissions: member.permissionsIn(channel).bitfield,
 												botPermissions: guild.me.permissionsIn(channel).bitfield
 												botPermissions: guild.me.permissionsIn(channel).bitfield
 											};
 											};
@@ -161,8 +170,8 @@ if ( process.env.dashboard ) {
 						}, error => {
 						}, error => {
 							return 'noMember';
 							return 'noMember';
 						} );
 						} );
-					}`).then( results => {
-						data.response = results.find( result => result );
+					}`, shardIDForGuildID(message.data.guild, manager.totalShards)).then( result => {
+						data.response = result;
 					}, error => {
 					}, error => {
 						data.error = error.toString();
 						data.error = error.toString();
 					} ).finally( () => {
 					} ).finally( () => {
@@ -202,8 +211,8 @@ if ( process.env.dashboard ) {
 						}, error => {
 						}, error => {
 							console.log( '- Dashboard: Error while creating the webhook: ' + error );
 							console.log( '- Dashboard: Error while creating the webhook: ' + error );
 						} );
 						} );
-					}`).then( results => {
-						data.response = results.find( result => result );
+					}`, shardIDForGuildID(message.data.guild, manager.totalShards)).then( result => {
+						data.response = result;
 					}, error => {
 					}, error => {
 						data.error = error.toString();
 						data.error = error.toString();
 					} ).finally( () => {
 					} ).finally( () => {
@@ -225,8 +234,8 @@ if ( process.env.dashboard ) {
 						}, error => {
 						}, error => {
 							console.log( '- Dashboard: Error while moving the webhook: ' + error );
 							console.log( '- Dashboard: Error while moving the webhook: ' + error );
 						} );
 						} );
-					}`).then( results => {
-						data.response = results.find( result => result );
+					}`, shardIDForGuildID(message.data.guild, manager.totalShards)).then( result => {
+						data.response = result;
 					}, error => {
 					}, error => {
 						data.error = error.toString();
 						data.error = error.toString();
 					} ).finally( () => {
 					} ).finally( () => {

+ 22 - 17
package-lock.json

@@ -387,14 +387,14 @@
       "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups="
       "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups="
     },
     },
     "discord-oauth2": {
     "discord-oauth2": {
-      "version": "2.5.0",
-      "resolved": "https://registry.npmjs.org/discord-oauth2/-/discord-oauth2-2.5.0.tgz",
-      "integrity": "sha512-CFbc2jtALlzbsNw8yBxBWWQUxVAUqa3+8ZbhD0Vrrlj+9mh3PC5Itn7r4ibndwUCTYLKPcVKDAgLEL2WdYdSAQ=="
+      "version": "2.6.0",
+      "resolved": "https://registry.npmjs.org/discord-oauth2/-/discord-oauth2-2.6.0.tgz",
+      "integrity": "sha512-9lEt1Rp9rruFPiVQOPbe2rKJXB40fO2u9Ozjz3n/TlVYnIxCTeohVkNI/c5AoLFDZcSxFc2MtDTf9iG0X7BkRg=="
     },
     },
     "discord.js": {
     "discord.js": {
-      "version": "12.4.1",
-      "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.4.1.tgz",
-      "integrity": "sha512-KxOB8LOAN3GmrvkD6a6Fr1nlfArIFZ+q7Uqg4T/5duB90GZy9a0/Py2E+Y+eHKP6ZUCR2mbNMLCcHGjahiaNqA==",
+      "version": "12.5.0",
+      "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.0.tgz",
+      "integrity": "sha512-MXZcnBIosHEOX26ipWEcZdUrTyfTbb4sDYYp0Go5N05PyI78LR8Ds7yAfMu0zUDmxFHYLSYX0pCdiO2pd4CP6w==",
       "requires": {
       "requires": {
         "@discordjs/collection": "^0.1.6",
         "@discordjs/collection": "^0.1.6",
         "@discordjs/form-data": "^3.0.1",
         "@discordjs/form-data": "^3.0.1",
@@ -990,14 +990,14 @@
       "integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ=="
       "integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ=="
     },
     },
     "npm": {
     "npm": {
-      "version": "7.0.9",
-      "resolved": "https://registry.npmjs.org/npm/-/npm-7.0.9.tgz",
-      "integrity": "sha512-r+omObVoL4OXyY4A4BVO90A6XpKFQ7xPO8Jf1vOHq2mMwJu07F/waPGfyo377NiDvah8Cr0smUTpmbGCRjFIMA==",
+      "version": "7.0.13",
+      "resolved": "https://registry.npmjs.org/npm/-/npm-7.0.13.tgz",
+      "integrity": "sha512-B7avOtnrtmFA1X4c8RvHHfyOr6ra7SDb7KMn1HtjmvlOj15m8ujtV6gn9ktAvSWSWUbfyXFcZA/4aHX3CEnFXQ==",
       "requires": {
       "requires": {
-        "@npmcli/arborist": "^1.0.9",
+        "@npmcli/arborist": "^1.0.12",
         "@npmcli/ci-detect": "^1.2.0",
         "@npmcli/ci-detect": "^1.2.0",
         "@npmcli/config": "^1.2.1",
         "@npmcli/config": "^1.2.1",
-        "@npmcli/run-script": "^1.7.5",
+        "@npmcli/run-script": "^1.8.0",
         "abbrev": "~1.1.1",
         "abbrev": "~1.1.1",
         "ansicolors": "~0.3.2",
         "ansicolors": "~0.3.2",
         "ansistyles": "~0.1.3",
         "ansistyles": "~0.1.3",
@@ -1064,7 +1064,7 @@
       },
       },
       "dependencies": {
       "dependencies": {
         "@npmcli/arborist": {
         "@npmcli/arborist": {
-          "version": "1.0.9",
+          "version": "1.0.12",
           "bundled": true,
           "bundled": true,
           "requires": {
           "requires": {
             "@npmcli/installed-package-contents": "^1.0.5",
             "@npmcli/installed-package-contents": "^1.0.5",
@@ -1073,7 +1073,7 @@
             "@npmcli/move-file": "^1.0.1",
             "@npmcli/move-file": "^1.0.1",
             "@npmcli/name-from-folder": "^1.0.1",
             "@npmcli/name-from-folder": "^1.0.1",
             "@npmcli/node-gyp": "^1.0.0",
             "@npmcli/node-gyp": "^1.0.0",
-            "@npmcli/run-script": "^1.7.2",
+            "@npmcli/run-script": "^1.8.0",
             "bin-links": "^2.2.1",
             "bin-links": "^2.2.1",
             "cacache": "^15.0.3",
             "cacache": "^15.0.3",
             "common-ancestor-path": "^1.0.1",
             "common-ancestor-path": "^1.0.1",
@@ -1175,13 +1175,14 @@
           }
           }
         },
         },
         "@npmcli/run-script": {
         "@npmcli/run-script": {
-          "version": "1.7.5",
+          "version": "1.8.0",
           "bundled": true,
           "bundled": true,
           "requires": {
           "requires": {
             "@npmcli/node-gyp": "^1.0.0",
             "@npmcli/node-gyp": "^1.0.0",
             "@npmcli/promise-spawn": "^1.3.0",
             "@npmcli/promise-spawn": "^1.3.0",
             "infer-owner": "^1.0.4",
             "infer-owner": "^1.0.4",
             "node-gyp": "^7.1.0",
             "node-gyp": "^7.1.0",
+            "puka": "^1.0.1",
             "read-package-json-fast": "^1.1.3"
             "read-package-json-fast": "^1.1.3"
           }
           }
         },
         },
@@ -2309,6 +2310,10 @@
           "version": "1.8.0",
           "version": "1.8.0",
           "bundled": true
           "bundled": true
         },
         },
+        "puka": {
+          "version": "1.0.1",
+          "bundled": true
+        },
         "punycode": {
         "punycode": {
           "version": "2.1.1",
           "version": "2.1.1",
           "bundled": true
           "bundled": true
@@ -3119,9 +3124,9 @@
       "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
       "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
     },
     },
     "ws": {
     "ws": {
-      "version": "7.3.1",
-      "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.1.tgz",
-      "integrity": "sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA=="
+      "version": "7.4.0",
+      "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.0.tgz",
+      "integrity": "sha512-kyFwXuV/5ymf+IXhS6f0+eAFvydbaBW3zjpT6hUdAh/hbVjTIB5EHBGi0bPoCLSK2wcuz3BrEkB9LrYv1Nm4NQ=="
     },
     },
     "yallist": {
     "yallist": {
       "version": "3.1.1",
       "version": "3.1.1",

+ 3 - 3
package.json

@@ -16,13 +16,13 @@
   },
   },
   "dependencies": {
   "dependencies": {
     "cheerio": "^1.0.0-rc.3",
     "cheerio": "^1.0.0-rc.3",
-    "discord-oauth2": "^2.5.0",
-    "discord.js": "^12.4.1",
+    "discord-oauth2": "^2.6.0",
+    "discord.js": "^12.5.0",
     "dotenv": "^8.2.0",
     "dotenv": "^8.2.0",
     "full-icu": "^1.3.1",
     "full-icu": "^1.3.1",
     "got": "^11.8.0",
     "got": "^11.8.0",
     "htmlparser2": "^5.0.1",
     "htmlparser2": "^5.0.1",
-    "npm": "^7.0.9",
+    "npm": "^7.0.13",
     "sqlite3": "^5.0.0"
     "sqlite3": "^5.0.0"
   },
   },
   "repository": {
   "repository": {