Skip to content

Commit 79b3f56

Browse files
author
bot
committed
math in console edition; integrate satoshidice.io; cvs log for console edition
1 parent e49736e commit 79b3f56

File tree

24 files changed

+421
-25
lines changed

24 files changed

+421
-25
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
* [EpicDice](https://epicdice.io/?ref=mydicebot)
5757
* [KryptoGames](https://kryptogamers.com/?ref=mydicebot)
5858

59+
## Free Bitcoin Faucet
60+
* [Faucet Collector](https://faucetcollector.com/?ref=4789455)
61+
62+
## Exchange/Trading
63+
* [Binance](https://www.binance.com/en/register?ref=40077522)
64+
5965
# TODO
6066
* [BetKing (coming soon)](https://betking.io/?ref=u:mydicebot)
6167
* [BitDice (coming soon)](https://www.bitdice.me/?r=90479)

src/api/models/satoshidice.js

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
'use strict';
2+
3+
var BaseDice = require('./base');
4+
var fetch = require('isomorphic-fetch');
5+
var APIError = require('../errors/APIError');
6+
7+
module.exports = class SatoshiDice extends BaseDice {
8+
constructor(){
9+
super();
10+
this.url = 'https://www.satoshidice.io';
11+
this.benefit = '?c=mydicebot'
12+
}
13+
14+
async login(userName, password, twoFactor ,apiKey, req) {
15+
let data = {};
16+
data.username = userName;
17+
data.password = password;
18+
let ret = await this._send('api/login', 'POST', data, '');
19+
console.log(ret);
20+
req.session.accessToken = ret.token;
21+
req.session.username = userName;
22+
req.session.balance = ret.message.balance;
23+
//console.log(req.session);
24+
//console.log(req.session.accessToken);
25+
return true;
26+
}
27+
28+
async getUserInfo(req) {
29+
return true
30+
}
31+
32+
async refresh(req) {
33+
let info = req.session.info;
34+
if(info){
35+
console.log("info is not null");
36+
return info;
37+
}
38+
let userinfo = {};
39+
userinfo.bets = 0;
40+
userinfo.wins = 0;
41+
userinfo.losses = 0;
42+
userinfo.profit = 0;
43+
userinfo.wagered = 0;
44+
userinfo.balance = req.session.balance;
45+
userinfo.success = true;
46+
info.info = userinfo;
47+
req.session.info = info;
48+
return info;
49+
}
50+
51+
async clear(req) {
52+
let info = {};
53+
let userinfo = {};
54+
userinfo.bets = 0;
55+
userinfo.wins = 0;
56+
userinfo.losses = 0;
57+
userinfo.profit = 0;
58+
userinfo.wagered = 0;
59+
userinfo.balance = req.session.balance;
60+
userinfo.success = true;
61+
info.info = userinfo;
62+
info.currentInfo = {};
63+
info.currentInfo.balance = req.session.balance;
64+
info.currentInfo.bets = 0;
65+
info.currentInfo.wins = 0;
66+
info.currentInfo.losses = 0;
67+
info.currentInfo.profit = 0;
68+
info.currentInfo.wagered = 0;
69+
req.session.info = info;
70+
return info;
71+
}
72+
73+
async bet(req) {
74+
let accessToken = req.session.accessToken;
75+
let amount = parseFloat(req.body.PayIn/100000000);
76+
let currency = req.body.Currency.toLowerCase();
77+
let condition = req.body.High == "true"?"over":"under";
78+
let game = 0;
79+
let data = {};
80+
if(req.body.High == "true"){
81+
game = 9999-Math.floor((req.body.Chance*100));
82+
} else {
83+
game = Math.floor((req.body.Chance*100));
84+
}
85+
let multiplier = (100-1)/req.body.Chance;
86+
data.betAmount = ""+parseFloat(amount).toFixed(8);
87+
data.rollNumber= ""+game;
88+
data.rollDirection = condition;
89+
let ret = await this._send('api/bet', 'POST', data, accessToken);
90+
//console.log(ret);
91+
let info = req.session.info;
92+
let betInfo = {};
93+
betInfo.condition = req.body.High == "true"?'>':'<';
94+
betInfo.id = "clientseed:"+ret.message.currentClientSeed +"serverseed:"+ret.message.currentServerSeedHashed ;
95+
betInfo.target = game;
96+
betInfo.roll = ret.message.rollResult;
97+
betInfo.amount = amount.toFixed(8);
98+
info.info.bets++;
99+
info.currentInfo.bets++;
100+
if(ret.message.betStatus == "win"){
101+
betInfo.win = true;
102+
info.info.wins++;
103+
info.currentInfo.wins++;
104+
betInfo.profit = parseFloat(ret.message.balance).toFixed(8) - info.info.balance;
105+
betInfo.payout = parseFloat(amount+betInfo.profit).toFixed(8);
106+
} else {
107+
betInfo.win = false;
108+
info.info.losses++;
109+
info.currentInfo.losses++;
110+
betInfo.payout = 0;
111+
betInfo.profit = parseFloat(-betInfo.amount).toFixed(8);
112+
}
113+
//console.log(betInfo);
114+
info.info.profit = (parseFloat(info.info.profit) + parseFloat(betInfo.profit)).toFixed(8);
115+
info.info.balance = parseFloat(ret.message.balance).toFixed(8);
116+
info.currentInfo.balance = parseFloat(ret.message.balance).toFixed(8);
117+
info.info.wagered = (parseFloat(info.info.wagered) + parseFloat(betInfo.amount)).toFixed(8);
118+
info.currentInfo.wagered = (parseFloat(info.currentInfo.wagered)+parseFloat(betInfo.amount)).toFixed(8);
119+
info.currentInfo.profit = (parseFloat(info.currentInfo.profit)+parseFloat(betInfo.profit)).toFixed(8);
120+
let returnInfo = {};
121+
returnInfo.betInfo= betInfo;
122+
returnInfo.info = info;
123+
req.session.info = info;
124+
console.log(returnInfo);
125+
return returnInfo;
126+
}
127+
128+
async _send(route, method, body, cookie){
129+
let url = `${this.url}/${route}`;
130+
//console.log(JSON.stringify(body), cookie);
131+
let res = await fetch(url, {
132+
method,
133+
headers: {
134+
'User-Agent': 'MyDiceBot',
135+
'Content-Type': 'application/json',
136+
'Cookie': 'token='+cookie,
137+
},
138+
body: JSON.stringify(body),
139+
});
140+
let data = await res.json();
141+
console.log(data);
142+
if(route == 'api/login'){
143+
data.token = this._parseCookies(res);
144+
}
145+
146+
if(!data.valid) {
147+
let errs = new Error(data.message);
148+
errs.value = JSON.stringify(data.message);
149+
throw new APIError(data.message ,errs);
150+
}
151+
return data;
152+
}
153+
154+
_parseCookies(response) {
155+
let raw = response.headers.raw()['set-cookie'];
156+
let token = "";
157+
raw.forEach(function(entry) {
158+
let parts = entry.split(';');
159+
let cookiePart = parts[0];
160+
if(cookiePart.indexOf('token')>=0){
161+
token = cookiePart.split("=")[1];
162+
}
163+
});
164+
return token;
165+
}
166+
}

src/api/models/wolfbet.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,3 @@ module.exports = class WolfBet extends BaseDice {
186186
return data;
187187
}
188188
}
189-
exports.WinDice

src/api/routes/api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var DuckDice = require('../models/duckdice');
1515
var FreeBitco = require('../models/freebitco');
1616
var WinDice = require('../models/windice');
1717
var WolfBet = require('../models/wolfbet');
18+
var SatoshiDice = require('../models/satoshidice');
1819
var Factory = require('../models/factory');
1920
var config = require('config');
2021
var fs = require('fs');
@@ -78,6 +79,7 @@ function createDice (req, res, next) {
7879
Factory.register('WinDice', new WinDice());
7980
Factory.register('WolfBet', new WolfBet());
8081
Factory.register('999Doge', new NineDoge());
82+
Factory.register('SatoshiDice', new SatoshiDice());
8183
next();
8284
}
8385

src/console.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var path = require('path');
22
var fs = require('fs');
33
var util = require('util');
4+
var math = require('mathjs');
45
var readlineSync = require('readline-sync');
56
var Factory = require('./api/models/factory');
67
var BitslerDice = require('./api/models/bitsler');
@@ -17,7 +18,8 @@ var FreeBitco = require('./api/models/freebitco');
1718
var WinDice = require('./api/models/windice');
1819
var WolfBet = require('./api/models/wolfbet');
1920
var NineDoge = require('./api/models/ninedoge');
20-
let regpath = path.join(__dirname,'public/js/reg.js');
21+
var SatoshiDice = require('./api/models/satoshidice');
22+
var regpath = path.join(__dirname,'public/js/reg.js');
2123
eval(fs.readFileSync(regpath, 'utf8'));
2224
var readdir = util.promisify(fs.readdir);
2325

@@ -37,7 +39,8 @@ Factory.register('FreeBitco', new FreeBitco());
3739
Factory.register('WinDice', new WinDice());
3840
Factory.register('WolfBet', new WolfBet());
3941
Factory.register('999Doge', new NineDoge());
40-
var needUserSites = ['999Dice','FreeBitco','999Doge'];
42+
Factory.register('SatoshiDice', new SatoshiDice());
43+
var needUserSites = ['999Dice','FreeBitco','999Doge','SatoshiDice'];
4144
var needTokenSites = ['PrimeDice','Stake','WolfBet'];
4245
var needApiKeySites = ['Bitsler'];
4346
var needOnlyApiKeySites = ['YoloDice','Crypto-Games','DuckDice','WinDice'];
@@ -62,7 +65,7 @@ if(readlineSync.keyInYN('Whether to read the last configuration?')) {
6265
let rawdata = fs.readFileSync('./recent_account_info.json');
6366
req.body = JSON.parse(rawdata);
6467
} else {
65-
sites = ['Simulator', '999Dice', 'Bitsler', 'Crypto-Games', 'DuckDice', 'PrimeDice', 'Stake', 'YoloDice','WolfBet', 'FreeBitco.in', 'WinDice', 'EpicDice', 'KryptoGames', '999Doge'];
68+
sites = ['Simulator', '999Dice', 'Bitsler', 'Crypto-Games', 'DuckDice', 'PrimeDice', 'Stake', 'YoloDice','WolfBet', 'FreeBitco.in', 'WinDice', 'EpicDice', 'KryptoGames', '999Doge', 'SatoshiDice'];
6669
index = readlineSync.keyInSelect(sites, 'Which site?');
6770
if(index < 0 ){
6871
return false;
@@ -168,7 +171,7 @@ var datalog = grid.set(1.2, 0, 1.2, 4, contrib.log,
168171
, selectedFg: "green"
169172
, label: 'Bet Info'
170173
, border: {type: "line", fg: "cyan"}});
171-
var log = grid.set(2.4, 0, 1.6, 4, contrib.log,
174+
var logs = grid.set(2.4, 0, 1.6, 4, contrib.log,
172175
{ fg: "green"
173176
, selectedFg: "green"
174177
, label: 'Server Log'});
@@ -197,6 +200,15 @@ screen.key(['enter'],async function(ch, key) {
197200
isloop = true;
198201
stop = false;
199202
let i = 0;
203+
req.logdata = "betid,amount,low_high,payout,chance,actual_chance,profit";
204+
let nowdate = new Date();
205+
let logname = req.body.site+'_'+ nowdate.getFullYear() + '-' +
206+
("0" + (nowdate.getMonth() + 1)).slice(-2) + '-' +
207+
("0" + (nowdate.getDate())).slice(-2) + '_' +
208+
("0" + nowdate.getHours()).slice(-2) + '-' +
209+
("0" + nowdate.getMinutes()).slice(-2) + '-' +
210+
("0" + nowdate.getSeconds()).slice(-2)+ '_bet.csv';
211+
await saveLog(logname,req.logdata+'\r\n');
200212
betfunc = (() => {
201213
(async() => {
202214
if(!isloop || stop){
@@ -213,6 +225,7 @@ screen.key(['enter'],async function(ch, key) {
213225
await sleep(sleepTime);
214226
betfunc();
215227
}
228+
await saveLog(logname,req.logdata+'\r\n');
216229
i++;
217230
})();
218231
});
@@ -227,9 +240,9 @@ screen.render()
227240
console.log = function (message) {
228241
try {
229242
if (typeof message == 'object') {
230-
log.log(JSON && JSON.stringify ? (JSON.stringify(message)).replace(/\"/g,"") : message);
243+
logs.log(JSON && JSON.stringify ? (JSON.stringify(message)).replace(/\"/g,"") : message+"\r\n");
231244
} else {
232-
log.log(message);
245+
logs.log(message+"\r\n");
233246
}
234247
} catch(err){
235248
console.error(err);
@@ -261,7 +274,7 @@ async function betScript(req) {
261274
iswin = getWinStatus(ret);
262275
setStreak(iswin, currentAmount);
263276
setBetToLua(ret, currencyValue);
264-
consoleData(ret, iswin);
277+
req.logdata = consoleData(ret, iswin);
265278
consoleStats(ret.info, currencyValue);
266279
} catch(err){
267280
console.error(err);
@@ -275,6 +288,14 @@ async function betScript(req) {
275288
return false;
276289
}
277290
}
291+
292+
async function saveLog(logname, logdata){
293+
fs.writeFile('./log/'+logname, logdata, {flag: 'a'}, function (err) {
294+
if(err) {
295+
console.error(err);
296+
}
297+
});
298+
}
278299
async function scriptBet(init, req){
279300
try{
280301
if(!init){

src/package.json.console

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "mydicebot-console-200303",
2+
"name": "mydicebot-console-200328",
33
"version": "1.0.0",
44
"description": "MyDiceBot - Bet more, earn more!",
55
"homepage": "https://mydicebot.com",
@@ -8,9 +8,13 @@
88
"pkg": {
99
"scripts": [
1010
"public/**/info.js",
11-
"public/**/reg.js"
11+
"public/**/reg.js",
12+
"public/**/math.min.js"
1213
],
13-
"assets": "node_modules/blessed/**/*"
14+
"assets": [
15+
"node_modules/blessed/**/*",
16+
"node_modules/mathjs/**/*"
17+
]
1418
},
1519
"babel": {
1620
"presets": [
@@ -30,6 +34,7 @@
3034
"fs-extra": "^8.1.0",
3135
"graphql-request": "^1.8.2",
3236
"isomorphic-fetch": "^2.2.1",
37+
"mathjs": "^6.6.1",
3338
"minimist": "^1.2.0",
3439
"readline-sync": "^1.4.10",
3540
"request": "^2.88.0",

src/public/js/999Dice/info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ function consoleData(ret, iswin){
132132
let chanceStr = ret.High + ' '+ ret.BetRoll/10000 ;
133133
let profitStr = ((ret.PayOut-ret.PayIn)/100000000).toFixed(8);
134134
datalog.log('betid:' +ret.BetId + ' amount:'+ (ret.PayIn/100000000).toFixed(8)+ ' low_high:'+ ret.High+' payout:'+ (ret.PayOut/100000000).toFixed(8)+' chance:'+chanceStr+' actual_chance:'+ ret.Secret/10000 +' profit:'+profitStr );
135+
return ret.BetId + ','+ (ret.PayIn/100000000).toFixed(8)+ ','+ ret.High+','+ (ret.PayOut/100000000).toFixed(8)+','+chanceStr+','+ ret.Secret/10000 +','+profitStr ;
135136
}
136137

137138
function consoleStats(userinfo, cv){

src/public/js/999Doge/info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ function consoleData(ret, iswin){
132132
let chanceStr = ret.High + ' '+ ret.BetRoll/10000 ;
133133
let profitStr = ((ret.PayOut-ret.PayIn)/100000000).toFixed(8);
134134
datalog.log('betid:' +ret.BetId + ' amount:'+ (ret.PayIn/100000000).toFixed(8)+ ' low_high:'+ ret.High+' payout:'+ (ret.PayOut/100000000).toFixed(8)+' chance:'+chanceStr+' actual_chance:'+ ret.Secret/10000 +' profit:'+profitStr );
135+
return ret.BetId + ','+ (ret.PayIn/100000000).toFixed(8)+ ','+ ret.High+','+ (ret.PayOut/100000000).toFixed(8)+','+chanceStr+','+ ret.Secret/10000 +','+profitStr ;
135136
}
136137

137138
function consoleStats(userinfo, cv){

src/public/js/Bitsler/info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ function consoleData(ret, iswin){
147147
let chanceStr = ret.betInfo.condition + ' '+ ret.betInfo.target;
148148
let profitStr = ret.betInfo.profit;
149149
datalog.log('betid:' +ret.betInfo.id + ' amount:'+ ret.betInfo.amount+ ' low_high:'+ ret.betInfo.condition+' payout:'+ (ret.betInfo.payout).toFixed(8) +' chance:'+chanceStr+' actual_chance:'+ ret.betInfo.result +' profit:'+profitStr );
150+
return ret.betInfo.id + ','+ ret.betInfo.amount+ ','+ ret.betInfo.condition+','+ (ret.betInfo.payout).toFixed(8) +','+chanceStr+','+ ret.betInfo.result +','+profitStr;
150151
}
151152

152153
function consoleStats(userinfo, cv){

src/public/js/Crypto-Games/info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function consoleData(ret, iswin){
142142
let chanceStr = ret.betInfo.condition + ' '+ ret.betInfo.target;
143143
let profitStr = ret.betInfo.profit;
144144
datalog.log('betid:' +ret.betInfo.id + ' amount:'+ ret.betInfo.amount+ ' low_high:'+ ret.betInfo.condition+' payout:'+ ret.betInfo.payout +' chance:'+chanceStr+' actual_chance:'+ ret.betInfo.roll +' profit:'+profitStr );
145+
return ret.betInfo.id + ','+ ret.betInfo.amount+ ','+ ret.betInfo.condition+','+ ret.betInfo.payout +','+chanceStr+','+ ret.betInfo.roll +','+profitStr;
145146
}
146147

147148
function consoleStats(userinfo, cv){

src/public/js/DuckDice/info.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ function consoleData(ret, iswin){
144144
let chanceStr = ret.betInfo.condition + ' '+ ret.betInfo.target;
145145
let profitStr = ret.betInfo.profit;
146146
datalog.log('betid:' +ret.betInfo.id + ' amount:'+ ret.betInfo.amount+ ' low_high:'+ ret.betInfo.condition+' payout:'+ (ret.betInfo.payout).toFixed(8) +' chance:'+chanceStr+' actual_chance:'+ ret.betInfo.result +' profit:'+profitStr );
147+
return ret.betInfo.id + ','+ ret.betInfo.amount+ ','+ ret.betInfo.condition+','+ (ret.betInfo.payout).toFixed(8) +','+chanceStr+','+ ret.betInfo.result +','+profitStr;
148+
147149
}
148150

149151
function consoleStats(userinfo, cv){

src/public/js/EpicDice/info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ function consoleData(ret, iswin){
138138
let chanceStr = ret.betInfo.condition + ' '+ ret.betInfo.target;
139139
let profitStr = ret.betInfo.profit;
140140
datalog.log('betid:' +ret.betInfo.id + ' amount:'+ ret.betInfo.amount+ ' low_high:'+ ret.betInfo.condition+' payout:'+ ret.betInfo.payout +' chance:'+chanceStr+' actual_chance:'+ ret.betInfo.roll_number +' profit:'+profitStr );
141+
return ret.betInfo.id + ','+ ret.betInfo.amount+ ','+ ret.betInfo.condition+','+ (ret.betInfo.payout).toFixed(8) +','+chanceStr+','+ ret.betInfo.roll_numer +','+profitStr;
141142
}
142143

143144
function consoleStats(userinfo, cv){

src/public/js/FreeBitco/info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ function consoleData(ret, iswin){
132132
let chanceStr = ret.betInfo.condition + ' '+ ret.betInfo.target;
133133
let profitStr = ret.betInfo.profit;
134134
datalog.log('betid:' +ret.betInfo.id + ' amount:'+ ret.betInfo.amount+ ' low_high:'+ ret.betInfo.condition+' payout:'+ ret.betInfo.payout +' chance:'+chanceStr+' actual_chance:'+ ret.betInfo.roll +' profit:'+profitStr );
135+
return ret.betInfo.id + ','+ ret.betInfo.amount+ ','+ ret.betInfo.condition+','+ (ret.betInfo.payout).toFixed(8) +','+chanceStr+','+ ret.betInfo.roll +','+profitStr;
135136
}
136137

137138
function consoleStats(userinfo, cv){

0 commit comments

Comments
 (0)