Răsfoiți Sursa

don't edit the description in

Markus-Rost 4 ani în urmă
părinte
comite
1b2b77178a
5 a modificat fișierele cu 142 adăugiri și 157 ștergeri
  1. 1 1
      RcGcDb
  2. 80 81
      cmds/wiki/general.js
  3. 2 2
      cmds/wiki/random.js
  4. 2 2
      cmds/wiki/user.js
  5. 57 71
      functions/parse_page.js

+ 1 - 1
RcGcDb

@@ -1 +1 @@
-Subproject commit e344316491e96d8329e4a028e64a767efcc9d289
+Subproject commit 4025f15e1a9117587730ce65167e73290919226f

+ 80 - 81
cmds/wiki/general.js

@@ -188,101 +188,105 @@ function gamepedia_check_wiki(lang, msg, title, wiki, cmd, reaction, spoiler = '
 				return;
 				return;
 			}
 			}
 			if ( ( querypage.missing !== undefined && querypage.known === undefined && !( noRedirect || querypage.categoryinfo ) ) || querypage.invalid !== undefined ) return got.get( wiki + 'api.php?action=query&prop=categoryinfo|info|pageprops|pageimages|extracts&piprop=original|name&ppprop=description|displaytitle|page_image_free|infoboxes&explaintext=true&exsectionformat=raw&exlimit=1&generator=search&gsrnamespace=4|12|14|' + querypage.ns + '|' + Object.values(body.query.namespaces).filter( ns => ns.content !== undefined ).map( ns => ns.id ).join('|') + '&gsrlimit=1&gsrsearch=' + encodeURIComponent( title ) + '&format=json' ).then( srresponse => {
 			if ( ( querypage.missing !== undefined && querypage.known === undefined && !( noRedirect || querypage.categoryinfo ) ) || querypage.invalid !== undefined ) return got.get( wiki + 'api.php?action=query&prop=categoryinfo|info|pageprops|pageimages|extracts&piprop=original|name&ppprop=description|displaytitle|page_image_free|infoboxes&explaintext=true&exsectionformat=raw&exlimit=1&generator=search&gsrnamespace=4|12|14|' + querypage.ns + '|' + Object.values(body.query.namespaces).filter( ns => ns.content !== undefined ).map( ns => ns.id ).join('|') + '&gsrlimit=1&gsrsearch=' + encodeURIComponent( title ) + '&format=json' ).then( srresponse => {
+				logging(wiki, msg.guild?.id, 'general', 'search');
 				var srbody = srresponse.body;
 				var srbody = srresponse.body;
 				if ( srbody && srbody.warnings ) log_warn(srbody.warnings);
 				if ( srbody && srbody.warnings ) log_warn(srbody.warnings);
 				if ( srresponse.statusCode !== 200 || !srbody || srbody.batchcomplete === undefined ) {
 				if ( srresponse.statusCode !== 200 || !srbody || srbody.batchcomplete === undefined ) {
 					console.log( '- ' + srresponse.statusCode + ': Error while getting the search results: ' + ( srbody && srbody.error && srbody.error.info ) );
 					console.log( '- ' + srresponse.statusCode + ': Error while getting the search results: ' + ( srbody && srbody.error && srbody.error.info ) );
 					msg.sendChannelError( spoiler + '<' + wiki.toLink('Special:Search', {search:title}) + '>' + spoiler );
 					msg.sendChannelError( spoiler + '<' + wiki.toLink('Special:Search', {search:title}) + '>' + spoiler );
+				
+					if ( reaction ) reaction.removeEmoji();
 					return;
 					return;
 				}
 				}
 				if ( !srbody.query ) {
 				if ( !srbody.query ) {
 					msg.reactEmoji('🤷');
 					msg.reactEmoji('🤷');
+				
+					if ( reaction ) reaction.removeEmoji();
+					return;
 				}
 				}
-				else {
-					querypage = Object.values(srbody.query.pages)[0];
-					var pagelink = wiki.toLink(querypage.title, querystring, fragment);
-					var text = '';
-					var embed = new MessageEmbed().setAuthor( body.query.general.sitename ).setTitle( querypage.title.escapeFormatting() ).setURL( pagelink );
-					if ( querypage.pageprops && querypage.pageprops.displaytitle ) {
-						var displaytitle = htmlToDiscord( querypage.pageprops.displaytitle );
-						if ( displaytitle.length > 250 ) displaytitle = displaytitle.substring(0, 250) + '\u2026';
-						embed.setTitle( displaytitle );
-					}
-					if ( querypage.extract ) {
-						var extract = extract_desc(querypage.extract, fragment);
-						embed.backupDescription = extract[0];
-						if ( extract[1].length && extract[2].length ) {
-							embed.backupField = {name: extract[1], value: extract[2]};
-						}
-					}
-					if ( querypage.pageprops && querypage.pageprops.description ) {
-						var description = htmlToPlain( querypage.pageprops.description );
-						if ( description.length > 1000 ) description = description.substring(0, 1000) + '\u2026';
-						embed.backupDescription = description;
-					}
-					if ( querypage.ns === 6 ) {
-						var pageimage = ( querypage?.original?.source || wiki.toLink('Special:FilePath/' + querypage.title, {version:Date.now()}) );
-						if ( msg.showEmbed() && /\.(?:png|jpg|jpeg|gif)$/.test(querypage.title.toLowerCase()) ) embed.setImage( pageimage );
-						else if ( msg.uploadFiles() ) embed.attachFiles( [{attachment:pageimage,name:( spoiler ? 'SPOILER ' : '' ) + querypage.title}] );
-					}
-					else if ( querypage.title === body.query.general.mainpage ) {
-						embed.setThumbnail( new URL(body.query.general.logo, wiki).href );
-					}
-					else if ( querypage.pageimage && querypage.original ) {
-						embed.setThumbnail( querypage.original.source );
-					}
-					else if ( querypage.pageprops && querypage.pageprops.page_image_free ) {
-						embed.setThumbnail( wiki.toLink('Special:FilePath/' + querypage.pageprops.page_image_free, {version:Date.now()}) );
+				querypage = Object.values(srbody.query.pages)[0];
+				var pagelink = wiki.toLink(querypage.title, querystring, fragment);
+				var text = '';
+				var embed = new MessageEmbed().setAuthor( body.query.general.sitename ).setTitle( querypage.title.escapeFormatting() ).setURL( pagelink );
+				if ( querypage.pageprops && querypage.pageprops.displaytitle ) {
+					var displaytitle = htmlToDiscord( querypage.pageprops.displaytitle );
+					if ( displaytitle.length > 250 ) displaytitle = displaytitle.substring(0, 250) + '\u2026';
+					embed.setTitle( displaytitle );
+				}
+				if ( querypage.extract ) {
+					var extract = extract_desc(querypage.extract, fragment);
+					embed.backupDescription = extract[0];
+					if ( extract[1].length && extract[2].length ) {
+						embed.backupField = {name: extract[1], value: extract[2]};
 					}
 					}
-					else embed.setThumbnail( new URL(body.query.general.logo, wiki).href );
-					
-					var prefix = ( msg.channel.isGuild() && patreons[msg.guild.id] || process.env.prefix );
-					var linksuffix = ( querystring.toString() ? '?' + querystring : '' ) + ( fragment ? '#' + fragment : '' );
-					if ( title.replace( /[_-]/g, ' ' ).toLowerCase() === querypage.title.replace( /-/g, ' ' ).toLowerCase() ) {
-						text = '';
+				}
+				if ( querypage.pageprops && querypage.pageprops.description ) {
+					var description = htmlToPlain( querypage.pageprops.description );
+					if ( description.length > 1000 ) description = description.substring(0, 1000) + '\u2026';
+					embed.backupDescription = description;
+				}
+				if ( querypage.ns === 6 ) {
+					var pageimage = ( querypage?.original?.source || wiki.toLink('Special:FilePath/' + querypage.title, {version:Date.now()}) );
+					if ( msg.showEmbed() && /\.(?:png|jpg|jpeg|gif)$/.test(querypage.title.toLowerCase()) ) embed.setImage( pageimage );
+					else if ( msg.uploadFiles() ) embed.attachFiles( [{attachment:pageimage,name:( spoiler ? 'SPOILER ' : '' ) + querypage.title}] );
+				}
+				else if ( querypage.title === body.query.general.mainpage ) {
+					embed.setThumbnail( new URL(body.query.general.logo, wiki).href );
+				}
+				else if ( querypage.pageimage && querypage.original ) {
+					embed.setThumbnail( querypage.original.source );
+				}
+				else if ( querypage.pageprops && querypage.pageprops.page_image_free ) {
+					embed.setThumbnail( wiki.toLink('Special:FilePath/' + querypage.pageprops.page_image_free, {version:Date.now()}) );
+				}
+				else embed.setThumbnail( new URL(body.query.general.logo, wiki).href );
+				
+				var prefix = ( msg.channel.isGuild() && patreons[msg.guild.id] || process.env.prefix );
+				var linksuffix = ( querystring.toString() ? '?' + querystring : '' ) + ( fragment ? '#' + fragment : '' );
+				if ( title.replace( /[_-]/g, ' ' ).toLowerCase() === querypage.title.replace( /-/g, ' ' ).toLowerCase() ) {
+					text = '';
+				}
+				else if ( !srbody.continue ) {
+					text = '\n' + lang.get('search.infopage', '`' + prefix + cmd + ( lang.localNames.page || 'page' ) + ' ' + title + linksuffix + '`');
+				}
+				else {
+					text = '\n' + lang.get('search.infosearch', '`' + prefix + cmd + ( lang.localNames.page || 'page' ) + ' ' + title + linksuffix + '`', '`' + prefix + cmd + ( lang.localNames.search || 'search' ) + ' ' + title + linksuffix + '`');
+				}
+				
+				if ( querypage.categoryinfo ) {
+					var category = [lang.get('search.category.content')];
+					if ( querypage.categoryinfo.size === 0 ) {
+						category.push(lang.get('search.category.empty'));
 					}
 					}
-					else if ( !srbody.continue ) {
-						text = '\n' + lang.get('search.infopage', '`' + prefix + cmd + ( lang.localNames.page || 'page' ) + ' ' + title + linksuffix + '`');
+					if ( querypage.categoryinfo.pages > 0 ) {
+						category.push(lang.get('search.category.pages', querypage.categoryinfo.pages.toLocaleString(lang.get('dateformat')), querypage.categoryinfo.pages));
 					}
 					}
-					else {
-						text = '\n' + lang.get('search.infosearch', '`' + prefix + cmd + ( lang.localNames.page || 'page' ) + ' ' + title + linksuffix + '`', '`' + prefix + cmd + ( lang.localNames.search || 'search' ) + ' ' + title + linksuffix + '`');
+					if ( querypage.categoryinfo.files > 0 ) {
+						category.push(lang.get('search.category.files', querypage.categoryinfo.files.toLocaleString(lang.get('dateformat')), querypage.categoryinfo.files));
 					}
 					}
-					
-					if ( querypage.categoryinfo ) {
-						var category = [lang.get('search.category.content')];
-						if ( querypage.categoryinfo.size === 0 ) {
-							category.push(lang.get('search.category.empty'));
-						}
-						if ( querypage.categoryinfo.pages > 0 ) {
-							category.push(lang.get('search.category.pages', querypage.categoryinfo.pages.toLocaleString(lang.get('dateformat')), querypage.categoryinfo.pages));
-						}
-						if ( querypage.categoryinfo.files > 0 ) {
-							category.push(lang.get('search.category.files', querypage.categoryinfo.files.toLocaleString(lang.get('dateformat')), querypage.categoryinfo.files));
-						}
-						if ( querypage.categoryinfo.subcats > 0 ) {
-							category.push(lang.get('search.category.subcats', querypage.categoryinfo.subcats.toLocaleString(lang.get('dateformat')), querypage.categoryinfo.subcats));
-						}
-						if ( msg.showEmbed() ) embed.addField( category[0], category.slice(1).join('\n') );
-						else text += '\n\n' + category.join('\n');
+					if ( querypage.categoryinfo.subcats > 0 ) {
+						category.push(lang.get('search.category.subcats', querypage.categoryinfo.subcats.toLocaleString(lang.get('dateformat')), querypage.categoryinfo.subcats));
 					}
 					}
+					if ( msg.showEmbed() ) embed.addField( category[0], category.slice(1).join('\n') );
+					else text += '\n\n' + category.join('\n');
+				}
 
 
-					if ( !fragment && !embed.fields.length && querypage.pageprops && querypage.pageprops.infoboxes ) {
-						try {
-							var infobox = JSON.parse(querypage.pageprops.infoboxes)?.[0];
-							parse_infobox(infobox, embed, new URL(body.query.general.logo, wiki).href, wiki.articleURL.href);
-						}
-						catch ( error ) {
-							console.log( '- Failed to parse the infobox: ' + error );
-						}
+				if ( !fragment && !embed.fields.length && querypage.pageprops && querypage.pageprops.infoboxes ) {
+					try {
+						var infobox = JSON.parse(querypage.pageprops.infoboxes)?.[0];
+						parse_infobox(infobox, embed, new URL(body.query.general.logo, wiki).href, wiki.articleURL.href);
+					}
+					catch ( error ) {
+						console.log( '- Failed to parse the infobox: ' + error );
 					}
 					}
-		
-					msg.sendChannel( spoiler + '<' + pagelink + '>' + text + spoiler, {embed} ).then( message => parse_page(message, querypage, embed, wiki, ( querypage.title === body.query.general.mainpage ? '' : new URL(body.query.general.logo, wiki).href ), fragment) );
 				}
 				}
+
+				return parse_page(msg, spoiler + '<' + pagelink + '>' + text + spoiler, embed, wiki, reaction, querypage, ( querypage.title === body.query.general.mainpage ? '' : new URL(body.query.general.logo, wiki).href ), fragment);
 			}, error => {
 			}, error => {
+				logging(wiki, msg.guild?.id, 'general', 'search');
 				console.log( '- Error while getting the search results: ' + error );
 				console.log( '- Error while getting the search results: ' + error );
 				msg.sendChannelError( spoiler + '<' + wiki.toLink('Special:Search', {search:title}) + '>' + spoiler );
 				msg.sendChannelError( spoiler + '<' + wiki.toLink('Special:Search', {search:title}) + '>' + spoiler );
-			} ).finally( () => {
-				logging(wiki, msg.guild?.id, 'general', 'search');
+				
 				if ( reaction ) reaction.removeEmoji();
 				if ( reaction ) reaction.removeEmoji();
 			} );
 			} );
 			if ( querypage.ns === -1 ) {
 			if ( querypage.ns === -1 ) {
@@ -369,10 +373,7 @@ function gamepedia_check_wiki(lang, msg, title, wiki, cmd, reaction, spoiler = '
 				}
 				}
 			}
 			}
 			
 			
