|
@@ -95,148 +95,147 @@ function newMessage(msg, lang, wiki = defaultSettings.wiki, prefix = process.env
|
|
|
return cmdmap.LINK(lang, msg, line, wiki);
|
|
|
} );
|
|
|
|
|
|
- if ( ( channel.type !== 'text' || !pause[msg.guild.id] ) && !noInline && ( cont.includes( '[[' ) || cont.includes( '{{' ) ) ) {
|
|
|
- var links = [];
|
|
|
- var embeds = [];
|
|
|
- var linkcount = 0;
|
|
|
- var linkmaxcount = maxcount + 5;
|
|
|
- msg.cleanContent.replace( /\u200b/g, '' ).replace( /(?<!\\)```.+?```/gs, '<codeblock>' ).replace( /(?<!\\)`.+?`/gs, '<code>' ).split('\n').forEach( line => {
|
|
|
- if ( line.hasPrefix(prefix) || !( line.includes( '[[' ) || line.includes( '{{' ) ) ) return;
|
|
|
- if ( line.includes( '[[' ) && line.includes( ']]' ) && linkcount <= linkmaxcount ) {
|
|
|
- let regex = new RegExp( '(?<!\\\\)(|\\|\\|)\\[\\[([^' + "<>\\[\\]\\|{}\\x01-\\x1F\\x7F" + ']+)(?<!\\\\)\\]\\]\\1', 'g' );
|
|
|
- let entry = null;
|
|
|
- while ( ( entry = regex.exec(line) ) !== null ) {
|
|
|
- if ( linkcount < linkmaxcount ) {
|
|
|
- linkcount++;
|
|
|
- console.log( ( channel.type === 'text' ? msg.guild.id : '@' + author.id ) + ': ' + entry[0] );
|
|
|
- let title = entry[2].split('#')[0];
|
|
|
- let section = ( entry[2].includes( '#' ) ? entry[2].split('#').slice(1).join('#') : '' )
|
|
|
- links.push({title,section,spoiler:entry[1]});
|
|
|
- }
|
|
|
- else if ( linkcount === linkmaxcount ) {
|
|
|
- linkcount++;
|
|
|
- console.log( '- Message contains too many links!' );
|
|
|
- msg.reactEmoji('⚠️');
|
|
|
- break;
|
|
|
- }
|
|
|
+ if ( ( channel.type !== 'text' || !pause[msg.guild.id] ) && !noInline && ( cont.includes( '[[' ) || cont.includes( '{{' ) ) ) {
|
|
|
+ var links = [];
|
|
|
+ var embeds = [];
|
|
|
+ var linkcount = 0;
|
|
|
+ var linkmaxcount = maxcount + 5;
|
|
|
+ var breakInline = false;
|
|
|
+ msg.cleanContent.replace( /\u200b/g, '' ).replace( /(?<!\\)```.+?```/gs, '<codeblock>' ).replace( /(?<!\\)`.+?`/gs, '<code>' ).split('\n').forEach( line => {
|
|
|
+ if ( line.startsWith( '>>> ' ) ) breakinline = true;
|
|
|
+ if ( line.startsWith( '> ' ) || breakInline ) return;
|
|
|
+ if ( line.hasPrefix(prefix) || !( line.includes( '[[' ) || line.includes( '{{' ) ) ) return;
|
|
|
+ if ( line.includes( '[[' ) && line.includes( ']]' ) && linkcount <= linkmaxcount ) {
|
|
|
+ let regex = new RegExp( '(?<!\\\\)(|\\|\\|)\\[\\[([^' + "<>\\[\\]\\|{}\\x01-\\x1F\\x7F" + ']+)(?<!\\\\)\\]\\]\\1', 'g' );
|
|
|
+ let entry = null;
|
|
|
+ while ( ( entry = regex.exec(line) ) !== null ) {
|
|
|
+ if ( linkcount < linkmaxcount ) {
|
|
|
+ linkcount++;
|
|
|
+ console.log( ( channel.type === 'text' ? msg.guild.id : '@' + author.id ) + ': ' + entry[0] );
|
|
|
+ let title = entry[2].split('#')[0];
|
|
|
+ let section = ( entry[2].includes( '#' ) ? entry[2].split('#').slice(1).join('#') : '' )
|
|
|
+ links.push({title,section,spoiler:entry[1]});
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if ( line.includes( '{{' ) && line.includes( '}}' ) && count <= maxcount ) {
|
|
|
- let regex = new RegExp( '(?<!\\\\)(|\\|\\|)(?<!\\{)\\{\\{([^' + "<>\\[\\]\\|{}\\x01-\\x1F\\x7F" + ']+)(?<!\\\\)\\}\\}\\1', 'g' );
|
|
|
- let entry = null;
|
|
|
- while ( ( entry = regex.exec(line) ) !== null ) {
|
|
|
- if ( count < maxcount ) {
|
|
|
- count++;
|
|
|
- console.log( ( channel.type === 'text' ? msg.guild.id : '@' + author.id ) + ': ' + entry[0] );
|
|
|
- let title = entry[2].split('#')[0];
|
|
|
- let section = ( entry[2].includes( '#' ) ? entry[2].split('#').slice(1).join('#') : '' )
|
|
|
- embeds.push({title,section,spoiler:entry[1]});
|
|
|
- }
|
|
|
- else if ( count === maxcount ) {
|
|
|
- count++;
|
|
|
- console.log( '- Message contains too many links!' );
|
|
|
- msg.reactEmoji('⚠️');
|
|
|
- break;
|
|
|
- }
|
|
|
+ else if ( linkcount === linkmaxcount ) {
|
|
|
+ linkcount++;
|
|
|
+ console.log( '- Message contains too many links!' );
|
|
|
+ msg.reactEmoji('⚠️');
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
- } );
|
|
|
-
|
|
|
- if ( links.length ) got.get( wiki + 'api.php?action=query&meta=siteinfo&siprop=general&iwurl=true&titles=' + encodeURIComponent( links.map( link => link.title ).join('|') ) + '&format=json', {
|
|
|
- responseType: 'json'
|
|
|
- } ).then( response => {
|
|
|
- var body = response.body;
|
|
|
- if ( response.statusCode !== 200 || !body || !body.query ) {
|
|
|
- if ( wiki.noWiki(response.url) || response.statusCode === 410 ) {
|
|
|
- console.log( '- This wiki doesn\'t exist!' );
|
|
|
- msg.reactEmoji('nowiki');
|
|
|
- return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( line.includes( '{{' ) && line.includes( '}}' ) && count <= maxcount ) {
|
|
|
+ let regex = new RegExp( '(?<!\\\\)(|\\|\\|)(?<!\\{)\\{\\{([^' + "<>\\[\\]\\|{}\\x01-\\x1F\\x7F" + ']+)(?<!\\\\)\\}\\}\\1', 'g' );
|
|
|
+ let entry = null;
|
|
|
+ while ( ( entry = regex.exec(line) ) !== null ) {
|
|
|
+ if ( count < maxcount ) {
|
|
|
+ count++;
|
|
|
+ console.log( ( channel.type === 'text' ? msg.guild.id : '@' + author.id ) + ': ' + entry[0] );
|
|
|
+ let title = entry[2].split('#')[0];
|
|
|
+ let section = ( entry[2].includes( '#' ) ? entry[2].split('#').slice(1).join('#') : '' )
|
|
|
+ embeds.push({title,section,spoiler:entry[1]});
|
|
|
+ }
|
|
|
+ else if ( count === maxcount ) {
|
|
|
+ count++;
|
|
|
+ console.log( '- Message contains too many links!' );
|
|
|
+ msg.reactEmoji('⚠️');
|
|
|
+ break;
|
|
|
}
|
|
|
- console.log( '- ' + response.statusCode + ': Error while following the links: ' + ( body && body.error && body.error.info ) );
|
|
|
- return;
|
|
|
- }
|
|
|
- if ( body.query.normalized ) {
|
|
|
- body.query.normalized.forEach( title => links.filter( link => link.title === title.from ).forEach( link => link.title = title.to ) );
|
|
|
- }
|
|
|
- if ( body.query.interwiki ) {
|
|
|
- body.query.interwiki.forEach( interwiki => links.filter( link => link.title === interwiki.title ).forEach( link => {
|
|
|
- link.url = interwiki.url + ( link.section ? '#' + link.section.toSection() : '' );
|
|
|
- } ) );
|
|
|
- }
|
|
|
- if ( body.query.pages ) {
|
|
|
- var querypages = Object.values(body.query.pages);
|
|
|
- querypages.filter( page => page.invalid !== undefined ).forEach( page => links.filter( link => link.title === page.title ).forEach( link => {
|
|
|
- links.splice(links.indexOf(link), 1);
|
|
|
- } ) );
|
|
|
- querypages.filter( page => page.missing !== undefined && page.known === undefined ).forEach( page => links.filter( link => link.title === page.title ).forEach( link => {
|
|
|
- if ( ( page.ns === 2 || page.ns === 202 ) && !page.title.includes( '/' ) ) return;
|
|
|
- link.url = wiki.toLink(link.title, 'action=edit&redlink=1', '', body.query.general);
|
|
|
- } ) );
|
|
|
}
|
|
|
- if ( links.length ) msg.sendChannel( links.map( link => link.spoiler + '<' + ( link.url || wiki.toLink(link.title, '', link.section, body.query.general) ) + '>' + link.spoiler ).join('\n'), {split:true} );
|
|
|
- }, error => {
|
|
|
- if ( wiki.noWiki(error.message) ) {
|
|
|
+ }
|
|
|
+ } );
|
|
|
+
|
|
|
+ if ( links.length ) got.get( wiki + 'api.php?action=query&meta=siteinfo&siprop=general&iwurl=true&titles=' + encodeURIComponent( links.map( link => link.title ).join('|') ) + '&format=json' ).then( response => {
|
|
|
+ var body = response.body;
|
|
|
+ if ( response.statusCode !== 200 || !body || !body.query ) {
|
|
|
+ if ( wiki.noWiki(response.url) || response.statusCode === 410 ) {
|
|
|
console.log( '- This wiki doesn\'t exist!' );
|
|
|
msg.reactEmoji('nowiki');
|
|
|
- }
|
|
|
- else {
|
|
|
- console.log( '- Error while following the links: ' + error );
|
|
|
- }
|
|
|
- } );
|
|
|
-
|
|
|
- if ( embeds.length ) got.get( wiki + 'api.php?action=query&meta=siteinfo&siprop=general' + ( wiki.isFandom() ? '' : '|variables' ) + '&titles=' + encodeURIComponent( embeds.map( embed => embed.title + '|Template:' + embed.title ).join('|') ) + '&format=json', {
|
|
|
- responseType: 'json'
|
|
|
- } ).then( response => {
|
|
|
- var body = response.body;
|
|
|
- if ( response.statusCode !== 200 || !body || !body.query ) {
|
|
|
- if ( wiki.noWiki(response.url) || response.statusCode === 410 ) {
|
|
|
- console.log( '- This wiki doesn\'t exist!' );
|
|
|
- msg.reactEmoji('nowiki');
|
|
|
- return;
|
|
|
- }
|
|
|
- console.log( '- ' + response.statusCode + ': Error while following the links: ' + ( body && body.error && body.error.info ) );
|
|
|
return;
|
|
|
}
|
|
|
- if ( body.query.normalized ) {
|
|
|
- body.query.normalized.forEach( title => embeds.filter( embed => embed.title === title.from ).forEach( embed => embed.title = title.to ) );
|
|
|
- }
|
|
|
- if ( body.query.pages ) {
|
|
|
- var querypages = Object.values(body.query.pages);
|
|
|
- querypages.filter( page => page.invalid !== undefined ).forEach( page => embeds.filter( embed => embed.title === page.title ).forEach( embed => {
|
|
|
- embeds.splice(embeds.indexOf(embed), 1);
|
|
|
- } ) );
|
|
|
- var missing = [];
|
|
|
- querypages.filter( page => page.missing !== undefined && page.known === undefined ).forEach( page => embeds.filter( embed => embed.title === page.title ).forEach( embed => {
|
|
|
- if ( ( page.ns === 2 || page.ns === 202 ) && !page.title.includes( '/' ) ) return;
|
|
|
- embeds.splice(embeds.indexOf(embed), 1);
|
|
|
- if ( page.ns === 0 && !embed.section ) {
|
|
|
- var template = querypages.find( template => template.ns === 10 && template.title.split(':').slice(1).join(':') === embed.title );
|
|
|
- if ( template && template.missing === undefined ) embed.template = wiki.toLink(template.title, '', '', body.query.general);
|
|
|
- }
|
|
|
- if ( embed.template || !body.query.variables || !body.query.variables.some( variable => variable.toUpperCase() === embed.title ) ) missing.push(embed);
|
|
|
- } ) );
|
|
|
- if ( missing.length ) {
|
|
|
- msg.sendChannel( missing.map( embed => embed.spoiler + '<' + ( embed.template || wiki.toLink(embed.title, 'action=edit&redlink=1', '', body.query.general) ) + '>' + embed.spoiler ).join('\n'), {split:true} );
|
|
|
- }
|
|
|
- }
|
|
|
- if ( embeds.length ) {
|
|
|
- if ( wiki.isFandom() ) embeds.forEach( embed => msg.reactEmoji('⏳').then( reaction => {
|
|
|
- check_wiki.fandom(lang, msg, embed.title, wiki, '', reaction, embed.spoiler, '', embed.section);
|
|
|
- } ) );
|
|
|
- else embeds.forEach( embed => msg.reactEmoji('⏳').then( reaction => {
|
|
|
- check_wiki.gamepedia(lang, msg, embed.title, wiki, '', reaction, embed.spoiler, '', embed.section);
|
|
|
- } ) );
|
|
|
- }
|
|
|
- }, error => {
|
|
|
- if ( wiki.noWiki(error.message) ) {
|
|
|
+ console.log( '- ' + response.statusCode + ': Error while following the links: ' + ( body && body.error && body.error.info ) );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if ( body.query.normalized ) {
|
|
|
+ body.query.normalized.forEach( title => links.filter( link => link.title === title.from ).forEach( link => link.title = title.to ) );
|
|
|
+ }
|
|
|
+ if ( body.query.interwiki ) {
|
|
|
+ body.query.interwiki.forEach( interwiki => links.filter( link => link.title === interwiki.title ).forEach( link => {
|
|
|
+ link.url = interwiki.url + ( link.section ? '#' + link.section.toSection() : '' );
|
|
|
+ } ) );
|
|
|
+ }
|
|
|
+ if ( body.query.pages ) {
|
|
|
+ var querypages = Object.values(body.query.pages);
|
|
|
+ querypages.filter( page => page.invalid !== undefined ).forEach( page => links.filter( link => link.title === page.title ).forEach( link => {
|
|
|
+ links.splice(links.indexOf(link), 1);
|
|
|
+ } ) );
|
|
|
+ querypages.filter( page => page.missing !== undefined && page.known === undefined ).forEach( page => links.filter( link => link.title === page.title ).forEach( link => {
|
|
|
+ if ( ( page.ns === 2 || page.ns === 202 ) && !page.title.includes( '/' ) ) return;
|
|
|
+ link.url = wiki.toLink(link.title, 'action=edit&redlink=1', '', body.query.general);
|
|
|
+ } ) );
|
|
|
+ }
|
|
|
+ if ( links.length ) msg.sendChannel( links.map( link => link.spoiler + '<' + ( link.url || wiki.toLink(link.title, '', link.section, body.query.general) ) + '>' + link.spoiler ).join('\n'), {split:true} );
|
|
|
+ }, error => {
|
|
|
+ if ( wiki.noWiki(error.message) ) {
|
|
|
+ console.log( '- This wiki doesn\'t exist!' );
|
|
|
+ msg.reactEmoji('nowiki');
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log( '- Error while following the links: ' + error );
|
|
|
+ }
|
|
|
+ } );
|
|
|
+
|
|
|
+ if ( embeds.length ) got.get( wiki + 'api.php?action=query&meta=siteinfo&siprop=general' + ( wiki.isFandom() ? '' : '|variables' ) + '&titles=' + encodeURIComponent( embeds.map( embed => embed.title + '|Template:' + embed.title ).join('|') ) + '&format=json' ).then( response => {
|
|
|
+ var body = response.body;
|
|
|
+ if ( response.statusCode !== 200 || !body || !body.query ) {
|
|
|
+ if ( wiki.noWiki(response.url) || response.statusCode === 410 ) {
|
|
|
console.log( '- This wiki doesn\'t exist!' );
|
|
|
msg.reactEmoji('nowiki');
|
|
|
+ return;
|
|
|
}
|
|
|
- else {
|
|
|
- console.log( '- Error while following the links: ' + error );
|
|
|
+ console.log( '- ' + response.statusCode + ': Error while following the links: ' + ( body && body.error && body.error.info ) );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if ( body.query.normalized ) {
|
|
|
+ body.query.normalized.forEach( title => embeds.filter( embed => embed.title === title.from ).forEach( embed => embed.title = title.to ) );
|
|
|
+ }
|
|
|
+ if ( body.query.pages ) {
|
|
|
+ var querypages = Object.values(body.query.pages);
|
|
|
+ querypages.filter( page => page.invalid !== undefined ).forEach( page => embeds.filter( embed => embed.title === page.title ).forEach( embed => {
|
|
|
+ embeds.splice(embeds.indexOf(embed), 1);
|
|
|
+ } ) );
|
|
|
+ var missing = [];
|
|
|
+ querypages.filter( page => page.missing !== undefined && page.known === undefined ).forEach( page => embeds.filter( embed => embed.title === page.title ).forEach( embed => {
|
|
|
+ if ( ( page.ns === 2 || page.ns === 202 ) && !page.title.includes( '/' ) ) return;
|
|
|
+ embeds.splice(embeds.indexOf(embed), 1);
|
|
|
+ if ( page.ns === 0 && !embed.section ) {
|
|
|
+ var template = querypages.find( template => template.ns === 10 && template.title.split(':').slice(1).join(':') === embed.title );
|
|
|
+ if ( template && template.missing === undefined ) embed.template = wiki.toLink(template.title, '', '', body.query.general);
|
|
|
+ }
|
|
|
+ if ( embed.template || !body.query.variables || !body.query.variables.some( variable => variable.toUpperCase() === embed.title ) ) missing.push(embed);
|
|
|
+ } ) );
|
|
|
+ if ( missing.length ) {
|
|
|
+ msg.sendChannel( missing.map( embed => embed.spoiler + '<' + ( embed.template || wiki.toLink(embed.title, 'action=edit&redlink=1', '', body.query.general) ) + '>' + embed.spoiler ).join('\n'), {split:true} );
|
|
|
}
|
|
|
- } );
|
|
|
+ }
|
|
|
+ if ( embeds.length ) {
|
|
|
+ if ( wiki.isFandom() ) embeds.forEach( embed => msg.reactEmoji('⏳').then( reaction => {
|
|
|
+ check_wiki.fandom(lang, msg, embed.title, wiki, '', reaction, embed.spoiler, '', embed.section);
|
|
|
+ } ) );
|
|
|
+ else embeds.forEach( embed => msg.reactEmoji('⏳').then( reaction => {
|
|
|
+ check_wiki.gamepedia(lang, msg, embed.title, wiki, '', reaction, embed.spoiler, '', embed.section);
|
|
|
+ } ) );
|
|
|
+ }
|
|
|
+ }, error => {
|
|
|
+ if ( wiki.noWiki(error.message) ) {
|
|
|
+ console.log( '- This wiki doesn\'t exist!' );
|
|
|
+ msg.reactEmoji('nowiki');
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log( '- Error while following the links: ' + error );
|
|
|
+ }
|
|
|
+ } );
|
|
|
}
|
|
|
}
|
|
|
|