|
@@ -14,7 +14,7 @@ const toTitle = require('../util/wiki.js').toTitle;
|
|
|
* @param {String} [gender] - The gender of the user.
|
|
|
*/
|
|
|
function global_block(lang, msg, username, text, embed, wiki, spoiler, gender) {
|
|
|
- if ( !msg || !msg.channel.isGuild() || !( msg.guild.id in patreons ) ) return;
|
|
|
+ if ( !msg || !msg.channel.isGuild() || !( msg.guild.id in patreons ) || !wiki.isFandom() ) return;
|
|
|
|
|
|
var isUser = true;
|
|
|
if ( !gender ) {
|
|
@@ -29,7 +29,7 @@ function global_block(lang, msg, username, text, embed, wiki, spoiler, gender) {
|
|
|
text = splittext.join('\n\n');
|
|
|
}
|
|
|
|
|
|
- if ( wiki.isFandom() ) Promise.all([
|
|
|
+ Promise.all([
|
|
|
got.get( 'https://community.fandom.com/Special:Contributions/' + encodeURIComponent( username ) + '?limit=1', {
|
|
|
responseType: 'text'
|
|
|
} ).then( response => {
|
|
@@ -51,7 +51,7 @@ function global_block(lang, msg, username, text, embed, wiki, spoiler, gender) {
|
|
|
}, error => {
|
|
|
console.log( '- Error while getting the global block: ' + error );
|
|
|
} ),
|
|
|
- ( isUser ? got.get( 'https://community.fandom.com/wiki/Special:Editcount/' + encodeURIComponent( username ), {
|
|
|
+ ( isUser ? ( wiki.isGamepedia() ? got.get( 'https://help.gamepedia.com/UserProfile:' + encodeURIComponent( username ), {
|
|
|
responseType: 'text'
|
|
|
} ).then( gresponse => {
|
|
|
var gbody = gresponse.body;
|
|
@@ -60,7 +60,20 @@ function global_block(lang, msg, username, text, embed, wiki, spoiler, gender) {
|
|
|
}
|
|
|
else {
|
|
|
let $ = cheerio.load(gbody);
|
|
|
- var globaledits = $('#editcount .TablePager th').eq(7).text().replace( /[,\.]/g, '' );
|
|
|
+ var wikisedited = $('.curseprofile .rightcolumn .section.stats dd').eq(0).text().replace( /[,\.]/g, '' );
|
|
|
+ if ( wikisedited ) {
|
|
|
+ if ( msg.showEmbed() ) embed.spliceFields(1, 0, {
|
|
|
+ name: lang.get('user.info.wikisedited'),
|
|
|
+ value: wikisedited,
|
|
|
+ inline: true
|
|
|
+ });
|
|
|
+ else {
|
|
|
+ let splittext = text.split('\n');
|
|
|
+ splittext.splice(5, 0, lang.get('user.info.wikisedited') + ' ' + wikisedited);
|
|
|
+ text = splittext.join('\n');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var globaledits = $('.curseprofile .rightcolumn .section.stats dd').eq(2).text().replace( /[,\.]/g, '' );
|
|
|
if ( globaledits ) {
|
|
|
if ( msg.showEmbed() ) embed.spliceFields(1, 0, {
|
|
|
name: lang.get('user.info.globaleditcount'),
|
|
@@ -73,54 +86,16 @@ function global_block(lang, msg, username, text, embed, wiki, spoiler, gender) {
|
|
|
text = splittext.join('\n');
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- }, error => {
|
|
|
- console.log( '- Error while getting the global edit count: ' + error );
|
|
|
- } ) : undefined )
|
|
|
- ]).finally( () => {
|
|
|
- msg.edit( spoiler + text + spoiler, {embed,allowedMentions:{parse:[]}} ).catch(log_error);
|
|
|
- } );
|
|
|
- else if ( wiki.isGamepedia() ) Promise.all([
|
|
|
- got.get( 'https://commons.gamepedia.com/Special:GlobalBlockList/' + encodeURIComponent( username ) + '?uselang=qqx', {
|
|
|
- responseType: 'text'
|
|
|
- } ).then( response => {
|
|
|
- var body = response.body;
|
|
|
- if ( response.statusCode !== 200 || !body ) {
|
|
|
- console.log( '- ' + response.statusCode + ': Error while getting the global block.' );
|
|
|
- }
|
|
|
- else {
|
|
|
- let $ = cheerio.load(body);
|
|
|
- var gblocklist = $('.mw-blocklist');
|
|
|
- let splittext = text.split('\n\n');
|
|
|
- if ( gblocklist.length ) gblocklist.find('tbody tr').each( (i, gblock) => {
|
|
|
- gblock = $(gblock);
|
|
|
- var reason = gblock.find('.TablePager_col_reason').text().replace( /\)$/, '' ).split(', ');
|
|
|
- var timestamp = new Date(gblock.find('.TablePager_col_timestamp').text().replace( /(\d{2}:\d{2}), (\d{1,2}) \((\w+)\) (\d{4})/, '$3 $2, $4 $1 UTC' )).toLocaleString(lang.get('dateformat'), timeoptions);
|
|
|
- var expiry = gblock.find('.TablePager_col_expiry').text();
|
|
|
- if ( expiry.startsWith( '(infiniteblock)' ) ) expiry = lang.get('user.block.until_infinity');
|
|
|
- else expiry = new Date(expiry.replace( /(\d{2}:\d{2}), (\d{1,2}) \((\w+)\) (\d{4})/, '$3 $2, $4 $1 UTC' )).toLocaleString(lang.get('dateformat'), timeoptions);
|
|
|
- if ( msg.showEmbed() ) {
|
|
|
- var gblocktitle = lang.get('user.gblock.header', username, gender).escapeFormatting();
|
|
|
- var globalblock = embed.fields.find( field => field.inline === false && field.name === lang.get('user.block.header', username, gender).escapeFormatting() && field.value.replace( /\[([^\]]*)\]\([^\)]*\)/g, '$1' ) === lang.get('user.block.' + ( reason.length > 4 ? 'text' : 'noreason' ), timestamp, expiry, reason[1].escapeFormatting(), reason.slice(4).join(', ').escapeFormatting()) );
|
|
|
- if ( globalblock ) globalblock.name = gblocktitle;
|
|
|
- else {
|
|
|
- var block_wiki = reason[3].replace( /Special:BlockList$/, '' );
|
|
|
- var gblocktext = lang.get('user.gblock.' + ( reason.length > 4 ? 'text' : 'noreason' ), timestamp, expiry, '[' + reason[1] + '](' + block_wiki + 'User:' + toTitle(reason[1]) + ')', '[' + reason[2] + '](' + block_wiki + 'Special:Contribs/' + toTitle(username) + ')', reason.slice(4).join(', ').escapeFormatting());
|
|
|
- embed.addField( gblocktitle, gblocktext );
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- var globalblock = splittext.indexOf('**' + lang.get('user.block.header', username, gender).escapeFormatting() + '**\n' + lang.get('user.block.' + ( reason.length > 4 ? 'text' : 'noreason' ), timestamp, expiry, reason[1].escapeFormatting(), reason.slice(4).join(', ').escapeFormatting()));
|
|
|
- if ( globalblock !== -1 ) splittext[globalblock] = '**' + lang.get('user.gblock.header', username, gender).escapeFormatting() + '**\n' + lang.get('user.block.' + ( reason.length > 4 ? 'text' : 'noreason' ), timestamp, expiry, reason[1].escapeFormatting(), reason.slice(4).join(', ').escapeFormatting());
|
|
|
- else splittext.push('**' + lang.get('user.gblock.header', username, gender).escapeFormatting() + '**\n' + lang.get('user.gblock.' + ( reason.length > 4 ? 'text' : 'noreason' ), timestamp, expiry, reason[1].escapeFormatting(), reason[2], reason.slice(4).join(', ').escapeFormatting()));
|
|
|
+ if ( msg.showEmbed() ) {
|
|
|
+ let avatar = $('.curseprofile .mainavatar img').prop('src');
|
|
|
+ if ( avatar ) {
|
|
|
+ embed.setThumbnail( avatar.replace( /^(?:https?:)?\/\//, 'https://' ).replace( '?d=mm&s=96', '?d=' + encodeURIComponent( embed?.thumbnail?.url || '404' ) ) );
|
|
|
}
|
|
|
- } );
|
|
|
- text = splittext.join('\n\n');
|
|
|
+ }
|
|
|
}
|
|
|
}, error => {
|
|
|
- console.log( '- Error while getting the global block: ' + error );
|
|
|
- } ),
|
|
|
- ( isUser ? got.get( 'https://commons.gamepedia.com/UserProfile:' + encodeURIComponent( username ), {
|
|
|
+ console.log( '- Error while getting the global edit count: ' + error );
|
|
|
+ } ) : got.get( 'https://community.fandom.com/wiki/Special:Editcount/' + encodeURIComponent( username ), {
|
|
|
responseType: 'text'
|
|
|
} ).then( gresponse => {
|
|
|
var gbody = gresponse.body;
|
|
@@ -129,20 +104,7 @@ function global_block(lang, msg, username, text, embed, wiki, spoiler, gender) {
|
|
|
}
|
|
|
else {
|
|
|
let $ = cheerio.load(gbody);
|
|
|
- var wikisedited = $('.curseprofile .rightcolumn .section.stats dd').eq(0).text().replace( /[,\.]/g, '' );
|
|
|
- if ( wikisedited ) {
|
|
|
- if ( msg.showEmbed() ) embed.spliceFields(1, 0, {
|
|
|
- name: lang.get('user.info.wikisedited'),
|
|
|
- value: wikisedited,
|
|
|
- inline: true
|
|
|
- });
|
|
|
- else {
|
|
|
- let splittext = text.split('\n');
|
|
|
- splittext.splice(5, 0, lang.get('user.info.wikisedited') + ' ' + wikisedited);
|
|
|
- text = splittext.join('\n');
|
|
|
- }
|
|
|
- }
|
|
|
- var globaledits = $('.curseprofile .rightcolumn .section.stats dd').eq(2).text().replace( /[,\.]/g, '' );
|
|
|
+ var globaledits = $('#editcount .TablePager th').eq(7).text().replace( /[,\.]/g, '' );
|
|
|
if ( globaledits ) {
|
|
|
if ( msg.showEmbed() ) embed.spliceFields(1, 0, {
|
|
|
name: lang.get('user.info.globaleditcount'),
|
|
@@ -155,14 +117,10 @@ function global_block(lang, msg, username, text, embed, wiki, spoiler, gender) {
|
|
|
text = splittext.join('\n');
|
|
|
}
|
|
|
}
|
|
|
- if ( msg.showEmbed() ) {
|
|
|
- var avatar = $('.curseprofile .mainavatar img').prop('src');
|
|
|
- if ( avatar ) embed.setThumbnail( avatar.replace( /^(?:https?:)?\/\//, 'https://' ).replace( '?d=mm&s=96', '?d=404' ) );
|
|
|
- }
|
|
|
}
|
|
|
}, error => {
|
|
|
console.log( '- Error while getting the global edit count: ' + error );
|
|
|
- } ) : undefined )
|
|
|
+ } ) ) : undefined )
|
|
|
]).finally( () => {
|
|
|
msg.edit( spoiler + text + spoiler, {embed,allowedMentions:{parse:[]}} ).catch(log_error);
|
|
|
} );
|