Skip to content

Commit c8d7f37

Browse files
author
mydicebot
committed
v190610 - add kryptogamers support
1 parent 616c490 commit c8d7f37

File tree

9 files changed

+483
-28
lines changed

9 files changed

+483
-28
lines changed

README.md

+20-11
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* [MyDiceBot](https://mydicebot.com) is World #1 Cross-Platform Dicing Bot.
55
* Multiple platforms are supported, including __Windows, Mac, Linux,__ and __Web__.
66
* Multiple blockchains are supported, including __STEEM__.
7-
* Multiple programming languages are supported such as __Lua__.
8-
* [Open Source](https://github.com/mydicebot/mydicebot.github.io) and __Free Forever__
7+
* Multiple programming languages are supported such as __Lua__ and __Javascript__.
8+
* [Open Source](https://github.com/mydicebot/mydicebot.github.io) and __Free Forever__.
99

1010
![](screenshot/mydicebot-1000-win.png)
1111

@@ -49,6 +49,7 @@
4949
* [YoloDice](https://yolodice.com/r?6fAf-wVz)
5050
## Blockchain - STEEM
5151
* [EpicDice](https://epicdice.io/?ref=mydicebot)
52+
* [KryptoGames](https://kryptogamers.com/?ref=mydicebot)
5253
* [SteemBet](https://steem-bet.com?ref=mydicebot)
5354

5455
# TODO
@@ -97,16 +98,9 @@
9798
* Choose Dice Site, Input username/password/2FA/APIKey, then Login.
9899
* Bet and WIN.
99100
100-
# Startup Options
101-
* __-port__ (port is 3000 by default)
102-
103-
```
104-
mydicebot-win.exe -port 12345
105-
```
106-
107101
# Features
108102
* Supported platforms: __Windows, Mac, Linux, Web__
109-
* Supported programming languages: __Lua__
103+
* Supported programming languages: __Lua__ and __Javascript__
110104
* Supported multiple dice-sites
111105
* Supported multiple strategies
112106
* New account registration
@@ -170,7 +164,7 @@
170164
171165
## Sample Code
172166
* Strategy: Basic Martingale
173-
167+
* Using Lua
174168
```lua
175169
chance = 49.5
176170
multiplier = 2
@@ -189,6 +183,21 @@ function dobet()
189183
end
190184
end
191185
```
186+
* Using Javascript
187+
```javascript
188+
chance = 49.5;
189+
multiplier = 2;
190+
baseBet = 0.00000001;
191+
betHigh = false;
192+
193+
function dobet() {
194+
if (win) {
195+
nextBet = basebet;
196+
} else {
197+
nextBet = previousbet * multiplier;
198+
}
199+
}
200+
```
192201

193202
# Report Issue
194203
* [https://github.com/mydicebot/mydicebot.github.io/issues](https://github.com/mydicebot/mydicebot.github.io/issues)

src/api/controllers/apiController.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ let registerUrls = {
2929
"YoloDice":"https://yolodice.com/r?6fAf-wVz",
3030
"EpicDice": "https://magic-dice.com/?ref=mydicebot",
3131
"SteemBet": "https://magic-dice.com/?ref=mydicebot",
32+
"KryptoGames": "https://magic-dice.com/?ref=mydicebot",
3233
};
3334

3435
let mydiceUrls = {

src/api/models/kryptogames.js

+305
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
'use strict';
2+
3+
import {BaseDice} from './base'
4+
import FormData from 'form-data';
5+
import {APIError} from '../errors/APIError';
6+
import steem from 'steem';
7+
import request from 'request';
8+
import fetch from 'isomorphic-fetch';
9+
10+
export class KryptoGames extends BaseDice {
11+
constructor(){
12+
super();
13+
this.url = 'https://kryptogames.io';
14+
this.benefit = '?ref=mydicebot'
15+
this.currencys = ["steem","sbd"];
16+
steem.api.setOptions({url:'https://api.steemit.com'});
17+
}
18+
19+
async login(userName, password, twoFactor ,apiKey, req) {
20+
req.session.accessToken = apiKey;
21+
req.session.username = userName;
22+
return true;
23+
}
24+
25+
async getUserInfo(req) {
26+
let info = req.session.info;
27+
if(typeof info != 'undefined'){
28+
return true;
29+
}
30+
let userName = req.session.username;
31+
let ret = await steem.api.getAccountsAsync([userName]);
32+
let userinfo = {
33+
'bets' : 0,
34+
'wins' : 0,
35+
'losses' : 0,
36+
'profit' : 0,
37+
'wagered' : 0,
38+
'balance' : 0,
39+
};
40+
for(let k in ret){
41+
let sbd = ret[k]['sbd_balance'].split(' ');
42+
let steem_balance = ret[k]['balance'].split(' ');
43+
userinfo.balance = parseFloat(steem_balance[0]);
44+
}
45+
info = {};
46+
let currentInfo = userinfo;
47+
info.info = userinfo;
48+
req.session.info = info;
49+
console.log(req.session.info);
50+
return info;
51+
}
52+
53+
async refresh(req) {
54+
let info = req.session.info;
55+
if(info){
56+
return info;
57+
}
58+
let userName = req.session.username;
59+
let ret = await steem.api.getAccountsAsync([userName]);
60+
for(let k in ret){
61+
let balance = new Array();
62+
balance['sbd'] = ret[k]['sbd_balance'].split(' ');
63+
balance['steem'] = ret[k]['balance'].split(' ');
64+
info.info.balance = parseFloat(balance[req.query.currency][0]);
65+
}
66+
req.session.info = info;
67+
return info;
68+
}
69+
70+
async clear(req) {
71+
let userName = req.session.username;
72+
let ret = await steem.api.getAccountsAsync([userName]);
73+
let info = {};
74+
info.info = {
75+
'bets' : 0,
76+
'wins' : 0,
77+
'losses' : 0,
78+
'profit' : 0,
79+
'wagered' : 0,
80+
'balance' : 0,
81+
};
82+
info.currentInfo = {
83+
'bets' : 0,
84+
'wins' : 0,
85+
'losses' : 0,
86+
'profit' : 0,
87+
'wagered' : 0,
88+
'balance' : 0,
89+
}
90+
for(let k in ret){
91+
let balance = new Array();
92+
balance['sbd'] = ret[k]['sbd_balance'].split(' ');
93+
balance['steem'] = ret[k]['balance'].split(' ');
94+
info.info.balance = parseFloat(balance[req.query.currency][0]);
95+
info.currentInfo.balance = parseFloat(balance[req.query.currency][0]);
96+
info.info.success = 'true';
97+
}
98+
req.session.info = info;
99+
return info;
100+
}
101+
102+
async bet(req) {
103+
req.setTimeout(500000);
104+
let info = req.session.info;
105+
let amount = (req.body.PayIn/100000000).toFixed(3);
106+
let condition = 'under';
107+
let currency = req.body.Currency.toLowerCase();
108+
let target = 0;
109+
target = Math.floor(req.body.Chance) + 1;
110+
let cseed = Math.random().toString(36).substring(2);
111+
let memo = 'BRoll ' + condition + ' ' + target + ' '+ cseed;
112+
let bet = amount + ' '+ req.body.Currency.toUpperCase();
113+
let userName = req.session.username;
114+
let token = req.session.accessToken;
115+
let kryptoGamesDice = 'kryptogames';
116+
try{
117+
let ret = await this._transfer(token, userName, kryptoGamesDice, bet, memo);
118+
let data = await this._getBetInfo(ret.id, userName, cseed);
119+
if(typeof data._id == "undefined") {
120+
data = await this._getBetInfoFromUser(userName,ret.id, cseed);
121+
}
122+
if(typeof data._id != "undefined") {
123+
data.amount = amount;
124+
let betInfo = {};
125+
betInfo.id = data._id;
126+
betInfo.condition = '<';
127+
betInfo.target = target;
128+
betInfo.profit = (parseFloat(data.payout) - parseFloat(data.amount)).toFixed(8);
129+
betInfo.roll_number = data.diceRoll;
130+
betInfo.payout = parseFloat(data.payout).toFixed(8);
131+
betInfo.amount = parseFloat(data.amount).toFixed(8);
132+
info.info.balance = (parseFloat(info.info.balance) + parseFloat(betInfo.profit)).toFixed(8);
133+
info.currentInfo.balance = (parseFloat(info.currentInfo.balance) + parseFloat(betInfo.profit)).toFixed(8);
134+
info.info.bets++;
135+
info.currentInfo.bets++;
136+
info.info.profit = (parseFloat(info.info.profit) + parseFloat(betInfo.profit)).toFixed(8);
137+
info.info.wagered = (parseFloat(info.info.wagered) + parseFloat(amount)).toFixed(8);
138+
info.currentInfo.wagered = (parseFloat(info.currentInfo.wagered) + parseFloat(amount)).toFixed(8);
139+
info.currentInfo.profit = (parseFloat(info.currentInfo.profit) + parseFloat(betInfo.profit)).toFixed(8);
140+
if(data.won){
141+
betInfo.win = true;
142+
info.info.wins++;
143+
info.currentInfo.wins++;
144+
} else {
145+
betInfo.win = false;
146+
info.info.losses++;
147+
info.currentInfo.losses++;
148+
}
149+
let returnInfo = {};
150+
returnInfo.betInfo= betInfo;
151+
returnInfo.info = info;
152+
req.session.info = info;
153+
return returnInfo;
154+
} else {
155+
throw new Error('bet data is null');
156+
}
157+
} catch(e) {
158+
throw e;
159+
}
160+
}
161+
162+
async _getBetInfoFromUser(account, id, cseed){
163+
let memoRegEx = /\{(.*)/;
164+
return new Promise(async (resolve, reject) => {
165+
try {
166+
let options = {
167+
url: ' https://api.steemit.com',
168+
method: 'POST',
169+
json: {
170+
jsonrpc: '2.0',
171+
method: 'condenser_api.get_account_history',
172+
params: [account, -1, 1],
173+
id: 1
174+
},
175+
timeout:10000
176+
};
177+
for(let tryQueryCount=0; tryQueryCount<20; tryQueryCount++) {
178+
let data = await this._queryUserInfo(options,id,cseed);
179+
if(data !== undefined){
180+
tryQueryCount = 999;
181+
console.log(data);
182+
resolve(data)
183+
} else {
184+
console.log('Waiting for blockchain packing.....');
185+
await this._sleep(15000);
186+
}
187+
}
188+
resolve('not found')
189+
} catch (e) {
190+
reject( e );
191+
}
192+
});
193+
}
194+
195+
196+
197+
async _getBetInfo(id, userName, cseed){
198+
let memoRegEx = /\{(.*)/;
199+
let tryQueryCount = 0;
200+
return new Promise(( resolve, reject ) => {
201+
let release = steem.api.streamOperations(async function (err, op) {
202+
if (err) {
203+
reject( err );
204+
} else {
205+
if (op[0] === "transfer" && op[1].to === userName) {
206+
if (op[1].from === "kryptogames" && op[1].memo.startsWith("You")) {
207+
tryQueryCount++;
208+
try {
209+
memoRegEx = /Client Seed: ([A-Za-z0-9]+),/;
210+
let clientSeed = memoRegEx.exec(op[1].memo)[1] ;
211+
if(clientSeed == cseed ){
212+
release();
213+
let memo = op[1].memo;
214+
let steems = op[1].amount.split(' ');
215+
let data = {};
216+
console.log(memo);
217+
data.payout = steems[0];
218+
data._id = id;
219+
memoRegEx = /Result: ([0-9]+),/;
220+
data.diceRoll = memoRegEx.exec(op[1].memo)[1] ;
221+
data.won = false;
222+
if (memo.indexOf("Won")>0) {
223+
data.won = true;
224+
}
225+
resolve(data);
226+
}
227+
} catch (e) {
228+
reject( e );
229+
}
230+
}
231+
if (op[1].from === "kryptogames" && !op[1].memo.startsWith("You")) {
232+
release();
233+
let memo = op[1].memo;
234+
console.log(memo);
235+
reject(memo);
236+
}
237+
}
238+
}
239+
if(tryQueryCount>=100){
240+
release();
241+
resolve({});
242+
}
243+
});
244+
});
245+
}
246+
247+
async _transfer(p,u,t,s,m){
248+
return new Promise(( resolve, reject ) => {
249+
steem.broadcast.transfer(p, u, t, s, m, function(err, result){
250+
if(err) {
251+
reject( err );
252+
} else {
253+
resolve( result );
254+
}
255+
});
256+
});
257+
}
258+
async _sleep(ms) {
259+
return new Promise(resolve => setTimeout(resolve, ms))
260+
}
261+
262+
async _queryUserInfo(options, id, cseed){
263+
let memoRegEx = /\{(.*)/;
264+
return new Promise(( resolve, reject ) => {
265+
let req = request.post(options,function (e, r, body) {
266+
if(e) {
267+
console.log('reject error');
268+
reject( e );
269+
} else {
270+
if(body) {
271+
let res = body.result;
272+
for(let k in res) {
273+
let tran = res[k][1].op;
274+
try {
275+
if (tran[0] == "transfer" && tran[1].from == "kryptogames" && tran[1].memo.startsWith("You")) {
276+
memoRegEx = /Client Seed: ([A-Za-z0-9]+),/;
277+
let clientSeed = memoRegEx.exec(tran[1].memo)[1] ;
278+
console.log(clientSeed, cseed);
279+
if(clientSeed == cseed ){
280+
let memo = tran[1].memo;
281+
let steems = tran[1].amount.split(' ');
282+
let data = {};
283+
console.log(memo);
284+
data.payout = steems[0];
285+
data._id = id;
286+
memoRegEx = /Result: ([0-9]+),/;
287+
data.diceRoll = memoRegEx.exec(tran[1].memo)[1] ;
288+
data.won = false;
289+
if (memo.indexOf("Won")>0) {
290+
data.won = true;
291+
}
292+
resolve(data);
293+
}
294+
}
295+
} catch (e) {
296+
reject( e );
297+
}
298+
}
299+
}
300+
resolve();
301+
}
302+
});
303+
});
304+
}
305+
}

src/api/routes/api.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {MagicDice} from '../models/magic';
1212
import {Simulator} from '../models/simulator';
1313
import {EpicDice} from '../models/epic';
1414
import {SteemBet} from '../models/steembet';
15+
import {KryptoGames} from '../models/kryptogames';
1516
import {Factory} from '../models/factory';
1617
import fs from 'fs';
1718
import path from 'path';
@@ -73,6 +74,7 @@ function createDice (req, res, next) {
7374
Factory.register('Simulator', new Simulator());
7475
Factory.register('EpicDice', new EpicDice());
7576
Factory.register('SteemBet', new SteemBet());
77+
Factory.register('KryptoGames', new KryptoGames());
7678
next();
7779
}
7880

0 commit comments

Comments
 (0)