Browse Source

Minor fixes

Markus-Rost 4 năm trước cách đây
mục cha
commit
f738f243b9
4 tập tin đã thay đổi với 29 bổ sung6 xóa
  1. 5 1
      cmds/invite.js
  2. 5 2
      cmds/patreon.js
  3. 16 3
      functions/parse_page.js
  4. 3 0
      util/i18n.js

+ 5 - 1
cmds/invite.js

@@ -12,7 +12,11 @@ function cmd_invite(lang, msg, args, line, wiki) {
 	if ( args.join('') ) {
 		this.LINK(lang, msg, line, wiki);
 	} else {
-		msg.client.generateInvite(defaultPermissions).then( invite => msg.sendChannel( lang.get('invite.bot') + '\n<' + invite + '>' ), log_error );
+		msg.client.generateInvite({
+			permissions: defaultPermissions
+		}).then( invite => {
+			msg.sendChannel( lang.get('invite.bot') + '\n<' + invite + '>' );
+		}, log_error );
 	}
 }
 

+ 5 - 2
cmds/patreon.js

@@ -17,8 +17,11 @@ function cmd_patreon(lang, msg, args, line, wiki) {
 	
 	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(defaultPermissions).then( invite => {
-			msg.replyMsg( 'I\'m not on a server with the id `' + args[1] + '`.\n<' + invite + '&guild_id=' + args[1] + '>', {}, true )
+		if ( guild === undefined ) return msg.client.generateInvite({
+			permissions: defaultPermissions,
+			guild: args[1]
+		}).then( invite => {
+			msg.replyMsg( 'I\'m not on a server with the id `' + args[1] + '`.\n<' + invite + '>', {}, true )
 		}, log_error );
 		if ( args[1] in patreons ) return msg.replyMsg( '"' + guild + '" has the patreon features already enabled.', {}, true );
 		db.get( 'SELECT count, COUNT(guild) guilds FROM patreons LEFT JOIN discord ON discord.patreon = patreons.patreon WHERE patreons.patreon = ? GROUP BY patreons.patreon', [msg.author.id], (dberror, row) => {

+ 16 - 3
functions/parse_page.js

@@ -1,5 +1,12 @@
 const cheerio = require('cheerio');
 
+const infoboxList = [
+	'.infobox',
+	'.portable-infobox',
+	'.infoboxtable',
+	'.notaninfobox'
+];
+
 const removeClasses = [
 	'table',
 	'div',
@@ -41,15 +48,21 @@ function parse_page(msg, title, embed, wiki, thumbnail) {
 			return;
 		}
 		var change = false;
-		var $ = cheerio.load(response.body.parse.text['*']);
+		var $ = cheerio.load(response.body.parse.text['*'].replace( /<br\/?>/g, '\n' ));
 		if ( embed.thumbnail?.url === thumbnail ) {
 			var image = response.body.parse.images.find( pageimage => ( /\.(?:png|jpg|jpeg|gif)$/.test(pageimage.toLowerCase()) && pageimage.toLowerCase().includes( title.toLowerCase().replace( / /g, '_' ) ) ) );
 			if ( !image ) {
-				thumbnail = $('img').filter( (i, img) => {
+				thumbnail = $(infoboxList.join(', ')).find('img').filter( (i, img) => {
+					img = $(img).prop('src')?.toLowerCase();
+					return ( /^(?:https?:)?\/\//.test(img) && /\.(?:png|jpg|jpeg|gif)(?:\/|\?|$)/.test(img) );
+				} ).first().prop('src');
+				if ( !thumbnail ) thumbnail = $('img').filter( (i, img) => {
 					img = $(img).prop('src')?.toLowerCase();
 					return ( /^(?:https?:)?\/\//.test(img) && /\.(?:png|jpg|jpeg|gif)(?:\/|\?|$)/.test(img) );
 				} ).first().prop('src');
-				if ( !thumbnail ) image = response.body.parse.images.find( pageimage => ( /\.(?:png|jpg|jpeg|gif)$/.test(pageimage.toLowerCase()) ) );
+				if ( !thumbnail ) image = response.body.parse.images.find( pageimage => {
+					return /\.(?:png|jpg|jpeg|gif)$/.test(pageimage.toLowerCase());
+				} );
 			}
 			if ( image ) thumbnail = wiki.toLink('Special:FilePath/' + image);
 			if ( thumbnail ) {

+ 3 - 0
util/i18n.js

@@ -187,11 +187,14 @@ function plural(lang, number, args) {
 				else text = getArg(args, 1);
 			}
 			break;
+		case 'bn':
 		case 'de':
 		case 'en':
 		case 'es':
+		case 'ja':
 		case 'nl':
 		case 'pt-br':
+		case 'th':
 		case 'tr':
 		case 'ja':
 		case 'zh-hans':