|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var BaseDice = require('./base'); |
| 4 | +var fetch = require('isomorphic-fetch'); |
| 5 | +var FormData = require('form-data'); |
| 6 | +var APIError = require('../errors/APIError'); |
| 7 | + |
| 8 | +module.exports = class NineDoge extends BaseDice { |
| 9 | + constructor(){ |
| 10 | + super(); |
| 11 | + this.url = 'https://www.999doge.com'; |
| 12 | + this.benefit = '?224280708' |
| 13 | + } |
| 14 | + |
| 15 | + async login(userName, password, twoFactor ,apiKey, req) { |
| 16 | + apiKey = '794ec0fec4f543f1a14b0b50dbbcb345'; |
| 17 | + let formData = new FormData(); |
| 18 | + formData.append('a', 'Login'); |
| 19 | + formData.append('Username', userName); |
| 20 | + formData.append('Password', password); |
| 21 | + formData.append('Key', apiKey); |
| 22 | + if(twoFactor) { |
| 23 | + formData.append('Totp', twoFactor); |
| 24 | + } |
| 25 | + let ret = await this._send('web.aspx', 'POST', formData,''); |
| 26 | + //console.log(ret); |
| 27 | + if(ret.error) { |
| 28 | + return ret.error; |
| 29 | + } |
| 30 | + //if(!ret.ClientSeed) { |
| 31 | + // return 'Login Invalid, Please enter the correct information!'; |
| 32 | + //} |
| 33 | + |
| 34 | + req.session.clientSeed = ret.ClientSeed; |
| 35 | + req.session.accessToken = ret.SessionCookie; |
| 36 | + req.session.username = userName; |
| 37 | + req.session.apiKey = req.body.apikey; |
| 38 | + return true; |
| 39 | + } |
| 40 | + |
| 41 | + async refresh(req) { |
| 42 | + let ret = req.session.info; |
| 43 | + return ret; |
| 44 | + } |
| 45 | + |
| 46 | + async getUserInfo(req) { |
| 47 | + let formData = new FormData(); |
| 48 | + formData.append('a', 'GetBalances'); |
| 49 | + formData.append('s', req.session.accessToken); |
| 50 | + let ret = await this._send('web.aspx', 'POST', formData,''); |
| 51 | + let bs =JSON.parse(JSON.stringify(ret.Balances)); |
| 52 | + ret.CurrentBalances = bs; |
| 53 | + for (let i=0; i<ret.CurrentBalances.length; i++) { |
| 54 | + ret.CurrentBalances[i].TotalPayIn = 0; |
| 55 | + ret.CurrentBalances[i].TotalBets = 0; |
| 56 | + ret.CurrentBalances[i].TotalPayOut = 0; |
| 57 | + ret.CurrentBalances[i].TotalWins = 0; |
| 58 | + } |
| 59 | + //console.log(ret); |
| 60 | + req.session.info = ret; |
| 61 | + return ret; |
| 62 | + } |
| 63 | + |
| 64 | + async bet(req) { |
| 65 | + let formData = new FormData(); |
| 66 | + let currency = req.body.Currency; |
| 67 | + formData.append('a', 'PlaceBet'); |
| 68 | + formData.append('s', req.session.accessToken); |
| 69 | + formData.append('PayIn', req.body.PayIn); |
| 70 | + formData.append('ClientSeed', req.session.clientSeed); |
| 71 | + formData.append('Currency', currency); |
| 72 | + formData.append('ProtocolVersion', 2); |
| 73 | + let betRoll = 0; |
| 74 | + if(req.body.High == "true"){ |
| 75 | + betRoll = 999999-Math.floor((req.body.Chance*10000))+1; |
| 76 | + formData.append('Low', betRoll); |
| 77 | + formData.append('High', 999999); |
| 78 | + } else { |
| 79 | + betRoll = Math.floor((req.body.Chance*10000))-1; |
| 80 | + formData.append('Low', 0); |
| 81 | + formData.append('High', betRoll); |
| 82 | + } |
| 83 | + let ret = await this._send('web.aspx', 'POST', formData,''); |
| 84 | + console.log(ret); |
| 85 | + if(ret.NoPossibleProfit == 1) { |
| 86 | + return ret; |
| 87 | + } |
| 88 | + ret.High = req.body.High == "true"?'>':'<'; |
| 89 | + ret.PayIn = req.body.PayIn; |
| 90 | + let info = req.session.info; |
| 91 | + let currencyValue = req.body.CurrencyValue; |
| 92 | + info.Balances[currencyValue].TotalBets++; |
| 93 | + info.CurrentBalances[currencyValue].TotalBets++; |
| 94 | + info.Balances[currencyValue].Balance = info.Balances[currencyValue].Balance + ret.PayOut - ret.PayIn; |
| 95 | + info.CurrentBalances[currencyValue].Balance = info.CurrentBalances[currencyValue].Balance + ret.PayOut - ret.PayIn; |
| 96 | + ret.Win = false; |
| 97 | + if((ret.PayOut-ret.PayIn)>0) { |
| 98 | + ret.Win = true; |
| 99 | + info.Balances[currencyValue].TotalWins++; |
| 100 | + info.CurrentBalances[currencyValue].TotalWins++; |
| 101 | + } |
| 102 | + info.Balances[currencyValue].TotalPayIn = info.Balances[currencyValue].TotalPayIn - ret.PayIn; |
| 103 | + info.CurrentBalances[currencyValue].TotalPayIn = info.CurrentBalances[currencyValue].TotalPayIn - ret.PayIn; |
| 104 | + info.Balances[currencyValue].TotalPayOut = info.Balances[currencyValue].TotalPayOut + ret.PayOut; |
| 105 | + info.CurrentBalances[currencyValue].TotalPayOut = info.CurrentBalances[currencyValue].TotalPayOut + ret.PayOut; |
| 106 | + req.session.info = info; |
| 107 | + ret.info = info; |
| 108 | + ret.BetRoll = betRoll; |
| 109 | + return ret; |
| 110 | + } |
| 111 | + |
| 112 | + async clear(req) { |
| 113 | + console.log('loading....'); |
| 114 | + let info = req.session.info; |
| 115 | + let bs =JSON.parse(JSON.stringify(info.Balances)); |
| 116 | + info.CurrentBalances = bs; |
| 117 | + for (let i=0; i<info.CurrentBalances.length; i++) { |
| 118 | + info.CurrentBalances[i].TotalPayIn = 0; |
| 119 | + info.CurrentBalances[i].TotalBets = 0; |
| 120 | + info.CurrentBalances[i].TotalPayOut = 0; |
| 121 | + info.CurrentBalances[i].TotalWins = 0; |
| 122 | + } |
| 123 | + req.session.info = info; |
| 124 | + return info; |
| 125 | + } |
| 126 | + |
| 127 | + async _send(route, method, body, accessToken){ |
| 128 | + let url = `${this.url}/api/${route}${this.benefit}`; |
| 129 | + let res = await fetch(url, { |
| 130 | + method, |
| 131 | + headers: { |
| 132 | + 'User-Agent': 'DiceBot', |
| 133 | + }, |
| 134 | + body: body, |
| 135 | + }); |
| 136 | + if(res.status == 200){ |
| 137 | + let data = await res.json(); |
| 138 | + return data; |
| 139 | + } else { |
| 140 | + console.log('call api error '); |
| 141 | + throw new APIError("call api error","api not found"); |
| 142 | + } |
| 143 | + } |
| 144 | +} |
| 145 | +exports.NineDoge |
0 commit comments