Markus-Rost 3 سال پیش
والد
کامیت
b7110c807e
6فایلهای تغییر یافته به همراه18 افزوده شده و 3 حذف شده
  1. 1 1
      bot.js
  2. 1 0
      cmds/eval.js
  3. 12 2
      dashboard/oauth.js
  4. 2 0
      dashboard/rcscript.js
  5. 1 0
      dashboard/settings.js
  6. 1 0
      util/wiki.js

+ 1 - 1
bot.js

@@ -282,7 +282,7 @@ function messageCreate(msg) {
 				console.log( msg.guildId + ': Missing permissions - ' + missing.join(', ') );
 				if ( !missing.includes( 'SEND_MESSAGES' ) && !missing.includes( 'SEND_MESSAGES_IN_THREADS' ) ) {
 					db.query( 'SELECT lang FROM discord WHERE guild = $1 AND (channel = $2 OR channel = $3 OR channel IS NULL) ORDER BY channel DESC NULLS LAST LIMIT 1', sqlargs ).then( ({rows:[row]}) => {
-						return row.lang;
+						return row?.lang;
 					}, dberror => {
 						console.log( '- Error while getting the lang: ' + dberror );
 					} ).then( lang => {

+ 1 - 0
cmds/eval.js

@@ -59,6 +59,7 @@ function database(sql, sqlargs = []) {
  */
 function checkWiki(wiki) {
 	wiki = Wiki.fromInput(wiki);
+	if ( !wiki ) return `Couldn't resolve "${wiki}" into a valid url.`;
 	return got.get( wiki + 'api.php?&action=query&meta=siteinfo&siprop=general&list=recentchanges&rcshow=!bot&rctype=edit|new|log|categorize&rcprop=ids|timestamp&rclimit=100&format=json' ).then( response => {
 		if ( response.statusCode === 404 && typeof response.body === 'string' ) {
 			let api = cheerio.load(response.body)('head link[rel="EditURI"]').prop('href');

+ 12 - 2
dashboard/oauth.js

@@ -255,14 +255,24 @@ function dashboard_api(res, input) {
 		api: true,
 		error: false,
 		error_code: '',
-		wiki: wiki.href,
+		wiki: wiki?.href,
 		base: '',
 		sitename: '',
 		logo: '',
 		MediaWiki: false,
 		RcGcDw: '',
-		customRcGcDw: wiki.toLink('MediaWiki:Custom-RcGcDw', 'action=edit')
+		customRcGcDw: wiki?.toLink('MediaWiki:Custom-RcGcDw', 'action=edit')
 	};
+	if ( !wiki ) {
+		result.error = true;
+		let body = JSON.stringify(result);
+		res.writeHead(200, {
+			'Content-Length': Buffer.byteLength(body),
+			'Content-Type': 'application/json'
+		});
+		res.write( body );
+		return res.end();
+	}
 	return got.get( wiki + 'api.php?&action=query&meta=allmessages|siteinfo&ammessages=custom-RcGcDw&amenableparser=true&siprop=general&format=json', {
 		responseType: 'text'
 	} ).then( response => {

+ 2 - 0
dashboard/rcscript.js

@@ -378,6 +378,7 @@ function update_rcscript(res, userSettings, guild, type, settings) {
 				return res(`/guild/${guild}/rcscript`, 'savefail');
 			}
 			var wiki = Wiki.fromInput(settings.wiki);
+			if ( !wiki ) return res(`/guild/${guild}/rcscript/new`, 'savefail');
 			return got.get( wiki + 'api.php?&action=query&meta=allmessages|siteinfo&ammessages=custom-RcGcDw|recentchanges&amenableparser=true&siprop=general&titles=Special:RecentChanges&format=json', {
 				responseType: 'text'
 			} ).then( fresponse => {
@@ -622,6 +623,7 @@ function update_rcscript(res, userSettings, guild, type, settings) {
 				if ( ( row.postid === '-1' ) !== !settings.feeds ) hasDiff = true;
 				if ( !hasDiff ) return res(`/guild/${guild}/rcscript/${type}`, 'save');
 				var wiki = Wiki.fromInput(settings.wiki);
+				if ( !wiki ) return res(`/guild/${guild}/rcscript/${type}`, 'savefail');
 				return got.get( wiki + 'api.php?&action=query&meta=allmessages|siteinfo&ammessages=custom-RcGcDw&amenableparser=true&siprop=general&format=json', {
 					responseType: 'text'
 				} ).then( fresponse => {

+ 1 - 0
dashboard/settings.js

@@ -346,6 +346,7 @@ function update_settings(res, userSettings, guild, type, settings) {
 			return res(`/guild/${guild}/settings/${type}`, 'savefail');
 		} );
 		var wiki = Wiki.fromInput(settings.wiki);
+		if ( !wiki ) return res(`/guild/${guild}/settings`, 'savefail');
 		var embed;
 		return got.get( wiki + 'api.php?&action=query&meta=siteinfo&siprop=general&format=json', {
 			responseType: 'text'

+ 1 - 0
util/wiki.js

@@ -255,6 +255,7 @@ export default class Wiki extends URL {
 				if ( !input.includes( '.' ) ) return new Wiki('https://' + input + '.fandom.com/');
 				else return new Wiki('https://' + input.split('.')[1] + '.fandom.com/' + input.split('.')[0] + '/');
 			}
+			return null;
 		}
 		catch {
 			return null;