Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * _____ _ _ _____
- * | __ \ | | | |/ ____|
- * | |__) | _| |__ _ _ | | (___
- * | _ / | | | '_ \| | | | _ | |\___ \
- * | | \ \ |_| | |_) | |_| || |__| |____) |
- * |_| \_\__,_|_.__/ \__, (_)____/|_____/
- * __/ |
- * |___/
- *
- * The ultimate in bullshitting technology
- *
- * "Refactoring is for pussies" edition
- */
- var socket = require('request');
- var fs = require('fs');
- var cookie_jar = socket.jar();
- var cred = {
- user: '',
- pass: '',
- wiki: '',
- urll: '',
- apil: ''
- };
- var config = {
- key: '',
- room: '',
- mod: '',
- server: '',
- host: '',
- options: {}
- };
- var http = {
- headers: {
- 'User-Agent': 'Ruby.js/v1.0 (screw socket.io)',
- 'Content-Type': 'application/octet-stream',
- 'Accept': '*/*',
- 'Pragma': 'no-cache',
- 'Cache-Control': 'no-cache'
- },
- get: function(url, headers, callback) {
- socket.get({url: url, jar: cookie_jar, headers: headers}, function(e, r, b) {
- callback({error: e, response: r, body: b});
- });
- },
- post: function(url, form, headers, callback) {
- socket.post({url: url, form: form, jar: cookie_jar, headers: headers}, function(e, r, b) {
- callback({error: e, response: r, body: b});
- });
- }
- };
- var mediawiki = {
- _callback: null,
- _data: {},
- _loggedin: false,
- login: function(username, password, url, callback) {
- if (this._loggedin === false) {
- if (typeof callback === 'function') {
- this._callback = callback;
- this._data.url = url;
- this._data.form = {
- action: 'login',
- lgname: username,
- lgpassword: password,
- format: 'json'
- };
- http.post(this._data.url, this._data.form, {}, function(response) {
- if (!response.error) {
- mediawiki._data.form.lgtoken = (JSON.parse(response.body)).login.token;
- http.post(mediawiki._data.url, mediawiki._data.form, {}, function(response) {
- if (!response.error) {
- if ((JSON.parse(response.body)).login.result === 'Success') {
- mediawiki._data = {};
- mediawiki._loggedin = true;
- mediawiki._callback();
- } else {
- console.log('ERROR: Could not log into the wiki!');
- console.log(' -> ' + JSON.stringify(mediawiki._data));
- console.log(' -> ' + response.body);
- }
- } else {
- console.log('ERROR: Could not log into the wiki!');
- console.log(' -> ' + response.error);
- }
- });
- } else {
- console.log('ERROR: Could not log into the wiki!');
- console.log(' -> ' + response.error);
- }
- });
- } else {
- console.log('ERROR: Callback is not a function!');
- console.log(' -> ' + typeof callback);
- }
- } else {
- callback();
- }
- }
- };
- function getChatInfo() {
- http.get(cred.urll + '/wikia.php?controller=Chat&format=json', http.headers, function(response) {
- if (!response.error) {
- var data = JSON.parse(response.body);
- config.key = data.chatkey;
- config.room = data.roomId;
- config.mod = data.isChatMod;
- config.host = data.chatServerHost;
- http.get(cred.apil + '/api.php?action=query&meta=siteinfo&siprop=wikidesc&format=json', {}, function(response) {
- if (!response.error) {
- var data = JSON.parse(response.body);
- config.server = data.query.wikidesc.id;
- config.options.name: cred.user;
- config.options.EIO: 2;
- config.options.transport: 'polling';
- config.options.key: config.key;
- config.options.roomId: config.room;
- config.options.serverId: config.server;
- config.options.wikiId: config.server;
- } else {
- console.log('ERROR: Could not fetch chat config!');
- console.log(' -> ' + response.error);
- }
- });
- } else {
- console.log('ERROR: Could not fetch chat config!');
- console.log(' -> ' + response.error);
- }
- });
- }
- function login() {
- mediawiki.login(cred.user, cred.pass, cred.apil, function() {
- getChatInfo();
- });
- }
- function start() {
- try {
- var data = JSON.parse(fs.readFileSync('config.json', 'UTF-8'));
- } catch (e) {
- console.log('ERROR: Could not parse config.json!');
- console.log(' -> ' + e);
- }
- if (data.username) {
- if (data.passsword) {
- if (data.wiki) {
- cred.user = data.username;
- cred.pass = data.password;
- cred.wiki = data.wiki;
- cred.urll = 'http://' + data.wiki + '.wikia.com'
- cred.apil = cred.urll + '/api.php';
- login();
- } else {
- console.log('ERROR: No wiki name!');
- }
- } else {
- console.log('ERROR: No password!');
- }
- } else {
- console.log('ERROR: No username!');
- }
- }
- start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement