Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bot committed Aug 15, 2020
1 parent ca77f91 commit 1bf0bed
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 126 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ bash start.sh
|__start()__|Start the bet (from very beginning) after stop()|
|__resume()__|Resume the bet (from current stopping) after stop()|
|__resetsession()__|Reset the session|
|__resetstats()__|Reset the session|
|__resetseed()__|Reset the client seed|
|__sound(path_of_the_sound)__|Sound notificaiton|
|__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.|
|__betinterval(ms)__|Bet Interval in milliseconds|

## Sample Code
* Strategy: Basic Martingale
Expand Down
36 changes: 29 additions & 7 deletions src/api/models/yolo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ var bitcore = require('bitcore-lib');
var Message = require('bitcore-message');

module.exports = class YoloDice extends BaseDice {

constructor(proxy){
super(proxy);
this.host = 'api.yolodice.com';
this.port = '4444';
this.connected = false;
}

async connect(apiKey){
let yolo = this;
this.id = 0;
this.client = tls.connect(this.port, this.host);
this.client.setKeepAlive(true, 0);

this.client.on('close', function() {
yolo.connected = false;
console.log("Connection closed");
});
this.client.on('error', function(error) {
console.error(error);
this.client.destroy();
yolo.connected = false;
console.log(error);
});
let options = {
id: this.id++,
Expand All @@ -41,6 +47,7 @@ module.exports = class YoloDice extends BaseDice {
}
ret = await this._send(options);
let user = JSON.parse(ret).result;
this.connected = true;
return user;
}

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

async refresh(req) {
if(!this.connected){
await this.connect(req.session.apiKey);
}
//console.log('refresh')
await this.connect(req.session.apiKey);
//await this.connect(req.session.apiKey);
let options = {
id:this.id++,
method: 'read_user_coin_data',
Expand All @@ -78,7 +88,10 @@ module.exports = class YoloDice extends BaseDice {

async clear(req) {
console.log('loading....');
await this.connect(req.session.apiKey);
if(!this.connected){
await this.connect(req.session.apiKey);
}
//await this.connect(req.session.apiKey);
let options = {
id:this.id++,
method: 'read_user_coin_data',
Expand All @@ -103,7 +116,10 @@ module.exports = class YoloDice extends BaseDice {
}

async bet(req) {
await this.connect(req.session.apiKey);
//await this.connect(req.session.apiKey);
if(!this.connected){
await this.connect(req.session.apiKey);
}
let betRoll = 0;
let currency = req.body.Currency.toLowerCase();
//console.log(currency)
Expand Down Expand Up @@ -164,7 +180,10 @@ module.exports = class YoloDice extends BaseDice {

async getUserInfo(req) {
//console.log('get user info')
await this.connect(req.session.apiKey);
//await this.connect(req.session.apiKey);
if(!this.connected){
await this.connect(req.session.apiKey);
}
let options = {
id:this.id++,
method: 'read_user_coin_data',
Expand All @@ -188,7 +207,10 @@ module.exports = class YoloDice extends BaseDice {
}

async resetseed(req) {
await this.connect(req.session.apiKey);
//await this.connect(req.session.apiKey);
if(!this.connected){
await this.connect(req.session.apiKey);
}
let seed = Math.random().toString(32).substring(2);
let options = {
id:this.id++,
Expand Down
2 changes: 1 addition & 1 deletion src/package.json.console
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "mydicebot-console-200809",
"name": "mydicebot-console-200815",
"version": "1.0.0",
"description": "MyDiceBot - Bet more, earn more!",
"homepage": "https://mydicebot.com",
Expand Down
Loading

0 comments on commit 1bf0bed

Please sign in to comment.