-			msg.sendChannel( spoiler + '<' + pagelink + '>' + text + spoiler, {embed} ).then( message => parse_page(message, querypage, embed, wiki, ( querypage.title === body.query.general.mainpage ? '' : new URL(body.query.general.logo, wiki).href ), ( fragment || ( body.query.redirects && body.query.redirects[0].tofragment ) || '' )) );
-			
-			if ( reaction ) reaction.removeEmoji();
-			return;
+			return parse_page(msg, spoiler + '<' + pagelink + '>' + text + spoiler, embed, wiki, reaction, querypage, ( querypage.title === body.query.general.mainpage ? '' : new URL(body.query.general.logo, wiki).href ), ( fragment || ( body.query.redirects && body.query.redirects[0].tofragment ) || '' ));
 		}
 		}
 		if ( body.query.interwiki ) {
 		if ( body.query.interwiki ) {
 			if ( msg.channel.isGuild() && pause[msg.guild.id] ) {
 			if ( msg.channel.isGuild() && pause[msg.guild.id] ) {
@@ -461,9 +462,7 @@ function gamepedia_check_wiki(lang, msg, title, wiki, cmd, reaction, spoiler = '
 		}, error => {
 		}, error => {
 			console.log( '- Error while getting the main page: ' + error );
 			console.log( '- Error while getting the main page: ' + error );
 		} ).finally( () => {
 		} ).finally( () => {
-			msg.sendChannel( spoiler + '<' + pagelink + '>' + spoiler, {embed} ).then( message => parse_page(message, querypage, embed, wiki, '', fragment) );
-			
-			if ( reaction ) reaction.removeEmoji();
+			parse_page(msg, spoiler + '<' + pagelink + '>' + spoiler, embed, wiki, reaction, querypage, '', fragment);
 		} );
 		} );
 	}, error => {
 	}, error => {
 		if ( interwiki ) msg.sendChannel( spoiler + ' ' + interwiki + ' ' + spoiler );
 		if ( interwiki ) msg.sendChannel( spoiler + ' ' + interwiki + ' ' + spoiler );

+ 2 - 2
cmds/wiki/random.js

@@ -29,6 +29,7 @@ function gamepedia_random(lang, msg, wiki, reaction, spoiler) {
 				console.log( '- ' + response.statusCode + ': Error while getting the search results: ' + ( body && body.error && body.error.info ) );
 				console.log( '- ' + response.statusCode + ': Error while getting the search results: ' + ( body && body.error && body.error.info ) );
 				msg.sendChannelError( spoiler + '<' + wiki.toLink('Special:Random') + '>' + spoiler );
 				msg.sendChannelError( spoiler + '<' + wiki.toLink('Special:Random') + '>' + spoiler );
 			}
 			}
