Parcourir la source

easiers self hosting

Markus-Rost il y a 5 ans
Parent
commit
f83e7bae29
3 fichiers modifiés avec 16 ajouts et 83 suppressions
  1. 1 15
      .env.example
  2. 15 67
      main.js
  3. 0 1
      package.json

+ 1 - 15
.env.example

@@ -13,18 +13,4 @@ channel="591600620608159757"
 # Invite link to the bot help Discord
 invite="https://discord.gg/v77RTk5"
 # Link to the patreon page for the bot
-patreon="https://www.patreon.com/WikiBot"
-
-# Token to send server count to https://discordbots.org/ (optional)
-dbltoken="<token>"
-# Token to send server count to https://discord.bots.gg/ (optional)
-dbggtoken="<token>"
-
-# Username to log into an account on Gamepedia (optional)
-gpusername="<username>"
-# Password to log into an account on Gamepedia (optional)
-gppassword="<password>"
-# Username to log into an account on Fandom (optional)
-fusername="<username>"
-# Password to log into an account on Fandom (optional)
-fpassword="<password>"
+patreon="https://www.patreon.com/WikiBot"

+ 15 - 67
main.js

@@ -10,7 +10,6 @@ var ready = {
 }
 
 const Discord = require('discord.js');
-const DBL = require('dblapi.js');
 const got = require('got').extend( {
 	throwHttpErrors: false,
 	headers: {
@@ -29,68 +28,6 @@ var db = new sqlite3.Database( './wikibot.db', sqlite3.OPEN_READWRITE | sqlite3.
 	console.log( '- Connected to the database.' );
 } );
 
-/* Paused until UCP
-var cookieJar = request.jar();
-function gpWikiLogin() {
-	request( {
-		uri: 'https://help.gamepedia.com/api.php?action=query&meta=tokens&type=login&format=json',
-		json: true,
-		jar: cookieJar
-	}, function( error, response, body ) {
-		if ( error || !response || response.statusCode !== 200 || !body || body.batchcomplete === undefined || !body.query || !body.query.tokens ) {
-			console.log( '- ' + ( response && response.statusCode ) + ': Error while gettings the login token: ' + ( error || body && body.error && body.error.info ) );
-			return;
-		}
-		console.log( '- Gamepedia: Token successfully fetched.' );
-		request.post( {
-			uri: 'https://help.gamepedia.com/api.php',
-			form: {
-				action: 'login',
-				lgname: process.env.gpusername,
-				lgpassword: process.env.gppassword,
-				lgtoken: body.query.tokens.logintoken,
-				format: 'json'
-			},
-			json: true,
-			jar: cookieJar
-		}, function( loginerror, loginresponse, loginbody ) {
-			if ( loginerror || !loginresponse || loginresponse.statusCode !== 200 || !loginbody || !loginbody.login || loginbody.login.result !== 'Success' ) {
-				console.log( '- ' + ( loginresponse && loginresponse.statusCode ) + ': Error while logging in: ' + ( loginerror || loginbody && ( ( loginbody.login && loginbody.login.result ) || loginbody.error && loginbody.error.info ) ) );
-				return;
-			}
-			console.log( '- Gamepedia: Successfully logged in as ' + loginbody.login.lgusername + '.' );
-		} );
-	} );
-}
-if ( process.env.gpusername && process.env.gppassword ) gpWikiLogin();
-
-function fWikiLogin(token) {
-	request.post( {
-		uri: 'https://community.fandom.com/api.php',
-		form: {
-			action: 'login',
-			lgname: process.env.fusername,
-			lgpassword: process.env.fpassword,
-			lgtoken: token,
-			format: 'json'
-		},
-		json: true,
-		jar: cookieJar
-	}, function( loginerror, loginresponse, loginbody ) {
-		if ( loginerror || !loginresponse || loginresponse.statusCode !== 200 || !loginbody || !loginbody.login || loginbody.login.result !== 'Success' ) {
-			if ( loginbody && loginbody.login && loginbody.login.result === 'NeedToken' ) {
-				console.log( '- Fandom: Token successfully fetched.' );
-				return fWikiLogin(loginbody.login.token);
-			}
-			console.log( '- ' + ( loginresponse && loginresponse.statusCode ) + ': Error while logging in: ' + ( loginerror || loginbody && ( ( loginbody.login && loginbody.login.result ) || loginbody.error && loginbody.error.info ) ) );
-			return;
-		}
-		console.log( '- Fandom: Successfully logged in as ' + loginbody.login.lgusername + '.' );
-	} );
-}
-if ( process.env.fusername && process.env.fpassword ) fWikiLogin();
-*/
-
 var client = new Discord.Client( {
 	messageCacheLifetime: 300,
 	messageSweepInterval: 300,
@@ -115,7 +52,6 @@ var client = new Discord.Client( {
 		]
 	}
 } );
-const dbl = new DBL(process.env.dbltoken);
 
 var i18n = require('./i18n/allLangs.json');
 Object.keys(i18n.allLangs[1]).forEach( lang => i18n[lang] = require('./i18n/' + lang + '.json') );
@@ -293,8 +229,18 @@ client.on( 'ready', () => {
 	
 	if ( !isDebug ) client.setInterval( () => {
 		console.log( '- Current server count: ' + client.guilds.cache.size );
-		dbl.postStats(client.guilds.cache.size).catch( () => {} );
-		got.post( 'https://discord.bots.gg/api/v1/bots/' + client.user.id + '/stats', {
+		if ( process.env.dbltoken ) got.post( 'https://top.gg/api/bots/' + client.user.id + '/stats', {
+			headers: {
+				Authorization: process.env.dbltoken
+			},
+			json: {
+				server_count: client.guilds.cache.size
+			},
+			responseType: 'json'
+		} ).catch( error => {
+			console.log( '- Error while posting statistics to https://top.gg/bot/' + client.user.id + ': ' + error );
+		} );
+		if ( process.env.dbggtoken ) got.post( 'https://discord.bots.gg/api/v1/bots/' + client.user.id + '/stats', {
 			headers: {
 				Authorization: process.env.dbggtoken
 			},
@@ -302,7 +248,9 @@ client.on( 'ready', () => {
 				guildCount: client.guilds.cache.size
 			},
 			responseType: 'json'
-		} ).catch( () => {} );
+		} ).catch( error => {
+			console.log( '- Error while posting statistics to https://discord.bots.gg/bots/' + client.user.id + ': ' + error );
+		} );
 	}, 10800000 ).unref();
 } );
 	

+ 0 - 1
package.json

@@ -11,7 +11,6 @@
   "license": "ISC",
   "dependencies": {
     "cheerio": "^1.0.0-rc.3",
-    "dblapi.js": "^2.4.0",
     "discord.js": "^12.1.1",
     "dotenv": "^6.2.0",
     "full-icu": "^1.3.1",