Skip to content

Commit d48dd81

Browse files
author
mydicebot
committed
Fixed bug : proxy switch
Adapted to the latest APIs of prime and stake Adjust the console version error log output Fixed bug : freebitco console version Finished : issue #94 Increase currency (Bitsler,DuckDice,PrimeDice,Stake)
1 parent 1cbc4bc commit d48dd81

File tree

9 files changed

+149
-46
lines changed

9 files changed

+149
-46
lines changed

src/api/models/prime.js

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module.exports = class PrimeDice extends BaseDice {
1515

1616
async login(userName, password, twoFactor ,apiKey, req) {
1717
let data = {};
18-
data.query = "{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses amount profit currency}}}";
18+
//data.query = "{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses amount profit currency}}}";
19+
data.query = "query DiceBotGetBalance{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses betAmount profit currency}}}";
1920
let ret = await this._send('', 'POST', data, apiKey);
2021
req.session.accessToken = apiKey;
2122
req.session.username = apiKey;
@@ -33,7 +34,8 @@ module.exports = class PrimeDice extends BaseDice {
3334
return false;
3435
}
3536
let data = {};
36-
data.query = "{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses betAmount profit currency}}}";
37+
//data.query = "{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses betAmount profit currency}}}";
38+
data.query = "query DiceBotGetBalance{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses betAmount profit currency}}}";
3739
let ret = await this._send('', 'POST', data, req.session.accessToken);
3840
ret = ret.user;
3941
let userinfo = {
@@ -67,7 +69,8 @@ module.exports = class PrimeDice extends BaseDice {
6769
async clear(req) {
6870
console.log('loading....');
6971
let data = {};
70-
data.query = "{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses betAmount profit currency}}}";
72+
//data.query = "{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses betAmount profit currency}}}";
73+
data.query = "query DiceBotGetBalance{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses betAmount profit currency}}}";
7174
let ret = await this._send('', 'POST', data, req.session.accessToken);
7275
ret=ret.user;
7376
let info = {};
@@ -121,14 +124,23 @@ module.exports = class PrimeDice extends BaseDice {
121124
target = Math.floor((req.body.Chance*100));
122125
}
123126
target = parseFloat(target/100).toFixed(2);
124-
let data = {};
125-
data.query = " mutation{primediceRoll(amount:"+amount+",target:"+target+",condition:"+ condition +",currency:"+currency+ ") { id nonce currency amount payout state { ... on CasinoGamePrimedice { result target condition } } createdAt serverSeed{seedHash seed nonce} clientSeed{seed} user{balances{available{amount currency}} statistic{game bets wins losses betAmount profit currency}}}}";
126-
let ret = await this._send('', 'POST', data, req.session.accessToken);
127+
//let data = {};
128+
//data.query = "mutation DiceBotDiceBet($amount: Float!, $target: Float!, $condition: CasinoGamePrimediceConditionEnum!, $currency: CurrencyEnum!, $identifier: String!) { primediceRoll(amount: $amount, target: $target, condition: $condition, currency: $currency, identifier: $identifier) { id nonce currency amount payout state { ... on CasinoGamePrimedice { result target condition } } createdAt serverSeed{seedHash seed nonce} clientSeed{seed} user{balances{available{amount currency}} statistic{game bets wins losses betAmount profit currency}}}}";
129+
//let variables = {};
130+
//variables.amount = amount;
131+
//variables.target = target;
132+
//variables.condition = condition;
133+
//variables.currency = currency;
134+
//data.variables = variables;
135+
let betdata = "{\"operationName\":\"PrimediceRoll\",\"variables\":{\"currency\":\""+currency+"\",\"amount\":"+amount+",\"target\":"+target+",\"condition\":\""+condition+"\"},\"query\":\"mutation PrimediceRoll($amount: Float!, $target: Float!, $condition: CasinoGamePrimediceConditionEnum!, $currency: CurrencyEnum!) {\\n primediceRoll(amount: $amount, target: $target, condition: $condition, currency: $currency) {\\n ...CasinoBetFragment\\n state {\\n ...PrimediceStateFragment\\n __typename\\n }\\n __typename\\n }\\n}\\n\\nfragment CasinoBetFragment on CasinoBet {\\n id\\n active\\n payoutMultiplier\\n amountMultiplier\\n amount\\n payout\\n updatedAt\\n currency\\n game\\n user {\\n id\\n name\\n __typename\\n }\\n __typename\\n}\\n\\nfragment PrimediceStateFragment on CasinoGamePrimedice {\\n result\\n target\\n condition\\n __typename\\n}\\n\"}";
136+
let ret = await this._sendbet('', 'POST', betdata, req.session.accessToken);
127137
let info = req.session.info;
128138
let betInfo = ret.primediceRoll;
129-
data = {};
130-
data.query = "{bet(betId:\""+betInfo.id+"\"){iid}}";
131-
let dataIID = await this._send('', 'POST', data, req.session.accessToken);
139+
//console.log(betInfo);
140+
betdata = "{\"operationName\":\"Bet\",\"variables\":{\"betId\":\""+betInfo.id+"\"},\"query\":\"query Bet($iid: String, $betId: String) {\\n bet(iid: $iid, betId: $betId) {\\n ...PrimediceBetFragment\\n __typename\\n }\\n}\\n\\nfragment PrimediceBetFragment on Bet {\\n id\\n iid\\n type\\n bet {\\n ... on CasinoBet {\\n ...CasinoBetFragment\\n state {\\n ... on CasinoGamePrimedice {\\n result\\n target\\n condition\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n}\\n\\nfragment CasinoBetFragment on CasinoBet {\\n id\\n active\\n payoutMultiplier\\n amount\\n payout\\n updatedAt\\n currency\\n game\\n user {\\n id\\n name\\n __typename\\n }\\n __typename\\n}\\n\"}";
141+
142+
let dataIID = await this._sendbet('', 'POST', betdata, req.session.accessToken);
143+
//console.log(dataIID);
132144
betInfo.iid = dataIID.bet.iid.split(":")[1];
133145
betInfo.condition = req.body.High == "true"?'>':'<';
134146
betInfo.target = target;
@@ -162,8 +174,11 @@ module.exports = class PrimeDice extends BaseDice {
162174

163175
async resetseed(req) {
164176
let clientSeed = Math.random().toString(36).substring(2);
165-
data = {};
166-
data.query = "mutation{rotateServerSeed{ seed seedHash nonce } changeClientSeed(seed:\"" + clientSeed + "\"){seed}}"
177+
let data = {};
178+
let variables = {};
179+
data.query = "mutation DiceBotRotateSeed ($seed: String!){rotateServerSeed{ seed seedHash nonce } changeClientSeed(seed: $seed){seed}}";
180+
variables.seed = clientSeed;
181+
data.variables = variables;
167182
let ret = await this._send('', 'POST', data, req.session.accessToken);
168183
console.log(clientSeed, ret);
169184
let info = {};
@@ -174,11 +189,11 @@ module.exports = class PrimeDice extends BaseDice {
174189
}
175190

176191
async _send(route, method, body, accessToken){
192+
console.log(JSON.stringify(body))
177193
let url = `${this.url}`;
178194
let options = {
179195
method,
180196
headers: {
181-
'User-Agent': 'MyDiceBot',
182197
'x-access-token': accessToken,
183198
'Content-Type': 'application/json',
184199
},
@@ -202,5 +217,35 @@ module.exports = class PrimeDice extends BaseDice {
202217
let ret = data.data;
203218
return ret;
204219
}
220+
221+
async _sendbet(route, method, body, accessToken){
222+
let url = `${this.url}`;
223+
let options = {
224+
method: method,
225+
headers: {
226+
'x-access-token': accessToken,
227+
'Content-Type': 'application/json',
228+
},
229+
body: body
230+
};
231+
if(this.proxy.ip) {
232+
let socks = 'socks://'+this.proxy.ip+':'+this.proxy.port;
233+
if(this.proxy.user){
234+
socks = 'socks://'+this.proxy.user+':'+this.proxy.password+'@'+this.proxy.ip+':'+this.proxy.port;
235+
}
236+
let agent = new SocksProxyAgent(socks);
237+
options.agent = agent;
238+
}
239+
options.body = body;
240+
let res = await fetch(url, options);
241+
let data = await res.json();
242+
if(data.errors) {
243+
let errs = new Error(data.errors[0].message);
244+
errs.value = data.errors[0].message;
245+
throw new APIError(data.errors[0].message ,errs);
246+
}
247+
let ret = data.data;
248+
return ret;
249+
}
205250
}
206251
exports.PrimeDice

src/api/models/stake.js

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = class StakeDice extends BaseDice {
1515

1616
async login(userName, password, twoFactor ,apiKey, req) {
1717
let data = {};
18-
data.query = "{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses amount profit currency}}}";
18+
data.query = "query DiceBotGetBalance{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses betAmount profit currency}}}";
1919
let ret = await this._send('', 'POST', data, apiKey);
2020
req.session.accessToken = apiKey;
2121
req.session.username = apiKey;
@@ -33,7 +33,7 @@ module.exports = class StakeDice extends BaseDice {
3333
return false;
3434
}
3535
let data = {};
36-
data.query = "{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses betAmount profit currency}}}";
36+
data.query = "query DiceBotGetBalance{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses betAmount profit currency}}}";
3737
let ret = await this._send('', 'POST', data, req.session.accessToken);
3838
ret = ret.user;
3939
let userinfo = {
@@ -67,7 +67,7 @@ module.exports = class StakeDice extends BaseDice {
6767
async clear(req) {
6868
console.log('loading....');
6969
let data = {};
70-
data.query = "{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses betAmount profit currency}}}";
70+
data.query = "query DiceBotGetBalance{user {activeServerSeed { seedHash seed nonce} activeClientSeed{seed} id balances{available{currency amount}} statistic {game bets wins losses betAmount profit currency}}}";
7171
let ret = await this._send('', 'POST', data, req.session.accessToken);
7272
ret=ret.user;
7373
let info = {};
@@ -121,14 +121,16 @@ module.exports = class StakeDice extends BaseDice {
121121
target = Math.floor((req.body.Chance*10000))-1;
122122
}
123123
target = parseFloat(target/10000).toFixed(2);
124-
let data = {};
125-
data.query = " mutation{diceRoll(amount:"+amount+",target:"+target+",condition:"+ condition +",currency:"+currency+ ") { id nonce currency amount payout state { ... on CasinoGameDice { result target condition } } createdAt serverSeed{seedHash seed nonce} clientSeed{seed} user{balances{available{amount currency}} statistic{game bets wins losses betAmount profit currency}}}}";
126-
let ret = await this._send('', 'POST', data, req.session.accessToken);
124+
//let data = {};
125+
//data.query = " mutation{diceRoll(amount:"+amount+",target:"+target+",condition:"+ condition +",currency:"+currency+ ") { id nonce currency amount payout state { ... on CasinoGameDice { result target condition } } createdAt serverSeed{seedHash seed nonce} clientSeed{seed} user{balances{available{amount currency}} statistic{game bets wins losses betAmount profit currency}}}}";
126+
127+
let betdata = "{\"operationName\":\"DiceRoll\",\"variables\":{\"target\":"+target+",\"condition\":\""+condition+"\",\"identifier\":\"d316d71e2f075a05339d\",\"amount\":"+amount+",\"currency\":\""+currency+"\"},\"query\":\"mutation DiceRoll($amount: Float!, $target: Float!, $condition: CasinoGameDiceConditionEnum!, $currency: CurrencyEnum!, $identifier: String!) {\\n diceRoll(amount: $amount, target: $target, condition: $condition, currency: $currency, identifier: $identifier) {\\n ...CasinoBetFragment\\n state {\\n ...DiceStateFragment\\n __typename\\n }\\n __typename\\n }\\n}\\n\\nfragment CasinoBetFragment on CasinoBet {\\n id\\n active\\n payoutMultiplier\\n amountMultiplier\\n amount\\n payout\\n updatedAt\\n currency\\n game\\n user {\\n id\\n name\\n __typename\\n }\\n __typename\\n}\\n\\nfragment DiceStateFragment on CasinoGameDice {\\n result\\n target\\n condition\\n __typename\\n}\\n\"}"
128+
let ret = await this._sendbet('', 'POST', betdata, req.session.accessToken);
127129
let info = req.session.info;
128130
let betInfo = ret.diceRoll;
129-
data = {};
130-
data.query = "{bet(betId:\""+betInfo.id+"\"){iid}}";
131-
let dataIID = await this._send('', 'POST', data, req.session.accessToken);
131+
betdata = "{\"operationName\":\"Bet\",\"variables\":{\"betId\":\""+betInfo.id+"\",\"modal\":\"bet\"},\"query\":\"query Bet($iid: String, $betId: String) {\\n bet(iid: $iid, betId: $betId) {\\n ...BetFragment\\n __typename\\n }\\n}\\n\\nfragment BetFragment on Bet {\\n id\\n iid\\n type\\n game {\\n name\\n icon\\n __typename\\n }\\n bet {\\n ... on CasinoBet {\\n ...CasinoBetFragment\\n __typename\\n }\\n ... on MultiplayerCrashBet {\\n ...MultiplayerCrashBet\\n __typename\\n }\\n ... on MultiplayerSlideBet {\\n ...MultiplayerSlideBet\\n __typename\\n }\\n ... on SoftswissBet {\\n ...SoftswissBet\\n __typename\\n }\\n ... on EvolutionBet {\\n ...EvolutionBet\\n __typename\\n }\\n __typename\\n }\\n __typename\\n}\\n\\nfragment CasinoBetFragment on CasinoBet {\\n id\\n active\\n payoutMultiplier\\n amountMultiplier\\n amount\\n payout\\n updatedAt\\n currency\\n game\\n user {\\n id\\n name\\n __typename\\n }\\n __typename\\n}\\n\\nfragment MultiplayerCrashBet on MultiplayerCrashBet {\\n id\\n user {\\n id\\n name\\n __typename\\n }\\n payoutMultiplier\\n gameId\\n amount\\n payout\\n currency\\n result\\n updatedAt\\n cashoutAt\\n btcAmount: amount(currency: btc)\\n __typename\\n}\\n\\nfragment MultiplayerSlideBet on MultiplayerSlideBet {\\n id\\n user {\\n id\\n name\\n __typename\\n }\\n payoutMultiplier\\n gameId\\n amount\\n payout\\n currency\\n slideResult: result\\n updatedAt\\n cashoutAt\\n btcAmount: amount(currency: btc)\\n active\\n createdAt\\n __typename\\n}\\n\\nfragment SoftswissBet on SoftswissBet {\\n id\\n amount\\n currency\\n updatedAt\\n payout\\n payoutMultiplier\\n user {\\n id\\n name\\n __typename\\n }\\n softswissGame: game {\\n id\\n name\\n edge\\n extId\\n provider {\\n id\\n name\\n __typename\\n }\\n __typename\\n }\\n __typename\\n}\\n\\nfragment EvolutionBet on EvolutionBet {\\n id\\n amount\\n currency\\n createdAt\\n payout\\n payoutMultiplier\\n user {\\n id\\n name\\n __typename\\n }\\n softswissGame: game {\\n id\\n name\\n edge\\n __typename\\n }\\n __typename\\n}\\n\"}";
132+
let dataIID = await this._sendbet('', 'POST', betdata, req.session.accessToken);
133+
console.log(dataIID);
132134
betInfo.iid = dataIID.bet.iid.split(":")[1];
133135
betInfo.condition = req.body.High == "true"?'>':'<';
134136
betInfo.target = target;
@@ -162,8 +164,11 @@ module.exports = class StakeDice extends BaseDice {
162164

163165
async resetseed(req) {
164166
let clientSeed = Math.random().toString(36).substring(2);
165-
data = {};
166-
data.query = "mutation{rotateServerSeed{ seed seedHash nonce } changeClientSeed(seed:\"" + clientSeed + "\"){seed}}"
167+
let data = {};
168+
let variables = {};
169+
data.query = "mutation DiceBotRotateSeed ($seed: String!){rotateServerSeed{ seed seedHash nonce } changeClientSeed(seed: $seed){seed}}";
170+
variables.seed = clientSeed;
171+
data.variables = variables;
167172
let ret = await this._send('', 'POST', data, req.session.accessToken);
168173
console.log(clientSeed, ret);
169174
let info = {};
@@ -202,5 +207,35 @@ module.exports = class StakeDice extends BaseDice {
202207
let ret = data.data;
203208
return ret;
204209
}
210+
211+
async _sendbet(route, method, body, accessToken){
212+
let url = `${this.url}`;
213+
let options = {
214+
method: method,
215+
headers: {
216+
'x-access-token': accessToken,
217+
'Content-Type': 'application/json',
218+
},
219+
body: body
220+
};
221+
if(this.proxy.ip) {
222+
let socks = 'socks://'+this.proxy.ip+':'+this.proxy.port;
223+
if(this.proxy.user){
224+
socks = 'socks://'+this.proxy.user+':'+this.proxy.password+'@'+this.proxy.ip+':'+this.proxy.port;
225+
}
226+
let agent = new SocksProxyAgent(socks);
227+
options.agent = agent;
228+
}
229+
options.body = body;
230+
let res = await fetch(url, options);
231+
let data = await res.json();
232+
if(data.errors) {
233+
let errs = new Error(data.errors[0].message);
234+
errs.value = data.errors[0].message;
235+
throw new APIError(data.errors[0].message ,errs);
236+
}
237+
let ret = data.data;
238+
return ret;
239+
}
205240
}
206241
exports.StakeDice

src/console.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ if(readlineSync.keyInYN('Whether to read the last configuration?')) {
5353
let rawdata = fs.readFileSync('./recent_account_info.json');
5454
req.body = JSON.parse(rawdata);
5555
} else {
56-
sites = ['Simulator', '999Dice', 'Bitsler', 'Crypto-Games', 'DuckDice', 'PrimeDice', 'Stake', 'YoloDice','WolfBet', 'FreeBitco.in', 'WinDice', 'EpicDice', 'KryptoGames', '999Doge', 'SatoshiDice','ParaDice'];
56+
sites = ['Simulator', '999Dice', 'Bitsler', 'Crypto-Games', 'DuckDice', 'PrimeDice', 'Stake', 'YoloDice','WolfBet', 'FreeBitco', 'WinDice', 'EpicDice', 'KryptoGames', '999Doge', 'SatoshiDice','ParaDice'];
5757
index = readlineSync.keyInSelect(sites, 'Which site?');
5858
if(index < 0 ){
5959
return false;
@@ -275,10 +275,9 @@ screen.render();
275275
console.log = function (message) {
276276
try {
277277
if (typeof message == 'object') {
278-
logs.log(JSON && JSON.stringify ? (JSON.stringify(message)).replace(/\"/g,"") : message+"\r\n");
279-
} else {
280-
logs.log(message+"\r\n");
278+
message = JSON.stringify(message) ==='{}' ? message.toString() : (JSON.stringify(message)).replace(/\"/g,"");
281279
}
280+
logs.log(message+"\r\n");
282281
} catch(err){
283282
console.error(err);
284283
process.exit();
@@ -287,10 +286,10 @@ console.log = function (message) {
287286
console.error = function (message) {
288287
try {
289288
if (typeof message == 'object') {
290-
logs.log(JSON && JSON.stringify ? (JSON.stringify(message)).replace(/\"/g,"") : message+"\r\n");
291-
} else {
292-
logs.log(message+"\r\n");
289+
message = JSON.stringify(message) ==='{}' ? message.toString() : (JSON.stringify(message)).replace(/\"/g,"");
293290
}
291+
logs.log(message+"\r\n");
292+
out('error_log',message+'\r\n');
294293
} catch(err){
295294
console.error(err);
296295
process.exit();
@@ -344,6 +343,13 @@ async function betScript(req) {
344343
}
345344
}
346345

346+
async function out(logname, logdata){
347+
fs.writeFile('./log/'+logname, logdata, {flag: 'a'}, function (err) {
348+
if(err) {
349+
console.error(err);
350+
}
351+
});
352+
}
347353
async function saveLog(logname, logdata){
348354
fs.writeFile('./log/'+logname, logdata, {flag: 'a'}, function (err) {
349355
if(err) {

0 commit comments

Comments
 (0)