+			if ( reaction ) reaction.removeEmoji();
 			return;
 			return;
 		}
 		}
 		wiki.updateWiki(body.query.general);
 		wiki.updateWiki(body.query.general);
@@ -71,7 +72,7 @@ function gamepedia_random(lang, msg, wiki, reaction, spoiler) {
 			}
 			}
 		}
 		}
 		
 		
-		msg.sendChannel( '🎲 ' + spoiler + '<' + pagelink + '>' + spoiler, {embed} ).then( message => parse_page(message, querypage, embed, wiki, ( querypage.title === body.query.general.mainpage ? '' : new URL(body.query.general.logo, wiki).href )) );
+		parse_page(msg, '🎲 ' + spoiler + '<' + pagelink + '>' + spoiler, embed, wiki, reaction, querypage, ( querypage.title === body.query.general.mainpage ? '' : new URL(body.query.general.logo, wiki).href ));
 	}, error => {
 	}, error => {
 		if ( wiki.noWiki(error.message) ) {
 		if ( wiki.noWiki(error.message) ) {
 			console.log( '- This wiki doesn\'t exist!' );
 			console.log( '- This wiki doesn\'t exist!' );
@@ -81,7 +82,6 @@ function gamepedia_random(lang, msg, wiki, reaction, spoiler) {
 			console.log( '- Error while getting the search results: ' + error );
 			console.log( '- Error while getting the search results: ' + error );
 			msg.sendChannelError( spoiler + '<' + wiki.toLink('Special:Random') + '>' + spoiler );
 			msg.sendChannelError( spoiler + '<' + wiki.toLink('Special:Random') + '>' + spoiler );
 		}
 		}
-	} ).finally( () => {
 		if ( reaction ) reaction.removeEmoji();
 		if ( reaction ) reaction.removeEmoji();
 	} );
 	} );
 }
 }

+ 2 - 2
cmds/wiki/user.js

@@ -75,7 +75,7 @@ function gamepedia_user(lang, msg, namespace, username, wiki, querystring, fragm
 						}
 						}
 					}
 					}
 					
 					
-					msg.sendChannel( spoiler + '<' + pagelink + '>' + spoiler, {embed} ).then( message => parse_page(message, querypage, embed, wiki, '', fragment) );
+					return parse_page(msg, spoiler + '<' + pagelink + '>' + spoiler, embed, wiki, reaction, querypage, new URL(body.query.general.logo, wiki).href, fragment);
 				}
 				}
 			}
 			}
 			else {
 			else {
@@ -244,7 +244,7 @@ function gamepedia_user(lang, msg, namespace, username, wiki, querystring, fragm
 					}
 					}
 				}
 				}
 				
 				
-				msg.sendChannel( spoiler + '<' + pagelink + '>' + spoiler, {embed} ).then( message => parse_page(message, querypage, embed, wiki, new URL(body.query.general.logo, wiki).href, fragment) );
+				return parse_page(msg, spoiler + '<' + pagelink + '>' + spoiler, embed, wiki, reaction, querypage, new URL(body.query.general.logo, wiki).href, fragment);
 			}
 			}
 			
 			
 			if ( reaction ) reaction.removeEmoji();
 			if ( reaction ) reaction.removeEmoji();

