Parcourir la source

Added custom embeds

* Added custom embeds for search links
* Removed `!wiki user MarkusRost` command
* `!wiki User:MarkusRost` works now with the namespace alias of the related wiki and not only the one from the server language
Markus-Rost il y a 6 ans
Parent
commit
648edb4fdf
4 fichiers modifiés avec 131 ajouts et 140 suppressions
  1. 6 0
      .gitignore
  2. 0 42
      i18n.json
  3. 105 95
      main.js
  4. 20 3
      package.json

+ 6 - 0
.gitignore

@@ -0,0 +1,6 @@
+
+.env
+config*
+node_modules*
+*.bat
+package-lock.json

+ 0 - 42
i18n.json

@@ -64,7 +64,6 @@
 			"left": "%1$s left the voice channel \"%2$s\"."
 		},
 		"user": {
-			"talk": "talk:",
 			"gender": {
 				"unknown": "Unknown",
 				"male": "Male",
@@ -104,11 +103,6 @@
 		"search": {
 			"page": "page",
 			"search": "search",
-			"user": {
-				"unknown": "user",
-				"male": "user",
-				"female": "user"
-			},
 			"infopage": "Not the correct result? Use %s for a direct link.",
 			"infosearch": "Not the correct result? Use %1$s for a direct link or %2$s for a list of all hits."
 		},
@@ -142,7 +136,6 @@
 				{ "cmd": "<search term>", "desc": "I will answer with a link to a matching article in the wiki.", "unsearchable": true },
 				{ "cmd": "!<wiki> <search term>", "desc": "I will answer with a link to a matching article in the named Gamepedia wiki: `https://<wiki>.gamepedia.com/`", "unsearchable": true },
 				{ "cmd": "User:<username>", "desc": "I will show some information about the user.", "unsearchable": true },
-				{ "cmd": "user <username>", "desc": "I will show some information about the user.", "hide": true },
 				{ "cmd": "diff <diff> [<oldid>]", "desc": "I will answer with a link to the diff in the wiki." },
 				{ "cmd": "diff <page name>", "desc": "I will answer with a link to the last diff on the article in the wiki." },
 				{ "cmd": "random", "desc": "I will answer with a link to a random page in the wiki." },
@@ -212,7 +205,6 @@
 			"left": "%1$s hat den Sprachkanal \"%2$s\" verlassen."
 		},
 		"user": {
-			"talk": "diskussion:",
 			"gender": {
 				"unknown": "Unbekannt",
 				"male": "Männlich",
@@ -252,11 +244,6 @@
 		"search": {
 			"page": "seite",
 			"search": "suche",
-			"user": {
-				"unknown": "benutzer",
-				"male": "benutzer",
-				"female": "benutzerin"
-			},
 			"infopage": "Nicht das richtige Ergebnis? Nutze %s für einen direkten Link.",
 			"infosearch": "Nicht das richtige Ergebnis? Nutze %1$s für einen direkten Link oder %2$s für eine Liste mit allen Treffern."
 		},
@@ -291,9 +278,6 @@
 				{ "cmd": "<Suchbegriff>", "desc": "Ich antworte mit einem Link auf einen passenden Artikel im Wiki.", "unsearchable": true },
 				{ "cmd": "!<Wiki> <Suchbegriff>", "desc": "Ich antworte mit einem Link auf einen passenden Artikel im angegebenen Gamepedia-Wiki: `https://<Wiki>.gamepedia.com/`", "unsearchable": true },
 				{ "cmd": "Benutzer:<Benutzername>", "desc": "Ich liste ein paar Informationen über den Benutzer auf.", "unsearchable": true },
-				{ "cmd": "benutzer <Benutzername>", "desc": "Ich liste ein paar Informationen über den Benutzer auf.", "hide": true },
-				{ "cmd": "benutzerin <Benutzername>", "desc": "Ich liste ein paar Informationen über den Benutzer auf.", "hide": true },
-				{ "cmd": "user <Benutzername>", "desc": "Ich liste ein paar Informationen über den Benutzer auf.", "hide": true },
 				{ "cmd": "diff <diff> [<oldid>]", "desc": "Ich verlinke auf die Änderung im Wiki." },
 				{ "cmd": "diff <Seitenname>", "desc": "Ich verlinke auf die letzte Änderung an der Seite im Wiki." },
 				{ "cmd": "random", "desc": "Ich antworte mit einem Link auf eine zufällige Seite im Wiki." },
@@ -373,7 +357,6 @@
 			"left": "%1$s a quitté le salon vocal \"%2$s\"."
 		},
 		"user": {
-			"talk": "discussion:",
 			"gender": {
 				"unknown": "Inconnu",
 				"male": "Homme",
@@ -413,11 +396,6 @@
 		"search": {
 			"page": "page",
 			"search": "chercher",
-			"user": {
-				"unknown": "utilisateur",
-				"male": "utilisateur",
-				"female": "utilisatrice"
-			},
 			"infopage": "Pas le bon résultat ? Utilisez %s pour un lien direct.",
 			"infosearch": "Pas le bon résultat ? Utilisez %1$s pour un lien direct ou %2$s pour une liste de toutes les correspondances."
 		},
@@ -451,8 +429,6 @@
 				{ "cmd": "<terme de recherche>", "desc": "Je vais répondre avec un lien vers un article correspondant sur Wiki.", "unsearchable": true },
 				{ "cmd": "!<wiki> <terme de recherche>", "desc": "Je vais répondre avec un lien vers un article correspondant sur wiki Gamepedia nommé : `https://<wiki>.gamepedia.com/`", "unsearchable": true },
 				{ "cmd": "Utilisateur:<nom d'utilisateur>", "desc": "Je vais montrer quelques informations sur l'utilisateur.", "unsearchable": true },
-				{ "cmd": "utilisateur <nom d'utilisateur>", "desc": "Je vais montrer quelques informations sur l'utilisateur.", "hide": true },
-				{ "cmd": "user <nom d'utilisateur>", "desc": "Je vais montrer quelques informations sur l'utilisateur.", "hide": true },
 				{ "cmd": "diff <diff> [<oldid>]", "desc": "Je vais répondre avec un lien vers la diff sur Wiki." },
 				{ "cmd": "diff <nom de la page>", "desc": "Je vais répondre avec un lien vers la dernière diff de l'article sur Wiki." },
 				{ "cmd": "random", "desc": "Je vais répondre avec un lien vers une page du Wiki au hasard." },
@@ -530,7 +506,6 @@
 			"left": "%1$s wyszedł z \"%2$s\"."
 		},
 		"user": {
-			"talk": "dyskusja:",
 			"gender": {
 				"unknown": "Nieznane",
 				"male": "Mężczyzna",
@@ -570,11 +545,6 @@
 		"search": {
 			"page": "strona",
 			"search": "szukaj",
-			"user": {
-				"unknown": "użytkownik",
-				"male": "użytkownik",
-				"female": "użytkowniczka"
-			},
 			"infopage": "Nie to czego szukałeś? Użyj %s dla bezpośredniego linku.",
 			"infosearch": "Nie to czego szukałeś? Użyj %1$s dla bezpośredniego linku lub %2$s dla listy wszystkich wyników."
 		},
@@ -608,9 +578,6 @@
 				{ "cmd": "<wyszukiwana fraza>", "desc": "Odpowiem linkiem do pasujacego artykułu na Wiki.", "unsearchable": true },
 				{ "cmd": "!<wiki> <wyszukiwana fraza>", "desc": "Odpowiem z pasującym linkiem do podanej wiki na Gamepedii: `https://<wiki>.gamepedia.com/`", "unsearchable": true },
 				{ "cmd": "Użytkownik:<nazwa użytkownika>", "desc": "Pokażę informacje na temat użytkownika.", "unsearchable": true },
-				{ "cmd": "użytkownik <nazwa użytkownika>", "desc": "Pokażę informacje na temat użytkownika.", "hide": true },
-				{ "cmd": "użytkowniczka <nazwa użytkownika>", "desc": "Pokażę informacje na temat użytkownika.", "hide": true },
-				{ "cmd": "user <nazwa użytkownika>", "desc": "Pokażę informacje na temat użytkownika.", "hide": true },
 				{ "cmd": "diff <diff> [<oldid>]", "desc": "Odpowiem linkiem do podanej zmiany na Wiki." },
 				{ "cmd": "diff <nazwa strony>", "desc": "Odpowiem linkiem do ostatniej zmiany w podanym artykule na Wiki." },
 				{ "cmd": "random", "desc": "Odpowiem linkiem do losowej strony na wiki." },
@@ -696,7 +663,6 @@
 			"left": "%1$s deixou o canal de voz \"%2$s\"."
 		},
 		"user": {
-			"talk": "discussão:",
 			"gender": {
 				"unknown": "Desconhecido",
 				"male": "Masculino",
@@ -736,11 +702,6 @@
 		"search": {
 			"page": "página",
 			"search": "pesquisar",
-			"user": {
-				"unknown": "usuário",
-				"male": "usuário",
-				"female": "usuária"
-			},
 			"infopage": "Não é o resultado correto? Use %s para um link direto.",
 			"infosearch": "Não é o resultado correto? Use %1$s para um link direto ou %2$s para uma lista de todos os acessos."
 		},
@@ -774,9 +735,6 @@
 				{ "cmd": "<termo de pesquisa>", "desc": "Eu vou responder com um link para um artigo correspondente no wiki.", "unsearchable": true },
 				{ "cmd": "!<wiki> <termo de pesquisa>", "desc": "Vou responder com um link para um artigo correspondente na wiki da Gamepedia: `https://<wiki>.gamepedia.com/`", "unsearchable": true },
 				{ "cmd": "Usuário:<username>", "desc": "Vou mostrar algumas informações sobre o usuário.", "unsearchable": true },
-				{ "cmd": "usuário <username>", "desc": "Vou mostrar algumas informações sobre o usuário.", "hide": true },
-				{ "cmd": "usuária <username>", "desc": "Vou mostrar algumas informações sobre o usuário.", "hide": true },
-				{ "cmd": "user <username>", "desc": "Vou mostrar algumas informações sobre o usuário.", "hide": true },
 				{ "cmd": "diff <diff> [<oldid>]", "desc": "Vou responder com um link para o diff na wiki." },
 				{ "cmd": "diff <page name>", "desc": "Vou responder com um link para o último diff no artigo na wiki." },
 				{ "cmd": "random", "desc": "Vou responder com um link para uma página aleatória na wiki." },

+ 105 - 95
main.js

@@ -1,3 +1,4 @@
+require('dotenv').config();
 const fs = require('fs');
 const util = require('util');
 util.inspect.defaultOptions = {compact:false,breakLength:Infinity};
@@ -75,9 +76,9 @@ function getAllSites() {
 }
 
 client.on('ready', () => {
+	console.log( '- Erfolgreich als ' + client.user.username + ' angemeldet!' );
 	getSettings(setStatus);
 	getAllSites();
-	console.log( '- Erfolgreich als ' + client.user.username + ' angemeldet!' );
 } );
 
 dbl.on('posted', () => {
@@ -450,7 +451,6 @@ function cmd_delete(lang, msg, args, line) {
 function cmd_link(lang, msg, title, wiki = lang.link, cmd = ' ', querystring = '', fragment = '') {
 	if ( cmd == ' ' && admin(msg) && !( msg.guild.id in settings ) ) {
 		cmd_settings(lang, msg, [], '');
-		cmd_helpserver(lang, msg);
 	}
 	if ( title.includes( '#' ) ) {
 		fragment = title.split('#').slice(1).join('#');
@@ -479,19 +479,13 @@ function cmd_link(lang, msg, title, wiki = lang.link, cmd = ' ', querystring = '
 	else if ( invoke == 'page' || invoke == lang.search.page ) msg.channel.send( '<https://' + wiki + '.gamepedia.com/' + args.join('_').toTitle() + linksuffix + '>' );
 	else if ( invoke == 'search' || invoke == lang.search.search ) msg.channel.send( '<https://' + wiki + '.gamepedia.com/Special:Search/' + args.join('_').toTitle() + linksuffix + '>' );
 	else if ( invoke == 'diff' ) cmd_diff(lang, msg, args, wiki);
-	else if ( !msg.notuser && ( invoke == 'user' || invoke == lang.search.user.unknown || invoke == lang.search.user.male || invoke == lang.search.user.female ) ) cmd_user(lang, msg, args.join('_').toTitle(), wiki, title.toTitle(), cmd, querystring, fragment);
-	else if ( !msg.notuser && invoke.startsWith('user:') ) cmd_user(lang, msg, title.substr(5).toTitle(), wiki, title.toTitle(), cmd, querystring, fragment);
-	else if ( !msg.notuser && invoke.startsWith('userprofile:') ) cmd_user(lang, msg, title.substr(12).toTitle(), wiki, title.toTitle(), cmd, querystring, fragment);
-	else if ( !msg.notuser && invoke.startsWith(lang.search.user.unknown + ':') ) cmd_user(lang, msg, title.substr(lang.search.user.unknown.length + 1).toTitle(), wiki, title.toTitle(), cmd, querystring, fragment);
-	else if ( !msg.notuser && invoke.startsWith(lang.search.user.male + ':') ) cmd_user(lang, msg, title.substr(lang.search.user.male.length + 1).toTitle(), wiki, title.toTitle(), cmd, querystring, fragment);
-	else if ( !msg.notuser && invoke.startsWith(lang.search.user.female + ':') ) cmd_user(lang, msg, title.substr(lang.search.user.female.length + 1).toTitle(), wiki, title.toTitle(), cmd, querystring, fragment);
 	else {
 		msg.reactEmoji('⏳').then( function( reaction ) {
 			request( {
-				uri: 'https://' + wiki + '.gamepedia.com/api.php?action=query&format=json&meta=siteinfo&siprop=general&iwurl=true&redirects=true&titles=' + encodeURIComponent( title ),
+				uri: 'https://' + wiki + '.gamepedia.com/api.php?action=query&format=json&meta=siteinfo&siprop=general&iwurl=true&redirects=true&prop=pageimages|extracts&exintro=true&explaintext=true&titles=' + encodeURIComponent( title ),
 				json: true
 			}, function( error, response, body ) {
-				if ( error || !response || !body || !body.query ) {
+				if ( error || !response || !body || body.batchcomplete == undefined || !body.query ) {
 					if ( response && response.request && response.request.uri && response.request.uri.href == 'https://www.gamepedia.com/' ) {
 						console.log( '- Dieses Wiki existiert nicht! ' + ( error ? error.message : ( body ? ( body.error ? body.error.info : '' ) : '' ) ) );
 						msg.reactEmoji('nowiki');
@@ -503,36 +497,57 @@ function cmd_link(lang, msg, title, wiki = lang.link, cmd = ' ', querystring = '
 				}
 				else {
 					if ( body.query.pages ) {
-						if ( body.query.pages['-1'] && ( ( body.query.pages['-1'].missing != undefined && body.query.pages['-1'].known == undefined ) || body.query.pages['-1'].invalid != undefined ) ) {
+						var querypage = Object.values(body.query.pages)[0];
+						if ( ( querypage.ns == 2 || querypage.ns == 202 ) && !querypage.title.includes( '/' ) ) {
+							var userparts = querypage.title.toTitle().split(':');
+							cmd_user(lang, msg, userparts[0] + ':', userparts.slice(1).join(':'), wiki);
+						}
+						else if ( body.query.pages['-1'] && ( ( body.query.pages['-1'].missing != undefined && body.query.pages['-1'].known == undefined ) || body.query.pages['-1'].invalid != undefined ) ) {
 							request( {
-								uri: 'https://' + wiki + '.gamepedia.com/api.php?action=query&format=json&list=search&srnamespace=0|4|12|14|10000|10002|10004|10006|10008|10010&srsearch=' + encodeURIComponent( title ) + '&srlimit=1',
+								uri: 'https://' + wiki + '.gamepedia.com/api.php?action=query&format=json&prop=pageimages|extracts&exintro=true&explaintext=true&generator=search&gsrnamespace=0|4|12|14|10000|10002|10004|10006|10008|10010&gsrlimit=1&gsrsearch=' + encodeURIComponent( title ),
 								json: true
 							}, function( srerror, srresponse, srbody ) {
-								if ( srerror || !srresponse || !srbody || !srbody.query || ( !srbody.query.search[0] && srbody.query.searchinfo.totalhits != 0 ) ) {
+								if ( srerror || !srresponse || !srbody || srbody.batchcomplete == undefined ) {
 									console.log( '- Fehler beim Erhalten der Suchergebnisse' + ( srerror ? ': ' + srerror : ( srbody ? ( srbody.error ? ': ' + srbody.error.info : '.' ) : '.' ) ) );
 									msg.channel.send( '<https://' + wiki + '.gamepedia.com/Special:Search/' + title.toTitle() + linksuffix + '>' ).then( message => message.reactEmoji('error') );
 								}
 								else {
-									if ( srbody.query.searchinfo.totalhits == 0 ) {
+									if ( !srbody.query ) {
 										msg.reactEmoji('🤷');
 									}
 									else {
-										var pagelink = 'https://' + wiki + '.gamepedia.com/' + srbody.query.search[0].title.toTitle() + linksuffix;
-										if ( title.replace( /\-/g, ' ' ).toTitle().toLowerCase() == srbody.query.search[0].title.replace( /\-/g, ' ' ).toTitle().toLowerCase() ) {
-											msg.channel.send( pagelink );
+										querypage = Object.values(srbody.query.pages)[0];
+										var pagelink = 'https://' + wiki + '.gamepedia.com/' + querypage.title.toTitle() + linksuffix;
+										var embed = new Discord.RichEmbed().setAuthor( body.query.general.sitename ).setTitle( querypage.title ).setURL( pagelink );
+										if ( querypage.extract ) embed.setDescription( querypage.extract );
+										if ( querypage.pageimage ) {
+											var pageimage = 'https://' + wiki + '.gamepedia.com/Special:FilePath/' + querypage.pageimage;
+											if ( querypage.ns == 6 ) embed.setImage( pageimage );
+											else embed.setThumbnail( pageimage );
+										} else embed.setThumbnail( body.query.general.logo );
+										if ( title.replace( /\-/g, ' ' ).toTitle().toLowerCase() == querypage.title.replace( /\-/g, ' ' ).toTitle().toLowerCase() ) {
+											msg.channel.send( pagelink, embed );
 										}
-										else if ( srbody.query.searchinfo.totalhits == 1 ) {
-											msg.channel.send( pagelink + '\n' + lang.search.infopage.replace( '%s', '`' + process.env.prefix + cmd + lang.search.page + ' ' + title + '`' ) );
+										else if ( !srbody.continue ) {
+											msg.channel.send( pagelink + '\n' + lang.search.infopage.replace( '%s', '`' + process.env.prefix + cmd + lang.search.page + ' ' + title + '`' ), embed );
 										}
 										else {
-											msg.channel.send( pagelink + '\n' + lang.search.infosearch.replace( '%1$s', '`' + process.env.prefix + cmd + lang.search.page + ' ' + title + '`' ).replace( '%2$s', '`' + process.env.prefix + cmd + lang.search.search + ' ' + title + '`' ) );
+											msg.channel.send( pagelink + '\n' + lang.search.infosearch.replace( '%1$s', '`' + process.env.prefix + cmd + lang.search.page + ' ' + title + '`' ).replace( '%2$s', '`' + process.env.prefix + cmd + lang.search.search + ' ' + title + '`' ), embed );
 										}
 									}
 								}
 							} );
 						}
 						else {
-							msg.channel.send( 'https://' + wiki + '.gamepedia.com/' + Object.values(body.query.pages)[0].title.toTitle() + ( querystring ? '?' + querystring.toTitle() : '' ) + ( body.query.redirects && body.query.redirects[0].tofragment ? '#' + body.query.redirects[0].tofragment.toSection() : ( fragment ? '#' + fragment.toSection() : '' ) ) );
+							var pagelink = 'https://' + wiki + '.gamepedia.com/' + querypage.title.toTitle() + ( querystring ? '?' + querystring.toTitle() : '' ) + ( body.query.redirects && body.query.redirects[0].tofragment ? '#' + body.query.redirects[0].tofragment.toSection() : ( fragment ? '#' + fragment.toSection() : '' ) );
+							var embed = new Discord.RichEmbed().setAuthor( body.query.general.sitename ).setTitle( querypage.title ).setURL( pagelink );
+							if ( querypage.extract ) embed.setDescription( querypage.extract );
+							if ( querypage.pageimage ) {
+								var pageimage = 'https://' + wiki + '.gamepedia.com/Special:FilePath/' + querypage.pageimage;
+								if ( querypage.ns == 6 ) embed.setImage( pageimage );
+								else embed.setThumbnail( pageimage );
+							} else embed.setThumbnail( body.query.general.logo );
+							msg.channel.send( pagelink, embed );
 						}
 					}
 					else if ( body.query.interwiki ) {
@@ -608,85 +623,80 @@ function cmd_sendumfrage(lang, msg, args, reactions, imgs, i) {
 	}, error => msg.reactEmoji('error') );
 }
 
-function cmd_user(lang, msg, username, wiki, title, cmd, querystring, fragment) {
-	if ( !username || username.includes( '/' ) || username.toLowerCase().startsWith('talk:') || username.toLowerCase().startsWith(lang.user.talk) ) {
-		msg.notuser = true;
-		cmd_link(lang, msg, title, wiki, cmd, querystring, fragment);
-	} else {
-		msg.reactEmoji('⏳').then( function( reaction ) {
-			request( {
-				uri: 'https://' + wiki + '.gamepedia.com/api.php?action=query&format=json&list=users&usprop=blockinfo|groups|editcount|registration|gender&ususers=' + encodeURIComponent( username ),
-				json: true
-			}, function( error, response, body ) {
-				if ( error || !response || !body || !body.query || !body.query.users[0] ) {
-					if ( response && response.request && response.request.uri && response.request.uri.href == 'https://www.gamepedia.com/' ) {
-						console.log( '- Dieses Wiki existiert nicht! ' + ( error ? error.message : ( body ? ( body.error ? body.error.info : '' ) : '' ) ) );
-						msg.reactEmoji('nowiki');
-					}
-					else {
-						console.log( '- Fehler beim Erhalten der Suchergebnisse' + ( error ? ': ' + error : ( body ? ( body.error ? ': ' + body.error.info : '.' ) : '.' ) ) );
-						msg.channel.send( '<https://' + wiki + '.gamepedia.com/User:' + username + '>' ).then( message => message.reactEmoji('error') );
-					}
+function cmd_user(lang, msg, namespace, username, wiki) {
+	msg.reactEmoji('⏳').then( function( reaction ) {
+		request( {
+			uri: 'https://' + wiki + '.gamepedia.com/api.php?action=query&format=json&list=users&usprop=blockinfo|groups|editcount|registration|gender&ususers=' + encodeURIComponent( username ),
+			json: true
+		}, function( error, response, body ) {
+			if ( error || !response || !body || body.batchcomplete == undefined || !body.query || !body.query.users[0] ) {
+				if ( response && response.request && response.request.uri && response.request.uri.href == 'https://www.gamepedia.com/' ) {
+					console.log( '- Dieses Wiki existiert nicht! ' + ( error ? error.message : ( body ? ( body.error ? body.error.info : '' ) : '' ) ) );
+					msg.reactEmoji('nowiki');
 				}
 				else {
-					if ( body.query.users[0].missing == "" || body.query.users[0].invalid == "" ) {
-						msg.reactEmoji('🤷');
+					console.log( '- Fehler beim Erhalten der Suchergebnisse' + ( error ? ': ' + error : ( body ? ( body.error ? ': ' + body.error.info : '.' ) : '.' ) ) );
+					msg.channel.send( '<https://' + wiki + '.gamepedia.com/' + namespace + username + '>' ).then( message => message.reactEmoji('error') );
+				}
+			}
+			else {
+				if ( body.query.users[0].missing == "" || body.query.users[0].invalid == "" ) {
+					msg.reactEmoji('🤷');
+				}
+				else {
+					username = body.query.users[0].name.toTitle();
+					var timeoptions = {
+						year: 'numeric',
+						month: 'short',
+						day: 'numeric',
+						hour: '2-digit',
+						minute: '2-digit',
+						timeZone: 'UTC',
+						timeZoneName: 'short'
 					}
-					else {
-						username = body.query.users[0].name.replace( / /g, '_' );
-						var timeoptions = {
-							year: 'numeric',
-							month: 'short',
-							day: 'numeric',
-							hour: '2-digit',
-							minute: '2-digit',
-							timeZone: 'UTC',
-							timeZoneName: 'short'
-						}
-						var gender = body.query.users[0].gender;
-						switch (gender) {
-							case 'male':
-								gender = lang.user.gender.male;
-								break;
-							case 'female':
-								gender = lang.user.gender.female;
-								break;
-							default: 
-								gender = lang.user.gender.unknown;
-						}
-						var registration = (new Date(body.query.users[0].registration)).toLocaleString(lang.user.dateformat, timeoptions);
-						var editcount = body.query.users[0].editcount;
-						var groups = body.query.users[0].groups;
-						var group = '';
-						for ( var i = 0; i < lang.user.group.length; i++ ) {
-							if ( groups.includes( lang.user.group[i][0] ) ) {
-								var thisSite = allSites.find( site => site.wiki_domain == wiki + '.gamepedia.com' );
-								if ( lang.user.group[i][0] == 'hydra_staff' && thisSite && thisSite.wiki_managers.includes( username.replace( /\_/g, ' ' ) ) ) group = lang.user.manager;
-								else group = lang.user.group[i][1];
-								break;
-							}
-						}
-						var isBlocked = false;
-						var blockedtimestamp = (new Date(body.query.users[0].blockedtimestamp)).toLocaleString(lang.user.dateformat, timeoptions);
-						var blockexpiry = body.query.users[0].blockexpiry;
-						if ( blockexpiry == 'infinity' ) {
-							blockexpiry = lang.user.until_infinity;
-							isBlocked = true;
-						} else if ( blockexpiry ) {
-							var blockexpirydate = blockexpiry.replace(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2,3})/, '$1-$2-$3T$4:$5:$6Z');
-							blockexpiry = (new Date(blockexpirydate)).toLocaleString(lang.user.dateformat, timeoptions);
-							if ( Date.parse(blockexpirydate) > Date.now() ) isBlocked = true;
+					var gender = body.query.users[0].gender;
+					switch (gender) {
+						case 'male':
+							gender = lang.user.gender.male;
+							break;
+						case 'female':
+							gender = lang.user.gender.female;
+							break;
+						default: 
+							gender = lang.user.gender.unknown;
+					}
+					var registration = (new Date(body.query.users[0].registration)).toLocaleString(lang.user.dateformat, timeoptions);
+					var editcount = body.query.users[0].editcount;
+					var groups = body.query.users[0].groups;
+					var group = '';
+					for ( var i = 0; i < lang.user.group.length; i++ ) {
+						if ( groups.includes( lang.user.group[i][0] ) ) {
+							var thisSite = allSites.find( site => site.wiki_domain == wiki + '.gamepedia.com' );
+							if ( lang.user.group[i][0] == 'hydra_staff' && thisSite && thisSite.wiki_managers.toTitle().includes( username ) ) group = lang.user.manager;
+							else group = lang.user.group[i][1];
+							break;
 						}
-						var blockedby = body.query.users[0].blockedby;
-						var blockreason = body.query.users[0].blockreason;
-						msg.channel.send( '<https://' + wiki + '.gamepedia.com/UserProfile:' + username + '>\n\n' + lang.user.info.replace( '%1$s', gender ).replace( '%2$s', registration ).replace( '%3$s', editcount ).replace( '%4$s', group ) + ( isBlocked ? '\n\n' + lang.user.blocked.replace( '%1$s', blockedtimestamp ).replace( '%2$s', blockexpiry ).replace( '%3$s', blockedby ).replace( '%4$s', blockreason.wikicode() ) : '' ) );
 					}
+					var isBlocked = false;
+					var blockedtimestamp = (new Date(body.query.users[0].blockedtimestamp)).toLocaleString(lang.user.dateformat, timeoptions);
+					var blockexpiry = body.query.users[0].blockexpiry;
+					if ( blockexpiry == 'infinity' ) {
+						blockexpiry = lang.user.until_infinity;
+						isBlocked = true;
+					} else if ( blockexpiry ) {
+						var blockexpirydate = blockexpiry.replace(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2,3})/, '$1-$2-$3T$4:$5:$6Z');
+						blockexpiry = (new Date(blockexpirydate)).toLocaleString(lang.user.dateformat, timeoptions);
+						if ( Date.parse(blockexpirydate) > Date.now() ) isBlocked = true;
+					}
+					var blockedby = body.query.users[0].blockedby;
+					var blockreason = body.query.users[0].blockreason;
+					msg.channel.send( '<https://' + wiki + '.gamepedia.com/' + namespace + username + '>\n\n' + lang.user.info.replace( '%1$s', gender ).replace( '%2$s', registration ).replace( '%3$s', editcount ).replace( '%4$s', group ) + ( isBlocked ? '\n\n' + lang.user.blocked.replace( '%1$s', blockedtimestamp ).replace( '%2$s', blockexpiry ).replace( '%3$s', blockedby ).replace( '%4$s', blockreason.wikicode() ) : '' ) );
 				}
-				
-				if ( reaction ) reaction.removeEmoji();
-			} );
+			}
+			
+			if ( reaction ) reaction.removeEmoji();
 		} );
-	}
+	} );
 }
 
 function cmd_diff(lang, msg, args, wiki) {
@@ -788,7 +798,7 @@ function cmd_diffsend(lang, msg, args, wiki) {
 		uri: 'https://' + wiki + '.gamepedia.com/api.php?action=query&format=json&list=tags&tglimit=500&tgprop=displayname&prop=revisions&rvprop=ids|timestamp|flags|user|size|comment|tags&revids=' + args.join('|'),
 		json: true
 	}, function( error, response, body ) {
-		if ( error || !response || !body || !body.query ) {
+		if ( error || !response || !body || body.batchcomplete == undefined || !body.query ) {
 			if ( response && response.request && response.request.uri && response.request.uri.href == 'https://www.gamepedia.com/' ) {
 				console.log( '- Dieses Wiki existiert nicht! ' + ( error ? error.message : ( body ? ( body.error ? body.error.info : '' ) : '' ) ) );
 				msg.reactEmoji('nowiki');
@@ -850,7 +860,7 @@ function cmd_random(lang, msg, wiki) {
 			uri: 'https://' + wiki + '.gamepedia.com/api.php?action=query&format=json&list=random&rnnamespace=0',
 			json: true
 		}, function( error, response, body ) {
-			if ( error || !response || !body || !body.query || !body.query.random[0] ) {
+			if ( error || !response || !body || body.batchcomplete == undefined || !body.query || !body.query.random[0] ) {
 				if ( response && response.request && response.request.uri && response.request.uri.href == 'https://www.gamepedia.com/' ) {
 					console.log( '- Dieses Wiki existiert nicht! ' + ( error ? error.message : ( body ? ( body.error ? body.error.info : '' ) : '' ) ) );
 					msg.reactEmoji('nowiki');

+ 20 - 3
package.json

@@ -1,7 +1,7 @@
 {
-  "name": "Wiki-Bot",
+  "name": "discord-wiki-bot",
   "version": "1.0.0",
-  "description": "Wiki-Bot is a bot for Discord with the purpose to easily link to Gamepedia wikis. He can resolve redirects and follow interwiki links.",
+  "description": "Wiki-Bot is a bot for Discord with the purpose to easily link to Gamepedia wikis.",
   "main": "main.js",
   "scripts": {
     "test": "node --icu-data-dir=node_modules/full-icu main.js debug",
@@ -12,8 +12,25 @@
   "dependencies": {
     "dblapi.js": "^2.3.0",
     "discord.js": "^11.4.2",
+    "dotenv": "^6.1.0",
     "full-icu": "^1.2.1",
     "npm": "^5.10.0",
     "request": "^2.88.0"
-  }
+  },
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/Markus-Rost/discord-wiki-bot.git"
+  },
+  "keywords": [
+    "gamepedia",
+    "discord",
+    "wikibot",
+    "voice-channel",
+    "wiki",
+    "discord-bot"
+  ],
+  "bugs": {
+    "url": "https://github.com/Markus-Rost/discord-wiki-bot/issues"
+  },
+  "homepage": "https://github.com/Markus-Rost/discord-wiki-bot#readme"
 }