Browse Source

add categories to removeSettings

Markus-Rost 4 years ago
parent
commit
c0f5b9a9ba
2 changed files with 13 additions and 8 deletions
  1. 8 3
      cmds/eval.js
  2. 5 5
      cmds/settings.js

+ 8 - 3
cmds/eval.js

@@ -263,7 +263,12 @@ function removePatreons(guild, msg) {
 function removeSettings(msg) {
 	if ( !msg ) return 'removeSettings(msg) – No message provided!';
 	try {
-		msg.client.shard.broadcastEval( `[[...this.guilds.cache.keys()], [...this.channels.cache.filter( channel => channel.isGuild() ).keys()]]` ).then( results => {
+		msg.client.shard.broadcastEval( `[
+			[...this.guilds.cache.keys()],
+			this.channels.cache.filter( channel => {
+				return ( channel.isGuild() || ( channel.type === 'category' && global.patreons.hasOwnProperty(channel.guild.id) ) );
+			} ).map( channel => ( channel.type === 'category' ? '#' : '' ) + channel.id )
+		]` ).then( results => {
 			var all_guilds = results.map( result => result[0] ).reduce( (acc, val) => acc.concat(val), [] );
 			var all_channels = results.map( result => result[1] ).reduce( (acc, val) => acc.concat(val), [] );
 			var guilds = [];
@@ -294,7 +299,7 @@ function removeSettings(msg) {
 							msg.replyMsg( 'I got an error while removing the guilds!', {}, true );
 							return dberror;
 						}
-						console.log( '- Guilds successfully removed.' );
+						console.log( '- Guilds successfully removed: ' + this.changes );
 					} );
 				}
 				if ( channels.length ) db.run( 'DELETE FROM discord WHERE channel IN (' + channels.map( channel => '?' ).join(', ') + ')', channels, function (dberror) {
@@ -303,7 +308,7 @@ function removeSettings(msg) {
 						msg.replyMsg( 'I got an error while removing the channels!', {}, true );
 						return dberror;
 					}
-					console.log( '- Channels successfully removed.' );
+					console.log( '- Channels successfully removed: ' + this.changes );
 				} );
 				if ( !guilds.length && !channels.length ) console.log( '- Settings successfully removed.' );
 			} );

+ 5 - 5
cmds/settings.js

@@ -70,9 +70,9 @@ function cmd_settings(lang, msg, args, line, wiki) {
 			if ( !args[1] ) return msg.replyMsg( text, {}, true );
 			
 			args[0] = args[1].toLowerCase();
-			args[1] = args.slice(2).join(' ').toLowerCase().trim().replace( /^<\s*(.*)>$/, '$1' );
+			args[1] = args.slice(2).join(' ').toLowerCase().trim().replace( /^<\s*(.*)\s*>$/, '$1' );
 		}
-		else args[1] = args.slice(1).join(' ').toLowerCase().trim().replace( /^<\s*(.*)>$/, '$1' );
+		else args[1] = args.slice(1).join(' ').toLowerCase().trim().replace( /^<\s*(.*)\s*>$/, '$1' );
 		
 		if ( args[0] === 'wiki' ) {
 			prelang += 'wiki';
@@ -89,18 +89,18 @@ function cmd_settings(lang, msg, args, line, wiki) {
 				return msg.replyMsg( text, {split:true}, true );
 			}
 			return msg.reactEmoji('⏳', true).then( reaction => {
-				got.get( wikinew + 'api.php?&action=query&meta=allmessages|siteinfo&ammessages=custom-GamepediaNotice|custom-FandomMergeNotice&amenableparser=true&siprop=general|extensions&format=json' ).then( response => {
+				got.get( wikinew + 'api.php?&action=query&meta=siteinfo&siprop=general|extensions&format=json' ).then( response => {
 					if ( response.statusCode === 404 && typeof response.body === 'string' ) {
 						let api = cheerio.load(response.body)('head link[rel="EditURI"]').prop('href');
 						if ( api ) {
 							wikinew = new Wiki(api.split('api.php?')[0], wikinew);
-							return got.get( wikinew + 'api.php?action=query&meta=allmessages|siteinfo&ammessages=custom-GamepediaNotice|custom-FandomMergeNotice&amenableparser=true&siprop=general|extensions&format=json' );
+							return got.get( wikinew + 'api.php?action=query&meta=siteinfo&siprop=general|extensions&format=json' );
 						}
 					}
 					return response;
 				} ).then( response => {
 					var body = response.body;
-					if ( response.statusCode !== 200 || !body?.query?.allmessages || !body?.query?.general || !body?.query?.extensions ) {
+					if ( response.statusCode !== 200 || !body?.query?.general || !body?.query?.extensions ) {
 						console.log( '- ' + response.statusCode + ': Error while testing the wiki: ' + body?.error?.info );
 						if ( reaction ) reaction.removeEmoji();
 						msg.reactEmoji('nowiki', true);