+ 57 - 71
functions/parse_page.js

@@ -51,88 +51,83 @@ const keepMainPageTag = [
 /**
 /**
  * Parses a wiki page to get it's description.
  * Parses a wiki page to get it's description.
  * @param {import('discord.js').Message} msg - The Discord message.
  * @param {import('discord.js').Message} msg - The Discord message.
+ * @param {String} content - The content for the message.
+ * @param {import('discord.js').MessageEmbed} embed - The embed for the message.
+ * @param {import('../util/wiki.js')} wiki - The wiki for the page.
+ * @param {import('discord.js').MessageReaction} reaction - The reaction on the message.
  * @param {Object} querypage - The details of the page.
  * @param {Object} querypage - The details of the page.
  * @param {String} querypage.title - The title of the page.
  * @param {String} querypage.title - The title of the page.
  * @param {String} querypage.contentmodel - The content model of the page.
  * @param {String} querypage.contentmodel - The content model of the page.
- * @param {import('discord.js').MessageEmbed} embed - The embed for the page.
- * @param {import('../util/wiki.js')} wiki - The wiki for the page.
  * @param {String} thumbnail - The default thumbnail for the wiki.
  * @param {String} thumbnail - The default thumbnail for the wiki.
  * @param {String} [fragment] - The section title to embed.
  * @param {String} [fragment] - The section title to embed.
  */
  */
-function parse_page(msg, {title, contentmodel}, embed, wiki, thumbnail, fragment = '') {
+function parse_page(msg, content, embed, wiki, reaction, {title, contentmodel}, thumbnail, fragment = '') {
 	if ( !msg?.showEmbed?.() || ( embed.description && embed.thumbnail?.url !== thumbnail && !embed.brokenInfobox && !fragment ) ) {
 	if ( !msg?.showEmbed?.() || ( embed.description && embed.thumbnail?.url !== thumbnail && !embed.brokenInfobox && !fragment ) ) {
+		msg.sendChannel( content, {embed} );
+
+		if ( reaction ) reaction.removeEmoji();
 		return;
 		return;
 	}
 	}
-	var change = false;
-	if ( contentmodel !== 'wikitext' ) {
-		return got.get( wiki + 'api.php?action=query&prop=revisions&rvprop=content&rvslots=main&converttitles=true&titles=%1F' + encodeURIComponent( title ) + '&format=json' ).then( response => {
-			var body = response.body;
-			if ( body && body.warnings ) log_warn(body.warnings);
-			var revision = Object.values(( body?.query?.pages || {} ))?.[0]?.revisions?.[0];
-			revision = ( revision?.slots?.main || revision );
-			if ( response.statusCode !== 200 || !body || body.batchcomplete === undefined || !revision?.['*'] ) {
-				console.log( '- ' + response.statusCode + ': Error while getting the page content: ' + ( body && body.error && body.error.info ) );
-				if ( embed.backupField && embed.length < 4750 && embed.fields.length < 25 ) {
-					embed.spliceFields( 0, 0, embed.backupField );
-					change = true;
-				}
-				if ( embed.backupDescription && embed.length < 5000 ) {
-					embed.setDescription( embed.backupDescription );
-					change = true;
-				}
-				return;
+	if ( contentmodel !== 'wikitext' ) return got.get( wiki + 'api.php?action=query&prop=revisions&rvprop=content&rvslots=main&converttitles=true&titles=%1F' + encodeURIComponent( title ) + '&format=json' ).then( response => {
+		var body = response.body;
+		if ( body && body.warnings ) log_warn(body.warnings);
+		var revision = Object.values(( body?.query?.pages || {} ))?.[0]?.revisions?.[0];
+		revision = ( revision?.slots?.main || revision );
+		if ( response.statusCode !== 200 || !body || body.batchcomplete === undefined || !revision?.['*'] ) {
+			console.log( '- ' + response.statusCode + ': Error while getting the page content: ' + ( body && body.error && body.error.info ) );
+			if ( embed.backupField && embed.length < 4750 && embed.fields.length < 25 ) {
+				embed.spliceFields( 0, 0, embed.backupField );
 			}
 			}
-			if ( !embed.description && embed.length < 4000 ) {
-				var description = revision['*'];
-				var regex = /^L(\d+)(?:-L?(\d+))?$/.exec(fragment);
-				if ( regex ) {
-					let descArray = description.split('\n').slice(regex[1] - 1, ( regex[2] || regex[1] ));
-					if ( descArray.length ) {
-						description = descArray.join('\n').replace( /^\n+/, '' ).replace( /\n+$/, '' );
-						if ( description ) {
-							if ( description.length > 2000 ) description = description.substring(0, 2000) + '\u2026';
-							description = '```' + ( contentModels[revision.contentmodel] || contentFormats[revision.contentformat] || '' ) + '\n' + description + '\n```';
-							embed.setDescription( description );
-							change = true;
-						}
+			if ( embed.backupDescription && embed.length < 5000 ) {
+				embed.setDescription( embed.backupDescription );
+			}
+			return;
+		}
+		if ( !embed.description && embed.length < 4000 ) {
+			var description = revision['*'];
+			var regex = /^L(\d+)(?:-L?(\d+))?$/.exec(fragment);
+			if ( regex ) {
+				let descArray = description.split('\n').slice(regex[1] - 1, ( regex[2] || regex[1] ));
+				if ( descArray.length ) {
+					description = descArray.join('\n').replace( /^\n+/, '' ).replace( /\n+$/, '' );
+					if ( description ) {
+						if ( description.length > 2000 ) description = description.substring(0, 2000) + '\u2026';
+						description = '```' + ( contentModels[revision.contentmodel] || contentFormats[revision.contentformat] || '' ) + '\n' + description + '\n```';
+						embed.setDescription( description );
 					}
 					}
 				}
 				}
-				else if ( description.trim() ) {
-					description = description.replace( /^\n+/, '' ).replace( /\n+$/, '' );
-					if ( description.length > 500 ) description = description.substring(0, 500) + '\u2026';
-					description = '```' + ( contentModels[revision.contentmodel] || contentFormats[revision.contentformat] || '' ) + '\n' + description + '\n```';
-					embed.setDescription( description );
-					change = true;
-				}
-				else if ( embed.backupDescription ) {
-					embed.setDescription( embed.backupDescription );
-					change = true;
-				}
 			}
 			}
-		}, error => {
-			console.log( '- Error while getting the page content: ' + error );
-			if ( embed.backupField && embed.length < 4750 && embed.fields.length < 25 ) {
-				embed.spliceFields( 0, 0, embed.backupField );
-				change = true;
+			else if ( description.trim() ) {
+				description = description.replace( /^\n+/, '' ).replace( /\n+$/, '' );
+				if ( description.length > 500 ) description = description.substring(0, 500) + '\u2026';
+				description = '```' + ( contentModels[revision.contentmodel] || contentFormats[revision.contentformat] || '' ) + '\n' + description + '\n```';
+				embed.setDescription( description );
 			}
 			}
-			if ( embed.backupDescription && embed.length < 5000 ) {
+			else if ( embed.backupDescription ) {
 				embed.setDescription( embed.backupDescription );
 				embed.setDescription( embed.backupDescription );
-				change = true;
 			}
 			}
-		} ).finally( () => {
-			if ( change ) msg.edit( msg.content, {embed,allowedMentions:{parse:[]}} ).catch(log_error);
-		} );
-	}
+		}
+	}, error => {
+		console.log( '- Error while getting the page content: ' + error );
+		if ( embed.backupField && embed.length < 4750 && embed.fields.length < 25 ) {
+			embed.spliceFields( 0, 0, embed.backupField );
+		}
+		if ( embed.backupDescription && embed.length < 5000 ) {
+			embed.setDescription( embed.backupDescription );
+		}
+	} ).finally( () => {
+		msg.sendChannel( content, {embed} );
+		
+		if ( reaction ) reaction.removeEmoji();
+	} );
 	got.get( wiki + 'api.php?action=parse&prop=text|images' + ( fragment ? '' : '&section=0' ) + '&disablelimitreport=true&disableeditsection=true&disabletoc=true&sectionpreview=true&page=' + encodeURIComponent( title ) + '&format=json' ).then( response => {
 	got.get( wiki + 'api.php?action=parse&prop=text|images' + ( fragment ? '' : '&section=0' ) + '&disablelimitreport=true&disableeditsection=true&disabletoc=true&sectionpreview=true&page=' + encodeURIComponent( title ) + '&format=json' ).then( response => {
 		if ( response.statusCode !== 200 || !response?.body?.parse?.text ) {
 		if ( response.statusCode !== 200 || !response?.body?.parse?.text ) {
 			console.log( '- ' + response.statusCode + ': Error while parsing the page: ' + response?.body?.error?.info );
 			console.log( '- ' + response.statusCode + ': Error while parsing the page: ' + response?.body?.error?.info );
 			if ( embed.backupDescription && embed.length < 5000 ) {
 			if ( embed.backupDescription && embed.length < 5000 ) {
 				embed.setDescription( embed.backupDescription );
 				embed.setDescription( embed.backupDescription );
-				change = true;
 			}
 			}
 			if ( embed.backupField && embed.length < 4750 && embed.fields.length < 25 ) {
 			if ( embed.backupField && embed.length < 4750 && embed.fields.length < 25 ) {
 				embed.spliceFields( 0, 0, embed.backupField );
 				embed.spliceFields( 0, 0, embed.backupField );
-				change = true;
 			}
 			}
 			return;
 			return;
 		}
 		}
@@ -160,7 +155,6 @@ function parse_page(msg, {title, contentmodel}, embed, wiki, thumbnail, fragment
 					}
 					}
 				}
 				}
 			} );
 			} );
-			change = true;
 		}
 		}
 		if ( embed.thumbnail?.url === thumbnail ) {
 		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, '_' ) ) ) );
 			var image = response.body.parse.images.find( pageimage => ( /\.(?:png|jpg|jpeg|gif)$/.test(pageimage.toLowerCase()) && pageimage.toLowerCase().includes( title.toLowerCase().replace( / /g, '_' ) ) ) );
@@ -178,10 +172,7 @@ function parse_page(msg, {title, contentmodel}, embed, wiki, thumbnail, fragment
 				} );
 				} );
 			}
 			}
 			if ( image ) thumbnail = wiki.toLink('Special:FilePath/' + image);
 			if ( image ) thumbnail = wiki.toLink('Special:FilePath/' + image);
-			if ( thumbnail ) {
-				embed.setThumbnail( thumbnail.replace( /^(?:https?:)?\/\//, 'https://' ) );
-				change = true;
-			}
+			if ( thumbnail ) embed.setThumbnail( thumbnail.replace( /^(?:https?:)?\/\//, 'https://' ) );
 		}
 		}
 		if ( fragment && embed.length < 4750 && embed.fields.length < 25 &&
 		if ( fragment && embed.length < 4750 && embed.fields.length < 25 &&
 		toSection(embed.fields[0]?.name.replace( /^\**_*(.*?)_*\**$/g, '$1' )) !== toSection(fragment) ) {
 		toSection(embed.fields[0]?.name.replace( /^\**_*(.*?)_*\**$/g, '$1' )) !== toSection(fragment) ) {
@@ -202,16 +193,13 @@ function parse_page(msg, {title, contentmodel}, embed, wiki, thumbnail, fragment
 				if ( value.length > 1000 ) value = limitLength(value, 1000, 20);
 				if ( value.length > 1000 ) value = limitLength(value, 1000, 20);
 				if ( name.length && value.length ) {
 				if ( name.length && value.length ) {
 					embed.spliceFields( 0, 0, {name, value} );
 					embed.spliceFields( 0, 0, {name, value} );
-					change = true;
 				}
 				}
 				else if ( embed.backupField ) {
 				else if ( embed.backupField ) {
 					embed.spliceFields( 0, 0, embed.backupField );
 					embed.spliceFields( 0, 0, embed.backupField );
-					change = true;
 				}
 				}
 			}
 			}
 			else if ( embed.backupField ) {
 			else if ( embed.backupField ) {
 				embed.spliceFields( 0, 0, embed.backupField );
 				embed.spliceFields( 0, 0, embed.backupField );
-				change = true;
 			}
 			}
 		}
 		}
 		if ( !embed.description && embed.length < 5000 ) {
 		if ( !embed.description && embed.length < 5000 ) {
@@ -223,25 +211,23 @@ function parse_page(msg, {title, contentmodel}, embed, wiki, thumbnail, fragment
 			if ( description ) {
 			if ( description ) {
 				if ( description.length > 1000 ) description = limitLength(description, 1000, 500);
 				if ( description.length > 1000 ) description = limitLength(description, 1000, 500);
 				embed.setDescription( description );
 				embed.setDescription( description );
-				change = true;
 			}
 			}
 			else if ( embed.backupDescription ) {
 			else if ( embed.backupDescription ) {
 				embed.setDescription( embed.backupDescription );
 				embed.setDescription( embed.backupDescription );
-				change = true;
 			}
 			}
 		}
 		}
 	}, error => {
 	}, error => {
 		console.log( '- Error while parsing the page: ' + error );
 		console.log( '- Error while parsing the page: ' + error );
 		if ( embed.backupDescription && embed.length < 5000 ) {
 		if ( embed.backupDescription && embed.length < 5000 ) {
 			embed.setDescription( embed.backupDescription );
 			embed.setDescription( embed.backupDescription );
-			change = true;
 		}
 		}
 		if ( embed.backupField && embed.length < 4750 && embed.fields.length < 25 ) {
 		if ( embed.backupField && embed.length < 4750 && embed.fields.length < 25 ) {
 			embed.spliceFields( 0, 0, embed.backupField );
 			embed.spliceFields( 0, 0, embed.backupField );
-			change = true;
 		}
 		}
 	} ).finally( () => {
 	} ).finally( () => {
-		if ( change ) msg.edit( msg.content, {embed,allowedMentions:{parse:[]}} ).catch(log_error);
+		msg.sendChannel( content, {embed} );
+
+		if ( reaction ) reaction.removeEmoji();
 	} );
 	} );
 }
 }