Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Rodriguez committed May 31, 2018
1 parent 90d34aa commit 72f22b1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion launcher/get-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ module.exports = function getAuth (cb) {
}
}
debug('Authenticating - Please stand by...'.grey)
mr.post('https://code.bot18.net/auth/' + username, opts, function (err, resp, body) {
bot18.lib.mr_post('https://code.bot18.net/auth/' + username, opts, function (err, resp, body) {
if (err) {
return cb(new Error('Your network connection is down. Please try again later.'))
}
Expand Down
4 changes: 1 addition & 3 deletions launcher/get-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var bot18 = global.BOT18

module.exports = function getEngine (cb) {
var salty = require('salty')
var mr = require('micro-request')
var vm = require('vm')
var zlib = require('zlib')
var debug = bot18.debug('launcher')
Expand Down Expand Up @@ -97,8 +96,7 @@ module.exports = function getEngine (cb) {
return cb(new Error('Invalid request to ZalgoNet. The REST API may have changed.'))
case 403:
var err = new Error('Authorization expired. Please log in again.')
err.retry = true
return cb(err)
return require(r(__dirname, 'get-auth'))(cb)
case 404:
return cb(new Error('Invalid engine distribution channel. Please choose either "stable", "unstable", or "trial".'))
case 429:
Expand Down
2 changes: 1 addition & 1 deletion launcher/get-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ var bot18 = global.BOT18

module.exports = function (cb) {
var r = require('path').resolve
require(r(__dirname, '..', 'lib', 'mr'))
require(r(__dirname, '..', 'lib', 'mr'))()
cb()
}
14 changes: 7 additions & 7 deletions lib/mr.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ var bot18 = global.BOT18
module.exports = function () {
function wrapMethod (method) {
return function (url, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = {}
}
var defaults = {
headers: {
'user-agent': bot18.user_agent
Expand All @@ -15,10 +11,14 @@ module.exports = function () {
if (bot18.auth && bot18.auth.authorized && bot18.auth.auth_token) {
defaults.headers['x-bot18-auth'] = bot18.auth.auth_token
}
if (typeof opts === 'function') {
cb = opts
opts = {}
}
var opts_copy = JSON.parse(JSON.stringify(opts))
var opts_merged = require('lodash.defaultsdeep')(opts_copy, defaults)
return require('micro-request')[method](url, opts_merged, cb)
}
var opts_copy = JSON.parse(JSON.stringify(opts))
var opts_merged = require('lodash.defaultsdeep')(opts_copy, defaults)
return require('micro-request')[method](url, opts_merged, cb)
}
;['get', 'post', 'put', 'delete'].forEach(function (method) {
bot18.lib['mr_' + method] = wrapMethod(method)
Expand Down

0 comments on commit 72f22b1

Please sign in to comment.