hubot-bustabit
Advanced tools
Comparing version 1.1.0 to 1.1.2
@@ -5,2 +5,4 @@ // When you log in to bustabit.com select the "AUTO" tab, then at the | ||
// copy paste the entire contents of this text into that text field and click run | ||
// You must also "allow unsafe scripts" which is an option in your browser | ||
// for example on chrome it will show you a little shield that you need to click. | ||
// Your Mubot should now have bustabit integration. | ||
@@ -11,3 +13,3 @@ | ||
const USER = engine.getUsername(); | ||
var won = false; // Keep track of whether we won or lost. | ||
var won; // Keep track of whether we won or lost. | ||
@@ -31,4 +33,4 @@ // Update the server with game information. | ||
// User won. | ||
engine.on('cashed_out', function(resp) { | ||
if(resp.username === USER) { | ||
engine.on('cashed_out', function(data) { | ||
if(data.username === USER) { | ||
won = true; | ||
@@ -44,7 +46,7 @@ updateServer('win=true&balance='+engine.getBalance()) | ||
xmlhttp.onreadystatechange = function() { | ||
if (this.readyState == 4 && this.status == 200) { | ||
bet = JSON.parse(this.responseText); | ||
if(bet.size) { | ||
engine.placeBet(bet.size*100, parseInt(bet.ratio*100), false); | ||
if(this.readyState === 4 && this.status === 200) { | ||
let bet = JSON.parse(this.responseText); | ||
if(bet.amount) { | ||
won = false; | ||
engine.placeBet(bet.amount*100, parseInt(bet.ratio*100), false) | ||
} | ||
@@ -51,0 +53,0 @@ } |
@@ -50,3 +50,3 @@ { | ||
}, | ||
"version": "1.1.0" | ||
"version": "1.1.2" | ||
} |
# hubot-bustabit | ||
A hubot bustabit integration script which supports single or multi person betting. | ||
Future versions will support single person fund mode for betting in community channels | ||
aside from the current community fund only mode. | ||
Hubot bustabit integration which supports single or multi person betting. | ||
Future versions will support betting with personal funds along with the | ||
current community fund only mode. | ||
**NOTE - For this script to work you must keep a browser logged in to bustabit.com | ||
and you must follow the directions in [`bustabit_script.js`](bustabit_script.js)** (copy paste it to bustabit.com). | ||
The screenshot bellow is using Discord, but you may use Twitch, Slack, or anything. | ||
![Image of coloring](https://preview.ibb.co/hRh40m/Screen_Shot_2017_07_18_at_12_16_30_PM.png) | ||
**For this script to work you must keep a browser logged in to bustabit.com and you must follow** | ||
**the directions in [`bustabit_script.js`](bustabit_script.js) (copy paste it to bustabit.com).** | ||
See [`src/bustabit.js`](src/bustabit.js) for full documentation. | ||
## Requirements | ||
Node & Hubot | ||
## Installation | ||
In hubot project repo, run: | ||
Once you have insalled Hubot, in hubot's root directory, run: | ||
@@ -24,2 +31,4 @@ `npm install hubot-bustabit --save` | ||
Your hubot should now have bustabit integration - Fund wallet and get rollen! | ||
## Sample Ussage | ||
@@ -26,0 +35,0 @@ |
@@ -8,5 +8,5 @@ // Description: | ||
// Commands: | ||
// Mubot bet <amount_in_bits> <cash_out_ratio> - Creates a bet, and adds it to the que. | ||
// Mubot view bets - Responds with the bet que in JSON. | ||
// Mubot bet - Returns the bet que length. | ||
// bet <amount_in_bits> <cash_out_ratio> - Creates a bet, and adds it to the que. | ||
// Mubot view bets - Responds with the bet que in JSON. | ||
// Mubot bets - Returns the bet que length. | ||
// | ||
@@ -17,3 +17,2 @@ // Author: | ||
(function(){ | ||
// REQ | ||
@@ -23,6 +22,9 @@ request = require('request'); | ||
// INIT | ||
var lastbet = {}; | ||
var betQue = []; | ||
var room = ''; | ||
var allBets = []; | ||
var lastbet = {}; | ||
var betQue = []; | ||
var room = ''; | ||
var allBets = []; | ||
var balance = 100; // Set this value to your balane, otherwise it will auto set after first bet. | ||
var first_bet = true; // keep track of the first bet incase the user forgets to set his balance above. | ||
const MAX_BET = 10; // the max bet as a percentage of blance | ||
@@ -32,25 +34,28 @@ // MAIN | ||
bot.brain.on('loaded', () => { | ||
if(!bot.brain.data.allBets) bot.brain.data.allBets = [] | ||
allBets = bot.brain.data.allBets; | ||
// (allBets = bot.brain.data).allBets || (allBets.allBets = []); allBets = allBets.allBets | ||
// allBets now references bot.brain.data.allBets even if it didnt exist before. | ||
if(!bot.brain.data.allBets) bot.brain.data.allBets = []; | ||
allBets = bot.brain.data.allBets | ||
}) | ||
bot.respond(/bets$/i, r => { | ||
if(Boolean(betQue.length)) r.send("The bet que is " + betQue.length + " long.") | ||
if(betQue.length) r.send("The bet que is " + betQue.length + " long."); | ||
else r.send("The bet que is empty.") | ||
}) | ||
bot.respond(/view bets$/i, r => { | ||
if(Boolean(betQue.length)) r.send(JSON.stringify(betQue)) | ||
if(betQue.length) r.send(JSON.stringify(betQue)); | ||
else r.send("The bet que is empty.") | ||
}) | ||
bot.hear(/^bet (\d+) (\d+\.?\d{0,2})$/i, r => { | ||
room = r.message.room | ||
if(first_bet) { | ||
first_bet = false; | ||
} else if(r.match[1] / balance > MAX_BET / 100) { | ||
return r.send("Sorry you cannot bet more than " + MAX_BET + "% of your balance.") | ||
} | ||
room = r.message.room; | ||
allBets.push({ | ||
amount: r.match[1], | ||
ratio: r.match[2], | ||
id: bot.brain.data.allBets.length || 0, | ||
id: bot.brain.data.allBets.length, | ||
user: r.message.user.name, | ||
profit: 0 | ||
}) | ||
if(Boolean(betQue.length)) { | ||
}); | ||
if(betQue.length) { | ||
r.send("Adding bet to que with ID#" + allBets.length + ". [" + r.match[1] + " bit(s) / Cashout @ x" + r.match[2] + "]") | ||
@@ -60,4 +65,4 @@ } else { | ||
} | ||
// Push last allBet (most recent bet) into the que. | ||
betQue.push(allBets.slice(-1)) | ||
// Push last allBet (most recent desired bet) into the que. | ||
betQue.push(allBets[allBets.length-1]) | ||
}) | ||
@@ -69,3 +74,3 @@ | ||
res.setHeader('Access-Control-Allow-Origin', '*'); | ||
res.setHeader('Access-Control-Request-Method', 'POST, OPTIONS'); | ||
res.setHeader('Access-Control-Request-Method', 'POST, GET'); | ||
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); | ||
@@ -97,2 +102,3 @@ next() | ||
}) | ||
} | ||
}; | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8922
168
42