Selaa lähdekoodia

fix some errors and crashes

Markus-Rost 4 vuotta sitten
vanhempi
sitoutus
8a9ad1353d
6 muutettua tiedostoa jossa 24 lisäystä ja 11 poistoa
  1. 17 10
      cmds/verify.js
  2. 4 0
      dashboard/oauth.js
  3. 1 0
      dashboard/settings.js
  4. 1 0
      dashboard/util.js
  5. 1 0
      main.js
  6. 0 1
      util/default.json

+ 17 - 10
cmds/verify.js

@@ -43,7 +43,7 @@ function cmd_verify(lang, msg, args, line, wiki, old_username = '') {
 		if ( !username.trim() ) {
 		if ( !username.trim() ) {
 			args[0] = line.split(' ')[0];
 			args[0] = line.split(' ')[0];
 			if ( args[0] === 'verification' ) args[0] = ( lang.localNames.verify || 'verify' );
 			if ( args[0] === 'verification' ) args[0] = ( lang.localNames.verify || 'verify' );
-			return this.help(lang, msg, args, line);
+			return this.help(lang, msg, args, line, wiki);
 		}
 		}
 		msg.reactEmoji('⏳').then( reaction => got.get( wiki + 'api.php?action=query&meta=siteinfo&siprop=general&list=users&usprop=blockinfo|groups|groupmemberships|editcount|registration&ususers=' + encodeURIComponent( username ) + '&format=json' ).then( response => {
 		msg.reactEmoji('⏳').then( reaction => got.get( wiki + 'api.php?action=query&meta=siteinfo&siprop=general&list=users&usprop=blockinfo|groups|groupmemberships|editcount|registration&ususers=' + encodeURIComponent( username ) + '&format=json' ).then( response => {
 			var body = response.body;
 			var body = response.body;
@@ -148,15 +148,20 @@ function cmd_verify(lang, msg, args, line, wiki, old_username = '') {
 				console.log( '- Error while getting the global block: ' + error );
 				console.log( '- Error while getting the global block: ' + error );
 				comment.push(lang.get('verify.failed_gblock'));
 				comment.push(lang.get('verify.failed_gblock'));
 			} ).then( async () => {
 			} ).then( async () => {
-				// async check for editcount on Gamepedia, workaround for https://gitlab.com/hydrawiki/hydra/-/issues/5054
-				if ( wiki.isGamepedia() || ( wiki.isFandom() && body.query.general.generator.startsWith( 'MediaWiki 1.3' ) ) ) {
-					try {
-						let ucresponse = await got.get( wiki + 'api.php?action=query&list=usercontribs&ucprop=&uclimit=500&ucuser=' + encodeURIComponent( username ) + '&format=json' );
-						if ( !ucresponse.body.continue ) queryuser.editcount = ucresponse.body.query.usercontribs.length;
-					} catch ( ucerror ) {
-						console.log( '- Error while working around the edit count: ' + ucerror )
+				// async check for editcount on Gamepedia and Fandom,
+				// workaround for https://gitlab.com/hydrawiki/hydra/-/issues/5054
+				if ( wiki.isGamepedia() || ( wiki.isFandom() && body.query.general.generator.startsWith( 'MediaWiki 1.3' ) ) ) await got.get( wiki + 'api.php?action=query&list=usercontribs&ucprop=&uclimit=500&ucuser=' + encodeURIComponent( username ) + '&format=json' ).then( ucresponse => {
+					var ucbody = ucresponse.body;
+					if ( ucbody?.warnings ) log_warn(ucbody.warnings);
+					if ( ucresponse.statusCode !== 200 || !ucbody?.query?.usercontribs ) {
+						return console.log( '- ' + ucresponse.statusCode + ': Error while working around the edit count: ' + ucbody?.error?.info );
 					}
 					}
-				}
+					if ( !ucbody.continue || ucbody.query.usercontribs.length > queryuser.editcount ) {
+						queryuser.editcount = ucbody.query.usercontribs.length;
+					}
+				}, ucerror => {
+					console.log( '- Error while working around the edit count: ' + ucerror );
+				} );
 				
 				
 				var options = {};
 				var options = {};
 				if ( wiki.isGamepedia() ) {
 				if ( wiki.isGamepedia() ) {
@@ -290,7 +295,9 @@ function cmd_verify(lang, msg, args, line, wiki, old_username = '') {
 				var revision = Object.values(mwbody.query.pages)[0]?.revisions?.[0];
 				var revision = Object.values(mwbody.query.pages)[0]?.revisions?.[0];
 				
 				
 				var discordname = '';
 				var discordname = '';
-				if ( revision && revision.user === username ) discordname = revision.slots.main['*'].escapeFormatting().replace( /^\s*([^@#:]{2,32}?)\s*#(\d{4,6})\s*$/, '$1#$2' );
+				if ( revision && revision.user === username ) {
+					discordname = ( revision?.slots?.main || revision )['*'].escapeFormatting().replace( /^\s*([^@#:]{2,32}?)\s*#(\d{4,6})\s*$/, '$1#$2' );
+				}
 				if ( discordname.length > 50 ) discordname = discordname.substring(0, 50) + '\u2026';
 				if ( discordname.length > 50 ) discordname = discordname.substring(0, 50) + '\u2026';
 				embed.addField( lang.get('verify.discord', ( msg.author.tag.escapeFormatting() === discordname ? queryuser.gender : 'unknown' )), msg.author.tag.escapeFormatting(), true ).addField( lang.get('verify.wiki', queryuser.gender), ( discordname || lang.get('verify.empty') ), true );
 				embed.addField( lang.get('verify.discord', ( msg.author.tag.escapeFormatting() === discordname ? queryuser.gender : 'unknown' )), msg.author.tag.escapeFormatting(), true ).addField( lang.get('verify.wiki', queryuser.gender), ( discordname || lang.get('verify.empty') ), true );
 				if ( msg.author.tag.escapeFormatting() !== discordname ) {
 				if ( msg.author.tag.escapeFormatting() !== discordname ) {

+ 4 - 0
dashboard/oauth.js

@@ -93,6 +93,10 @@ function dashboard_login(res, state, action) {
  * @param {String} [lastGuild] - The guild to return to
  * @param {String} [lastGuild] - The guild to return to
  */
  */
 function dashboard_oauth(res, state, searchParams, lastGuild) {
 function dashboard_oauth(res, state, searchParams, lastGuild) {
+	if ( searchParams.get('error') === 'access_denied' && state === searchParams.get('state') && settingsData.has(state) ) {
+		res.writeHead(302, {Location: '/'});
+		return res.end();
+	}
 	if ( state !== searchParams.get('state') || !searchParams.get('code') ) {
 	if ( state !== searchParams.get('state') || !searchParams.get('code') ) {
 		res.writeHead(302, {Location: '/login?action=failed'});
 		res.writeHead(302, {Location: '/login?action=failed'});
 		return res.end();
 		return res.end();

+ 1 - 0
dashboard/settings.js

@@ -100,6 +100,7 @@ function dashboard_settings(res, $, guild, args) {
 		if ( dberror ) {
 		if ( dberror ) {
 			console.log( '- Dashboard: Error while getting the settings: ' + dberror );
 			console.log( '- Dashboard: Error while getting the settings: ' + dberror );
 			$('#text .description').text('Failed to load the settings!');
 			$('#text .description').text('Failed to load the settings!');
+			$('.channel#settings').addClass('selected');
 			let body = $.html();
 			let body = $.html();
 			res.writeHead(200, {'Content-Length': body.length});
 			res.writeHead(200, {'Content-Length': body.length});
 			res.write( body );
 			res.write( body );

+ 1 - 0
dashboard/util.js

@@ -35,6 +35,7 @@ const db = new sqlite3.Database( './wikibot.db', mode, dberror => {
  * @property {String} acronym
  * @property {String} acronym
  * @property {String} [icon]
  * @property {String} [icon]
  * @property {String} userPermissions
  * @property {String} userPermissions
+ * @property {Boolean} [patreon]
  * @property {String} [botPermissions]
  * @property {String} [botPermissions]
  * @property {{id: String, name: String, permissions: Number}[]} [channels]
  * @property {{id: String, name: String, permissions: Number}[]} [channels]
  * @property {{id: String, name: String, lower: Boolean}[]} [roles]
  * @property {{id: String, name: String, lower: Boolean}[]} [roles]

+ 1 - 0
main.js

@@ -87,6 +87,7 @@ if ( process.env.dashboard ) {
 								let guild = this.guilds.cache.get(id);
 								let guild = this.guilds.cache.get(id);
 								return guild.members.fetch('${message.data.member}').then( member => {
 								return guild.members.fetch('${message.data.member}').then( member => {
 									return {
 									return {
+										patreon: guild.id in global.patreons,
 										botPermissions: guild.me.permissions.bitfield,
 										botPermissions: guild.me.permissions.bitfield,
 										channels: guild.channels.cache.filter( channel => {
 										channels: guild.channels.cache.filter( channel => {
 											return channel.isGuild();
 											return channel.isGuild();

+ 0 - 1
util/default.json

@@ -40,7 +40,6 @@
 		"global_bot",
 		"global_bot",
 		"hydra_staff",
 		"hydra_staff",
 		"wiki_manager",
 		"wiki_manager",
-		"content_team_member",
 		"grasp",
 		"grasp",
 		"bot-global",
 		"bot-global",
 		"staff",
 		"staff",