Skip to content

Commit 1bf0bed

Browse files
author
bot
committed
update
1 parent ca77f91 commit 1bf0bed

File tree

4 files changed

+183
-126
lines changed

4 files changed

+183
-126
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,11 @@ bash start.sh
230230
|__start()__|Start the bet (from very beginning) after stop()|
231231
|__resume()__|Resume the bet (from current stopping) after stop()|
232232
|__resetsession()__|Reset the session|
233+
|__resetstats()__|Reset the session|
233234
|__resetseed()__|Reset the client seed|
234235
|__sound(path_of_the_sound)__|Sound notificaiton|
235236
|__message(text, type=\'debug\', expire=time_interval_value_in_ms)__|Message notification on the screen. Four types: "info", "success", "debug", or "error". Expire interval is 4000 ms by default, -1 for not hiding the message.|
237+
|__betinterval(ms)__|Bet Interval in milliseconds|
236238

237239
## Sample Code
238240
* Strategy: Basic Martingale

src/api/models/yolo.js

+29-7
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@ var bitcore = require('bitcore-lib');
66
var Message = require('bitcore-message');
77

88
module.exports = class YoloDice extends BaseDice {
9+
910
constructor(proxy){
1011
super(proxy);
1112
this.host = 'api.yolodice.com';
1213
this.port = '4444';
14+
this.connected = false;
1315
}
1416

1517
async connect(apiKey){
18+
let yolo = this;
1619
this.id = 0;
1720
this.client = tls.connect(this.port, this.host);
21+
this.client.setKeepAlive(true, 0);
22+
1823
this.client.on('close', function() {
24+
yolo.connected = false;
1925
console.log("Connection closed");
2026
});
2127
this.client.on('error', function(error) {
22-
console.error(error);
23-
this.client.destroy();
28+
yolo.connected = false;
29+
console.log(error);
2430
});
2531
let options = {
2632
id: this.id++,
@@ -41,6 +47,7 @@ module.exports = class YoloDice extends BaseDice {
4147
}
4248
ret = await this._send(options);
4349
let user = JSON.parse(ret).result;
50+
this.connected = true;
4451
return user;
4552
}
4653

@@ -53,8 +60,11 @@ module.exports = class YoloDice extends BaseDice {
5360
}
5461

5562
async refresh(req) {
63+
if(!this.connected){
64+
await this.connect(req.session.apiKey);
65+
}
5666
//console.log('refresh')
57-
await this.connect(req.session.apiKey);
67+
//await this.connect(req.session.apiKey);
5868
let options = {
5969
id:this.id++,
6070
method: 'read_user_coin_data',
@@ -78,7 +88,10 @@ module.exports = class YoloDice extends BaseDice {
7888

7989
async clear(req) {
8090
console.log('loading....');
81-
await this.connect(req.session.apiKey);
91+
if(!this.connected){
92+
await this.connect(req.session.apiKey);
93+
}
94+
//await this.connect(req.session.apiKey);
8295
let options = {
8396
id:this.id++,
8497
method: 'read_user_coin_data',
@@ -103,7 +116,10 @@ module.exports = class YoloDice extends BaseDice {
103116
}
104117

105118
async bet(req) {
106-
await this.connect(req.session.apiKey);
119+
//await this.connect(req.session.apiKey);
120+
if(!this.connected){
121+
await this.connect(req.session.apiKey);
122+
}
107123
let betRoll = 0;
108124
let currency = req.body.Currency.toLowerCase();
109125
//console.log(currency)
@@ -164,7 +180,10 @@ module.exports = class YoloDice extends BaseDice {
164180

165181
async getUserInfo(req) {
166182
//console.log('get user info')
167-
await this.connect(req.session.apiKey);
183+
//await this.connect(req.session.apiKey);
184+
if(!this.connected){
185+
await this.connect(req.session.apiKey);
186+
}
168187
let options = {
169188
id:this.id++,
170189
method: 'read_user_coin_data',
@@ -188,7 +207,10 @@ module.exports = class YoloDice extends BaseDice {
188207
}
189208

190209
async resetseed(req) {
191-
await this.connect(req.session.apiKey);
210+
//await this.connect(req.session.apiKey);
211+
if(!this.connected){
212+
await this.connect(req.session.apiKey);
213+
}
192214
let seed = Math.random().toString(32).substring(2);
193215
let options = {
194216
id:this.id++,

src/package.json.console

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "mydicebot-console-200809",
2+
"name": "mydicebot-console-200815",
33
"version": "1.0.0",
44
"description": "MyDiceBot - Bet more, earn more!",
55
"homepage": "https://mydicebot.com",

0 commit comments

Comments
 (0)