Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import curses
- import curses.textpad
- import requests
- import json
- import io
- import os
- import sys, getopt
- from pathlib import Path
- import re
- import random
- import time
- import lupa
- from parse import parse
- import websocket
- from requests.structures import CaseInsensitiveDict
- server = 'just-dice.com'
- username = "XXXX"
- password = "XXXX"
- _path = os.path.abspath(os.path.dirname(__file__))
- account_file = Path(_path+'/account.jd')
- ##
- ## stores a configuration.
- ########################################################
- class Config:
- def __init__(self):
- self.WS = None
- self.manualSession = False
- self.manualActive = False
- self.recovery = False
- self.exitOnMax = False
- self.noprofitensure = False
- self.stopbetting = False
- self.profitensure = False
- self.hitsFlag = False
- self.OnStopCmd = True
- self.alarmOn = True
- self.stopifwin = False
- self.balance = 0.0
- self.maxbalance = 0.0
- self.minbalance = 0.0
- self.bstart = -1.0
- self.before = 0
- self.SessionCookie = "c0ffee00000000000000000000c0ffee"
- self.sid = ""
- self.csrf = ""
- self.maxdiff = 0
- self.wagered = 0
- self.wincount = 0
- self.losecount = 0
- self.betcount = 0
- self.lastmax = 0
- self.lastmaxmax = 0
- self.currentstreak = 0
- self.currentprofit = 0
- self.minstreak = 0
- self.maxstreak = 0
- self.chance = 49.5
- self.chance2 = 57.0
- self.MaxPayIn = 0
- self.nextbet = 0.0000001
- self.basebet = self.nextbet
- self.goal = 0
- self.goalDelta = 0
- self.myRange = 0
- self.secret = 0
- self.win = None
- self.streakwin = [0 for i in range(204800)]
- self.streaklose = [0 for i in range(204800)]
- self.gain = 0
- self.keeplogfile = False
- self.kbd = 0
- self.infoval = ""
- self.testMode = False
- self.nobetdisplay = False
- self.bnowfile = _path+"/bnow.CLAM"
- self.exitReason = ""
- self.botname = ""
- self.begin = time.time()
- self.end = time.time()
- self.now = time.time()
- self.seconds = 0
- self.oldseconds = 0
- self.stopamount = 0.2
- self.percentualStop = 0
- self.turnlimit = 0
- self.profitensurance = 0
- self.lua = 0
- self.side = 1
- ## End Config
- _C = Config()
- ##
- ## for work with curses regions
- ########################################################
- class Regions:
- def init(self, w):
- self.w = w
- (height, width) = w.getmaxyx ();
- self.height, self.width = (height, width)
- self.header1 = curses.newwin (7, width//2-10, 0, 0)
- self.header2 = curses.newwin (7, width-self.header1.getmaxyx()[1], 0, self.header1.getmaxyx()[1]+1)
- self.stat = curses.newwin (2, width, 7, 0)
- heightavail=height-9
- self.betregion = curses.newwin (heightavail//2+4, width, 9+1, 0)
- self.manualline = curses.newwin (1, width, 9+self.betregion.getmaxyx()[0]+1, 0)
- self.msgregion = curses.newwin (heightavail//2-4, width, 9+self.betregion.getmaxyx()[0]+1+1, 0)
- self.betregion.scrollok(True)
- self.msgregion.scrollok(True)
- self.w.addstr(9, 0, " balance chance high betsize profit lucky ")
- w.refresh()
- # refreshes curses regions from list
- def refresh (self, regions):
- for r in regions:
- getattr(self, r).refresh()
- # prints manualline region
- def print_m_line(self, msg=""):
- if len(msg) == 0: # manual betting mode
- if not _C.manualActive:
- self.clear_m_line()
- return
- if _C.balance > _C.before:
- s = " +{:.8f} D {:.8f}".format(_C.balance-_C.before, _C.balance - _C.goal)
- else:
- s = " {:.8f} D {:.8f}".format(_C.balance-_C.before, _C.balance - _C.goal)
- self.manualline.addstr(0, 0, "{:<14}{:>15.4f}% {:>15.4f}%{:>15.8f}{}".format("", _C.chance2, _C.chance, _C.nextbet, s))
- self.manualline.refresh()
- else: # msg mode
- self.clear_m_line()
- self.manualline.addstr(msg)
- self.manualline.refresh()
- def clear_m_line(self):
- self.manualline.move(0, 0)
- self.manualline.clrtoeol()
- self.manualline.refresh()
- # prints statistics in header1, header2 and stat regions
- def update_status(self):
- self.header1.attron(curses.color_pair(2))
- self.header1.addstr(0, 0, " minimum:{:15.8f}".format(_C.minbalance))
- self.header1.addstr(1, 0, " current:{:15.8f} ({:.8f}) ".format(_C.balance, _C.maxbalance-_C.stopamount))
- self.header1.addstr(2, 0, " diff:{:15.8f} (max. {:.8f}) ".format(_C.maxbalance - _C.balance, _C.maxdiff))
- self.header1.addstr(3, 0, " maximum:{:15.8f}".format(_C.maxbalance))
- if _C.goal > 0 :
- self.header1.addstr(3, 25, "(goal: {:.8f})".format(_C.goal))
- self.header1.addstr(4, 0, " profit:{:15.8f} ({:.3f}%) ".format(_C.balance - _C.bstart,
- 0 if _C.bstart == 0 else float(_C.balance*100/_C.bstart-100)))
- self.header1.addstr(5, 0, "MaxPayIn:{:15.8f}".format(_C.MaxPayIn))
- self.header1.addstr(6, 0, " wagered:{:15.8f}".format(_C.wagered))
- self.header1.attroff(curses.color_pair(2))
- if _C.profitensure:
- self.header1.addstr(1,43, "{:.8f}".format(float((_C.bstart + _C.maxbalance)/200000000)), curses.color_pair(2))
- self.header1.refresh()
- _C.end = time.time()
- _C.seconds = int(_C.end - _C.begin)
- if _C.seconds > 0:
- betsPerSecond = float(_C.betcount/_C.seconds)
- profitPerSecond = (_C.balance-_C.bstart)/_C.seconds
- else:
- betsPerSecond = 0
- profitPerSecond = 0
- minutes = int(_C.seconds/60)
- hours = int(minutes/60)
- minutes = minutes%60
- _C.seconds = _C.seconds%60
- self.header2.addstr(1, 0, "won {} of {} bets ({:.4f}% {:.2f} bets/s ) ".format(
- _C.wincount, _C.betcount, float(_C.wincount / _C.betcount * 100 if _C.betcount else 0), betsPerSecond))
- if _C.betcount - _C.lastmax > _C.lastmaxmax :
- _C.lastmaxmax = _C.betcount - _C.lastmax;
- self.header2.addstr(2, 0, "last max: {:>5} ({}) {:.2f}% ".format(
- _C.betcount - _C.lastmax, _C.lastmaxmax, float(_C.balance * 100 / _C.maxbalance if _C.maxbalance else 0)))
- self.header2.addstr(3, 0, "streak: {:>5} (min {} max {}) ".format(
- _C.currentstreak, _C.minstreak, _C.maxstreak))
- if _C.seconds != _C.oldseconds:
- self.header2.addstr(4, 0, "{}:{:02}:{:02} {:0.2f}/min {:0.2f}/hour ".format(
- hours,minutes,_C.seconds, profitPerSecond*60, profitPerSecond*3600))
- _C.oldseconds=_C.seconds
- self.header2.addstr(5, 0, f"info: {_C.infoval}")
- self.header2.refresh()
- for n in range(6,-1,-1):
- if -1*_C.minstreak - n > 0:
- self.stat.addstr(0, 1+n*6, "{:4}".format(-1*_C.minstreak - n), curses.color_pair(3))
- self.stat.addstr(1, 1+n*6, "{:4}".format(_C.streaklose[-1*_C.minstreak - n]))
- for n in range(6,-1,-1):
- if _C.maxstreak-n > 0:
- self.stat.addstr(0, self.width-16-n*6, "{:4}".format(_C.maxstreak-n), curses.color_pair(1))
- self.stat.addstr(1, self.width-16-n*6, "{:4}".format(_C.streakwin[_C.maxstreak-n]))
- self.stat.refresh()
- ## End Regions
- _R = Regions()
- ##
- ## low/high hits statistic
- ########################################################
- class HitsStat():
- min_hits = (250,125,100,65,55,40,33,27,24,20,15,13,10,9,8,7,7,6,5)
- def __init__(self):
- self.low = [{"count" : 0, "use" : False} for i in range(20)]
- self.high = [{"count" : 0, "use" : False} for i in range(20)]
- self.chances = []
- self.lowFlag = False
- self.highFlag = False
- self.chancesCurrent = 0
- def check(self, R):
- posLow = R // 500
- posHigh = 19 - posLow
- self.lowFlag = False
- self.highFlag = False
- for i in range(19):
- if posLow > i:
- self.low[i]["count"] += 1
- if self.low[i]["count"] >= self.min_hits[i]:
- self.low[i]["use"] = True
- self.lowFlag = True
- elif posLow <= i:
- self.low[i]["count"] = 0
- self.low[i]["use"] = False
- if posHigh > i:
- self.high[i]["count"] += 1
- if self.high[i]["count"] >= self.min_hits[i]:
- self.high[i]["use"] = True
- self.highFlag = True
- elif posHigh <= i:
- self.high[i]["count"] = 0
- self.high[i]["use"] = False
- return (self.lowFlag, self.highFlag)
- def once_in(self, count, chance):
- return 1/(1-chance/100)**count
- def print_msg(self):
- self.chances.clear()
- s = ""
- if self.lowFlag:
- s += "L: "
- for i in range(19):
- if self.low[i]["use"]:
- s += "c{} ({} once in {:.0f})| ".format((i+1)*5, self.low[i]["count"], self.once_in(self.low[i]["count"], (i+1)*5))
- self.chances.append((i+1)*5)
- #msg(s)
- if self.highFlag:
- s += "H: "
- for i in range(19):
- if self.high[i]["use"]:
- s += "c{} ({} once in {:.0f})| ".format((i+1)*5, self.high[i]["count"], self.once_in(self.high[i]["count"], (i+1)*5))
- self.chances.append((i+1)*5)
- #msg(s)
- self.chances.append(57)
- # switching chance2
- def toggle_chances(self):
- if len(self.chances) > 0:
- if self.chancesCurrent >= len(self.chances):
- self.chancesCurrent = 0
- _C.chance2 = self.chances[self.chancesCurrent]
- self.chancesCurrent += 1
- ## End HitsStat
- _H = HitsStat()
- ########################################################
- # converts float to string (to avoid scientific notation)
- def float_to_str(f):
- float_string = repr(f)
- if 'e' in float_string: # detect scientific notation
- digits, exp = float_string.split('e')
- digits = digits.replace('.', '').replace('-', '')
- exp = int(exp)
- # minus 1 for decimal point in the sci notation
- zero_padding = '0' * (abs(int(exp)) - 1)
- sign = '-' if f < 0 else ''
- if exp > 0:
- float_string = '{}{}{}.0'.format(sign, digits, zero_padding)
- else:
- float_string = '{}0.{}{}'.format(sign, zero_padding, digits)
- return float_string
- ########################################################
- def login():
- con_cookies = {}
- headers = CaseInsensitiveDict()
- headers["Host"] = server
- headers["User-Agent"] = "'User-Agent': 'Firefox'"
- headers["Connection"] = "Keep-Alive"
- try:
- #read connect.sid and hash cookies from file (if they were saved already)
- if account_file.is_file():
- with open(account_file) as data_file:
- con_cookies = json.load(data_file)
- else:
- # print("# get connect.sid cookie")
- headers["Cookie"] = "hash=b30adf82007d8544fa8ac14227ace6dfd1f7c1ee0b39c951ea101798cda5bbdb"
- response = requests.get(f"https://{server}/", headers=headers)
- if 'Set-Cookie' in response.headers.keys():
- con_cookies["sid"] = response.headers['Set-Cookie'].split(";")[0].split("=")[1]
- # print(con_cookies)
- # print("# get hash cookie")
- headers["Cookie"] = f"hash=b30adf82007d8544fa8ac14227ace6dfd1f7c1ee0b39c951ea101798cda5bbdb; connect.sid={con_cookies['sid']}"
- d = {'username' : username, 'password' : password, 'code' : ""}
- response = requests.post(f"https://{server}", data=d, headers=headers)
- if 'Set-Cookie' in response.headers.keys():
- con_cookies["hash"] = response.headers['Set-Cookie'].split(";")[0].split("=")[1]
- with io.open(account_file, 'w', encoding='utf8') as outfile:
- str_ = json.dumps(con_cookies,
- indent=4, sort_keys=True,
- separators=(',', ': '), ensure_ascii=False)
- outfile.write(str(str_))
- # print(con_cookies)
- # print("# get io cookie")
- headers["Referer"] = f"https://{server}/"
- headers["Cookie"] = f"hash={con_cookies['hash']}; connect.sid={con_cookies['sid']}"
- response = requests.get(f"https://{server}/socket.io/?EIO=3&transport=polling&t={int(time.time()*1000)}-0",
- headers=headers)
- if 'Set-Cookie' in response.headers.keys():
- con_cookies["io"] = response.headers['Set-Cookie'].split(";")[0].split("=")[1]
- # print(con_cookies)
- # print("# get csrf and other stuff")
- headers["Cookie"] = f"io=3{con_cookies['io']}; hash={con_cookies['hash']}; connect.sid={con_cookies['sid']}"
- response = requests.get(
- f"https://{server}/socket.io/?EIO=3&transport=polling&t={int(time.time()*1000)}-1&sid={con_cookies['io']}",
- headers=headers)
- rest_txt = response.text.split("ÿ42")[1]
- rest_txt = rest_txt[:rest_txt.rfind("]")+1]
- stats = json.loads(rest_txt)[1]
- del stats["chat"]
- _C.csrf = stats["csrf"]
- _C.sid = con_cookies['io']
- _C.SessionCookie = headers["Cookie"]
- _C.balance = float(stats["balance"])
- _C.uid = stats['uid']
- return True
- except Exception as err:
- _C.exitReason = f"login error ({err})"
- return False
- ########################################################
- def do_bet(bet):
- try:
- # msg(bet)
- _C.WS.send(bet)
- # 42["jderror","bet should be a string"]
- # 42["jderror","You already have a roll pending. Are you playing from multiple locations?"]
- result = _C.WS.recv()
- waiting = True
- count = 0
- while waiting:
- count += 1
- if "result" in result:
- r = json.loads(result[2:])[1]
- if r['uid'] == _C.uid:
- return result
- if "jderror" in result or count > 20:
- msg(f"Count: {count}")
- msg(result)
- waiting = False
- break
- result = _C.WS.recv()
- _C.exitReason = f'Bet error ({result})'
- return None
- except Exception as err:
- _C.exitReason = f'Bet request - error occurred: {err}'
- return None
- ########################################################
- # shows textbox for input float values (betsize, chances)
- # TODO: fix font/color
- def text_input(old_value, h, w, y, x):
- window = curses.newwin(h, w, y, x)
- window.clear()
- curses.curs_set(1)
- window.bkgd(' ', curses.color_pair(2) | curses.A_BOLD | curses.A_REVERSE)
- # window.addstr(0, 0, "{:15.8f}".format(old_value))
- window.addstr(0, 0, float_to_str(old_value))
- window.refresh()
- textbox = curses.textpad.Textbox(window)
- # textbox.stripspaces = 0
- class EscapeInterrupt(Exception):
- "Signal that the ESC key has been pressed"
- # filter keys (only [0-9.]) and set more convinient controls
- def validate(ch):
- if ch == 27:
- raise EscapeInterrupt()
- # Fix backspace for iterm
- if ch not in (10, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 262, 260, 330, 360, 261, 127):
- return 12
- if ch == curses.KEY_HOME: #
- ch = 1
- if ch == curses.KEY_LEFT:
- ch = 2
- if ch == 330: # DEL
- ch = 4
- if ch == curses.KEY_END:
- ch = 5
- if ch == curses.KEY_RIGHT:
- ch = 6
- if ch == 127: # BACKSPACE
- ch = 263
- return ch
- try:
- out = textbox.edit(validate=validate)
- except EscapeInterrupt:
- out = str(old_value)
- try:
- float(out)
- except ValueError:
- out = str(old_value)
- curses.curs_set(0)
- window.erase()
- del window
- return out
- ########################################################
- def get_random_int(a,b):
- return random.SystemRandom().randint(a, b)
- ########################################################
- # init/reset lua state before running script
- def init_lua():
- source = open(_C.botname).read()
- _C.lua.globals()["balance"] = _C.balance
- _C.lua.globals()["print"] = msg
- _C.lua.globals()["stop"] = stoplua
- _C.lua.globals()["infoval"] = ""
- _C.lua.globals()["side"] = _C.side
- _C.lua.execute(source)
- _C.chance = float(int(_C.lua.globals()["chance"]*10000)/10000)
- _C.nextbet = _C.lua.globals()["nextbet"]
- _C.basebet = _C.nextbet;
- _C.side = _C.lua.globals()["side"]
- ########################################################
- class BetInfo:
- def __init__(self, betsize, chance, side=0):
- if side == 0:
- self.Which = "lo" if get_random_int(0, 999999) < 500000 else "hi"
- elif side == -1:
- self.Which = "lo"
- else:
- self.Which = "hi"
- self.BetSize = betsize
- self.Chance = chance
- def set_result(self, res):
- # [
- # "result",
- # {
- # "bankroll": "3730713.91797571",
- # "bet": "0",
- # "betid": 5406701465,
- # "bets": "283",
- # "chance": "33.33",
- # "date": 1651234642,
- # "high": false,
- # "luck": "94.62%",
- # "lucky": 733854,
- # "max_profit": "341299.73",
- # "name": "yorK (3615997)",
- # "nonce": 65,
- # "payout": 2.97029703,
- # "ret": "0",
- # "this_profit": "-0",
- # "uid": "3615997",
- # "wagered": "0.00000000",
- # "win": false,
- # "stats":
- # {
- # "bets": 5406701465,
- # "losses": 3292547495,
- # "luck": 5406187554.532714,
- # "profit": -917006.16165835,
- # "wagered": 74982197.07890135,
- # "wins": 2114152617
- # },
- # "investment": 0,
- # "percent": 0,
- # "invest_pft": 0,
- # "balance": "0.00000000",
- # "profit": "0.00000000"
- # }
- # ]
- res = json.loads(res[2:])[1]
- # msg(res)
- self.bet = res['bet']
- self.betid = res['betid']
- self.chance = float(res['chance'])
- self.high = res['high']
- self.lucky = int(res['lucky'])
- self.payout = float(res['payout'])
- self.profit = float(res['this_profit'])
- self.win = res['win']
- self.balance = float(res['balance'])
- # self.bet = 0.0
- # self.betid = 0
- # self.chance = 50
- # self.high = True
- # self.lucky = 25.25
- # self.payout = 0.0
- # self.profit = 0.0
- # self.win = True
- # self.balance = 0.0
- def request(self, log=False) :
- # ws.send(f'42["bet","{csrf}",{{"chance":"{chance}","bet":"{betsize}","which":"{which}"}}]')
- bet = {"chance" : self.Chance, "bet" : self.BetSize, "which" : self.Which}
- return f'42["bet","{_C.csrf}",{{"chance":"{bet["chance"]}","bet":"{bet["bet"]:.8f}","which":"{bet["which"]}"}}]' if not log else bet
- ########################################################
- def betlog(line):
- logfile = open(_path+"/betlog", "a")
- logfile.write(f"{line}\n")
- logfile.close()
- if os.stat(_path+"/betlog").st_size > 10485760 and not _C.keeplogfile:
- os.rename(_path+"/betlog",_path+"/betlog.old")
- def interactive_mode():
- _C.nobetdisplay = False
- #ask back to user what to do next
- if _C.OnStopCmd and _C.alarmOn:
- print("\a")
- _C.alarmOn = False
- if not _C.hitsFlag:
- _C.goal = _C.maxbalance
- ekey = 1
- ekey = _R.w.getch()
- while ekey not in (ord("q"), ord("c"), ord("m"), ord('+'), ord('w')):
- _R.w.timeout(5)
- ekey = _R.w.getch()
- # if (hardstop==1) ekey='q';
- if _C.balance > _C.maxbalance:
- ekey = ord("q")
- if ekey == ord("q"):
- _C.kbd = ord("Q")
- return 0
- if ekey == ord("m"):
- _C.hitsFlag = False
- manual_mode()
- return 0
- if ekey == ord("w") and not _C.hitsFlag:
- _C.stopifwin = True
- if ekey == ord("c"):
- _C.stopifwin = False
- if ekey == ord("+"):
- _C.stopamount *= 110/100
- return 0
- ##
- ## Single bet
- ##
- ## :param betsize: The betsize
- ## :type betsize: float
- ## :param side: The range -1, 0, 1
- ## :type side: int
- ## :param chance: The chance or None
- ## :type chance: float
- ##
- def bet(betsize, side=0, chance=None):
- if chance is None:
- chance = _C.chance
- b = BetInfo(betsize, chance, side)
- # msg(b.request())
- if b.BetSize > _C.MaxPayIn:
- _C.MaxPayIn = b.BetSize
- _C.wagered += b.BetSize;
- if not _C.noprofitensure:
- if _C.balance > _C.bstart * 2 and _C.bstart > 0:
- _C.profitensure = True
- _R.header1.addstr(1, 29, "STOP2 @", curses.color_pair(3) | curses.A_BOLD)
- if _C.maxdiff > 2000*_C.basebet and _C.balance > _C.bstart + 2*_C.maxdiff and _C.bstart > 0:
- _C.profitensure = True
- _R.header1.addstr(1, 29, "STOP3 @", curses.color_pair(3) | curses.A_BOLD)
- if _C.maxbalance - 2000*_C.basebet > _C.bstart and _C.bstart > 0:
- _C.profitensure = True
- _R.header1.addstr(1, 29, "STOP4 @", curses.color_pair(3) | curses.A_BOLD)
- if _C.profitensurance > 0 and _C.maxbalance - _C.profitensurance > _C.bstart and _C.bstart > 0:
- _C.profitensure = True
- _R.header1.addstr(1, 29, "STOP5 @", curses.color_pair(3) | curses.A_BOLD)
- if _C.hitsFlag:
- _R.betregion.addstr("\nHits STOP. ", curses.color_pair(2) | curses.A_BOLD)
- _R.betregion.addstr("Press ")
- _R.betregion.addstr("c", curses.color_pair(2) | curses.A_BOLD)
- _R.betregion.addstr("ontinue / ")
- _R.betregion.addstr("q", curses.color_pair(2) | curses.A_BOLD)
- _R.betregion.addstr("uit / ")
- _R.betregion.addstr("m", curses.color_pair(2) | curses.A_BOLD)
- _R.betregion.addstr("anual (")
- _R.betregion.addstr("w", curses.color_pair(2) | curses.A_BOLD)
- _R.betregion.addstr(" - single bet, ")
- _R.betregion.addstr("+", curses.color_pair(2) | curses.A_BOLD)
- _R.betregion.addstr(" - stopamount*1.1)\n")
- _R.betregion.refresh()
- if not _C.manualActive:
- interactive_mode()
- if _C.kbd == ord("Q"):
- return 0
- else:
- if not _C.manualActive:
- if _C.balance >= _C.goal and _C.goal > 0:
- _C.exitReason = "GOAL REACHED {:.8f} >= {:.8f}".format(_C.balance, _C.goal)
- _C.kbd = ord("Q")
- return 0
- #if _C.profitensure and _C.balance-b.BetSize < (_C.bstart + _C.maxbalance)/2:
- #_C.exitReason = "PROFIT ENSURANCE {:.8f} < {:.8f}".format(
- #float(_C.balance - b.BetSize),
- #float((_C.balance + _C.maxbalance) / 2))
- #_C.kbd = ord("Q")
- #return 0
- #if ((_C.balance - b.BetSize < _C.maxbalance - _C.stopamount and _C.stopamount > 0 and _C.maxbalance > 0)
- #or _C.stopifwin):
- #_R.betregion.addstr("\nNext bet: {:.8f} - now at {:.2f}% of maxbalance. Press ".format(
- #betsize, float(_C.balance*100/_C.maxbalance)))
- #_R.betregion.addstr("c", curses.color_pair(2) | curses.A_BOLD)
- #_R.betregion.addstr("ontinue / ")
- #_R.betregion.addstr("q", curses.color_pair(2) | curses.A_BOLD)
- #_R.betregion.addstr("uit / ")
- #_R.betregion.addstr("m", curses.color_pair(2) | curses.A_BOLD)
- #_R.betregion.addstr("anual (")
- #_R.betregion.addstr("w", curses.color_pair(2) | curses.A_BOLD)
- #_R.betregion.addstr(" - single bet, ")
- #_R.betregion.addstr("+", curses.color_pair(2) | curses.A_BOLD)
- #_R.betregion.addstr(" - stopamount*1.1)\n")
- #_R.betregion.refresh()
- #_C.exitOnMax = True
- #if _C.balance < _C.bstart or _C.stopifwin:
- #interactive_mode()
- #if _C.balance > _C.bstart and _C.kbd != ord("X"):
- #_C.exitReason = "_C.balance > _C.bstart {:.8f} >= {:.8f}".format(_C.balance, _C.bstart)
- #_C.kbd = ord("Q")
- #return 0
- #else:
- #_C.kbd = ord("Q")
- #_C.exitReason = "ELSE: {:.8f} >= {:.8f}".format(_C.balance, _C.bstart)
- #return 0
- betlog(b.request(log=True))
- res = do_bet(b.request())
- if res is None:
- _C.stopbetting = True
- msg(f'chance: {b.Chance} amount : {b.BetSize:.8f}')
- msg(b.request())
- msg(_C.exitReason)
- # print("\a")
- return 0
- else:
- b.set_result(res)
- betlog(f'{res}'.replace("'",'"').replace(" ", ""))
- _C.secret = b.lucky/10000
- if _C.bstart == -1:
- _C.bstart = b.balance - b.bet
- h_l = " "
- if _C.secret < 49.5:
- h_l = "L"
- elif _C.secret >= 50.5:
- h_l = "H"
- l_30 = " ";
- h_30 = " ";
- if _C.secret < 30.0000001: l_30 = "|"
- if _C.secret > 70.0000: h_30 = "|"
- _C.hitsFlag = any(_H.check(_C.secret*100))
- if _C.hitsFlag:
- _H.print_msg()
- _C.balance = b.balance
- bprofit = b.profit
- _C.currentprofit = b.profit
- oncein = 1
- if b.win : #win
- color = 1
- color2 = 1
- _C.win = True
- if _C.currentstreak < 0:
- _C.streaklose[-1*_C.currentstreak] +=1
- _C.currentstreak = 1
- oncein = 100/_C.chance
- else:
- _C.currentstreak += 1
- oncein *= 100/chance
- if oncein + 0.9 >= 8000:
- _R.msgregion.addstr("{:12}: {:0.8f} {:0.8f} streak {:3} (once in {})\n".format(
- _C.betcount, _C.balance, _C.gain, _C.currentstreak, int(oncein+0.9)))
- _R.msgregion.refresh()
- _C.wincount += 1
- else:
- color2 = 3
- _C.win = False
- if _C.currentstreak > 0:
- _C.streakwin[_C.currentstreak] +=1
- _C.currentstreak = -1
- oncein = 100/(100-_C.chance)
- else:
- _C.currentstreak -= 1
- oncein *= 100/(100-_C.chance)
- if oncein + 0.9 >= 8000:
- _R.msgregion.addstr("{:12}: {:0.8f} {:0.8f} streak {:3} (once in {})\n".format(
- _C.betcount, _C.balance, _C.gain, _C.currentstreak, int(oncein+0.9)))
- _R.msgregion.refresh()
- _C.losecount += 1
- if _C.currentstreak < _C.minstreak:
- _C.minstreak = _C.currentstreak;
- if _C.currentstreak > _C.maxstreak:
- _C.maxstreak = _C.currentstreak;
- _C.betcount += 1
- if (_C.balance >= _C.maxbalance):
- _C.gain = _C.balance - _C.maxbalance
- _C.maxbalance = _C.balance
- _C.maxbets = _C.betcount - _C.lastmax
- _C.lastmax = _C.betcount
- _R.betregion.attron(curses.A_BOLD)
- if _C.exitOnMax or _C.turnlimit > 0 and _C.betcount > _C.turnlimit:
- _C.exitReason = f'EXIT on MAX requested'
- _C.kbd = ord('Q')
- if _C.balance < _C.minbalance:
- _C.minbalance = _C.balance
- if (_C.maxbalance - _C.balance) > _C.maxdiff:
- _C.maxdiff = _C.maxbalance - _C.balance
- if not _C.testMode:
- if not _C.nobetdisplay or _C.manualActive:
- color = int(_C.balance*100/_C.maxbalance) if _C.maxbalance > 0 else 0
- if color < 86:
- color = 86
- _R.betregion.attron(curses.color_pair(color2))
- if _C.balance < _C.maxbalance:
- _R.betregion.addstr("{} ".format(h_l))
- _R.betregion.addstr("{:4} {:4} ".format(abs(_C.currentstreak), _C.betcount-_C.lastmax))
- _R.betregion.addstr("{:18.8f} ".format(_C.balance), curses.color_pair(color))
- _R.betregion.addstr("{}{:5.4f}%{} {:^13} {:16.8f} {:16.8f} {:<9} \n".format(
- l_30, chance, h_30, str(b.high), betsize, bprofit, _C.secret))
- else:
- _R.betregion.addstr("{} {:4} {:4} {:18.8f} {}{:5.4f}%{} {:^13} {:16.8f} {:16.8f} {:<9} +{:.8f}\n".format(
- h_l,
- abs(_C.currentstreak),
- _C.betcount-_C.lastmax,
- _C.balance,
- l_30,
- chance,
- h_30, str(b.high),
- betsize,
- bprofit,
- _C.secret,
- _C.gain))
- _R.betregion.attroff(curses.color_pair(color))
- _R.betregion.attroff(curses.A_BOLD)
- _R.betregion.refresh()
- _R.update_status()
- logfile = open(_C.bnowfile, "a")
- logfile.write("{}:{:.8f}\n".format(0, _C.balance))
- logfile.close()
- ########################################################
- def manual_mode():
- cred = 0
- localcount = 0
- _C.manualActive= True
- _C.before= _C.balance
- if _C.manualSession:
- _C.nextbet = 0.00000001
- _C.basebet = _C.nextbet
- else:
- _C.recovery = True
- _R.update_status()
- _C.kbd = _R.w.getch()
- _C.now = time.time()
- while _C.kbd not in (ord("Q"), ord("D"), ord("X")):
- if _C.exitOnMax and _C.balance>=_C.maxbalance:
- msg(f"{_C.goal} - {_C.balance - _C.goal}")
- _C.kbd = ord("Q")
- continue
- if _C.balance - _C.goal > 0 and _C.goal > 0:
- msg(f"{_C.goal} - {_C.balance - _C.goal}")
- _C.kbd = ord("Q")
- continue
- _R.print_m_line()
- _R.w.timeout(5)
- _C.kbd = _R.w.getch()
- if _C.kbd == ord('z'):
- _C.nextbet *= 2
- if _C.nextbet > _C.balance:
- _C.nextbet = _C.balance-0.00000001
- elif _C.kbd == ord('x'):
- _C.nextbet /= 2
- if _C.nextbet < 0.00000001:
- _C.nextbet = 0.00000001
- elif _C.kbd == ord('a'):
- _C.nextbet *= 1.5
- if _C.nextbet > _C.balance:
- _C.nextbet = _C.balance-0.00000001
- elif _C.kbd == ord('s'):
- _C.nextbet /= 1.5
- if _C.nextbet < 0.00000001:
- _C.nextbet = 0.00000001
- elif _C.kbd == ord('u'):
- _H.toggle_chances()
- elif _C.kbd == ord('R'):
- if len(_C.botname):
- msg("Restart lua")
- init_lua()
- _C.stopbetting = False
- _C.kbd = ord('X')
- if _C.goalDelta > 0:
- _C.goal = _C.balance + _C.goalDelta
- else:
- msg("Run with botname argument")
- elif _C.kbd == ord('m'):
- if _C.chance > 5 and _C.chance < 95:
- _C.chance -= 5
- else:
- _C.chance -=1
- if _C.chance < 0.0001: _C.chance = 0.0001
- elif _C.kbd == ord('n'):
- if _C.chance >= 95 or _C.chance < 5:
- _C.chance += 1
- else:
- _C.chance += 5
- if _C.chance > 98.99: _C.chance = 98.99
- elif _C.kbd == ord('1'):
- _C.chance = 5
- elif _C.kbd == ord('5'):
- _C.chance = 50 if _C.chance == 49.5 else 49.5
- elif _C.kbd == ord('`'):
- _C.nextbet = 0.00000001
- elif _C.kbd == ord('7'):
- _C.chance = 70
- elif _C.kbd == ord('E'):
- nextbet = float("{:0.8f}".format(_C.nextbet))
- _C.nextbet = float(text_input(nextbet, *(1, 18, _R.manualline.getbegyx()[0], 49)))
- elif _C.kbd == curses.ascii.ENQ:
- _C.chance = float(text_input(_C.chance, *(1, 15, _R.manualline.getbegyx()[0], 34)))
- elif _C.kbd == ord('l'):
- bet(_C.nextbet)
- elif _C.kbd == ord('o'):
- bet(_C.nextbet, chance=_C.chance2)
- elif _C.kbd == ord('['):
- bet(_C.nextbet, -1, chance=_C.chance2)
- elif _C.kbd == ord(']'):
- bet(_C.nextbet, 1, chance=_C.chance2)
- elif _C.kbd == ord(','):
- bet(_C.nextbet, -1)
- elif _C.kbd == ord('.'):
- bet(_C.nextbet, 1)
- elif _C.kbd == ord('e'):
- _C.goal += 0.25
- # _C.exitOnMax = False
- _C.maxbalance += 0.25
- _R.update_status()
- elif _C.kbd == ord('r'):
- _C.goal -= 0.25
- # _C.exitOnMax = False
- _C.maxbalance -= 0.25
- _R.update_status()
- elif _C.kbd == ord('0'):
- _R.print_m_line("testMode is On. Press 'X' to stop")
- _C.nextbet = 0.00000004
- # _C.nobetdisplay = True
- # _C.testMode = True
- cred = 100000
- start = _C.betcount
- while cred > 0 and _C.currentstreak > -7:
- bet(_C.nextbet, -1)
- cred -= 1
- if _C.hitsFlag:
- cred = 0;
- if _R.w.getch() == ord("X"):
- _R.msgregion.addstr("testMode is off\n")
- _R.msgregion.refresh()
- cred = 0
- # _C.nobetdisplay = False
- # _C.testMode = False
- _R.msgregion.addstr("{:12} ({}) ".format(_C.betcount, _C.betcount-start))
- _R.msgregion.addstr("hunt streak {:3} (low)\n".format(_C.currentstreak), curses.color_pair(2))
- _R.msgregion.refresh()
- # elif _C.kbd == curses.KEY_MOUSE :
- # try:
- # pos = curses.getmouse()
- # except:
- # pos = None
- # if pos:
- # if pos[2] == _R.manualline.getbegyx()[0] and 16 < pos[1] < 31: # edit chance2 - mouse right click on chance2 in manualline
- # _C.chance2 = float(text_input(_C.chance2, *(1, 15, pos[2], 16)))
- # if pos[2] == _R.manualline.getbegyx()[0] and 32 < pos[1] < 48: # edit chance - mouse right click on chance in manualline
- # _C.chance = float(text_input(_C.chance, *(1, 15, pos[2], 34)))
- # if pos[2] == _R.manualline.getbegyx()[0] and 49 < pos[1] < 64: # edit chance - mouse right click on chance in manualline
- # nextbet = float("{:0.8f}".format(_C.nextbet))
- # _C.nextbet = float(text_input(nextbet, *(1, 18, pos[2], 49)))
- else:
- if _C.kbd>0:
- _R.msgregion.addstr("you pressed {} - Edit your code to make it do something useful\n".format(curses.unctrl(_C.kbd)))
- _R.msgregion.refresh()
- _C.manualActive = False
- _R.clear_m_line()
- # the print() function for Lua scripts
- def msg(s):
- _R.msgregion.addstr("{:12}: ".format(_C.betcount))
- _R.msgregion.addstr("{}\n".format(s), curses.color_pair(2))
- _R.msgregion.refresh()
- def stoplua():
- bailout("\nStop() called\n"+
- "\nBalance: {:13.8f} {}\n\033[0m".format(_C.balance, "CLAM")+
- "Profit: {:13.8f} {} ({:2f}%)\n\033[0m".format(_C.balance - _C.bstart, "CLAM", float((_C.balance-_C.bstart)*100/_C.bstart) if _C.bstart > 0 else 0)+
- "\n {} bets done in {} seconds ({:2f} bets/sec) ".format(_C.betcount, _C.seconds,float(_C.betcount/_C.seconds) if _C.seconds else _C.betcount))
- return 1
- def bailout(msg):
- curses.endwin()
- print("\nFATAL ERROR:\n {}\n\n".format(msg))
- # quit()
- sys.exit(9)
- ########################################################
- ########################################################
- def curses_main(w):
- curses.curs_set(0);
- curses.cbreak();
- curses.noecho();
- w.nodelay (True);
- curses.mousemask(curses.BUTTON3_CLICKED)
- w.refresh()
- curses.start_color()
- curses.use_default_colors();
- curses.init_pair (1, curses.COLOR_GREEN, -1);
- curses.init_pair (2, curses.COLOR_YELLOW, -1);
- curses.init_pair (3, curses.COLOR_RED, -1);
- curses.init_pair (4, curses.COLOR_CYAN, -1);
- curses.init_pair (5, curses.COLOR_WHITE, -1);
- curses.init_pair (100, curses.COLOR_GREEN, -1); # the following pairs are for color gradient
- curses.init_pair (99, 48, -1); # on 256 color terminal. TODO: check if colors availble
- curses.init_pair (98, 82, -1);
- curses.init_pair (97,118, -1);
- curses.init_pair (96,154, -1);
- curses.init_pair (95,190, -1);
- curses.init_pair (94,226, -1);
- curses.init_pair (93,220, -1);
- curses.init_pair (92,214, -1);
- curses.init_pair (91,208, -1);
- curses.init_pair (90,202, -1);
- curses.init_pair (89,196, -1);
- curses.init_pair (88,160, -1);
- curses.init_pair (87,124, -1);
- curses.init_pair (86, 88, -1);
- _R.init(w)
- _R.header2.addstr("{}: {}".format(_path, _C.botname))
- _R.w.refresh()
- _R.refresh(["header1", "header2", "stat", "betregion", "msgregion"])
- _R.print_m_line()
- if not login():
- return 0
- _C.WS = websocket.create_connection(f"wss://{server}/socket.io/?EIO=3&transport=websocket&sid={_C.sid}",
- cookie = _C.SessionCookie)
- _C.WS.send('2probe')
- _C.WS.recv()
- _C.WS.send('5')
- _C.WS.recv()
- _C.maxbalance=_C.balance;
- _C.minbalance=_C.balance;
- _C.bstart=_C.balance;
- _R.update_status()
- if _C.goalDelta > 0:
- _C.goal = _C.balance + _C.goalDelta
- if _C.percentualStop > 100:
- _C.percentualStop = 100
- if _C.percentualStop > 0:
- _C.stopamount = _C.balance*_C.percentualStop/100
- _C.kbd = -1
- if _C.manualSession:
- manual_mode();
- else:
- _C.lua = lupa.LuaRuntime()
- try:
- init_lua()
- except Exception as err:
- # _C.kbd = ord("Q")
- # _C.exitReason = f'Lua Exception occured: {err}'
- bailout(err)
- while _C.kbd not in (ord("Q"), ord("D")):
- w.timeout (0)
- _C.kbd = w.getch()
- if _C.kbd > 0 :
- if _C.kbd == ord('h'):
- _C.stopamount *= 110/100
- _C.stopbetting = False
- elif _C.kbd == ord('c'):
- msg("Continue pressed...")
- _C.stopbetting = False
- elif _C.kbd == ord('p'):
- _C.stopbetting = True
- msg("Pause pressed...")
- elif _C.kbd == ord('M'):
- msg("manualMode pressed...")
- manual_mode()
- elif _C.kbd == ord('N'):
- _C.nobetdisplay = not _C.nobetdisplay
- msg(f"nobetdisplay is {'ON' if _C.nobetdisplay else 'OFF'}")
- elif _C.kbd == ord('s'):
- _R.header1.addstr(1, 30, "STOP5 @", curses.color_pair(3) | curses.A_BOLD)
- _C.profitensure = True
- elif _C.kbd == ord('x'):
- _R.header1.addstr(0, 32, "EXIT on MAX balance", curses.color_pair(4) | curses.A_BOLD)
- _C.exitOnMax = True
- # elif _C.kbd == ord(''):
- # elif _C.kbd == ord(''):
- if _C.goal > 0 and _C.balance > _C.goal:
- _C.exitOnMax = True
- if not _C.stopbetting:
- bet(_C.nextbet, _C.side)
- _C.sessionprofit = _C.balance - _C.bstart;
- _C.lua.globals()["balance"] = _C.balance
- _C.lua.globals()["secret"] = _C.secret
- _C.lua.globals()["win"] = _C.win
- _C.lua.globals()["profit"] = _C.sessionprofit
- _C.lua.globals()["currentprofit"] = _C.currentprofit
- _C.lua.globals()["currentstreak"] = _C.currentstreak
- _C.lua.globals()["previousbet"] = _C.nextbet
- _C.lua.globals()["bets"] = _C.betcount
- _C.lua.globals()["wins"] = _C.wincount
- _C.lua.globals()["losses"] = _C.losecount
- _C.lua.globals()["info"] = ""
- _C.lua.globals()["side"] = _C.side
- _C.lua.globals().dobet()
- _C.chance = float(int(_C.lua.globals()["chance"]*100)/100)
- _C.nextbet = _C.lua.globals()["nextbet"]
- _C.basebet = _C.nextbet;
- _C.infoval = _C.lua.globals()["info"]
- _C.side = _C.lua.globals()["side"]
- def print_usage_info() :
- print("call it as: python main.py [options] <name_of_your_lua_file>");
- print("\noptions:");
- print(" -m # start a manual session\n");
- def main(argv):
- """
- The curses.wrapper function is an optional function that
- encapsulates a number of lower-level setup and teardown
- functions, and takes a single function to run when
- the initializations have taken place.
- """
- if len(argv) == 0 :
- print_usage_info()
- #login()
- else :
- try:
- opts, args = getopt.getopt(argv, "mH:h:knNXt:g:G:P:")
- except getopt.GetoptError:
- print_usage_info()
- quit()
- for opt, arg in opts :
- # print("opt - {} arg - {}".format(opt, arg) )
- if opt == "-m":
- _C.manualSession = True
- continue
- elif opt == "-H":
- _C.stopamount = float(arg)
- continue
- elif opt == "-h":
- _C.percentualStop = float(arg)
- continue
- elif opt == "-k":
- _C.keeplogfile = True
- continue
- elif opt == "-n":
- _C.noprofitensure = True
- continue
- elif opt == "-N":
- _C.nobetdisplay = True
- continue
- elif opt == "-t":
- _C.turnlimit = int(arg)
- continue
- elif opt == "-g":
- _C.goal = float(arg)
- continue
- elif opt == "-G":
- _C.goalDelta = float(arg)
- continue
- elif opt == "-P":
- _C.profitensurance = float(arg)
- continue
- else:
- print ("Unknown option {} ({})".format(opt, arg))
- quit()
- if not _C.manualSession:
- if args:
- _C.botname = args[-1]
- else:
- print ("you forgot botname\n")
- print_usage_info()
- quit()
- # quit()
- curses.wrapper(curses_main)
- # curses.curs_set(1)
- curses.endwin()
- _C.WS.close()
- if _C.betcount:
- logfile = open(_path+"/pybot.log", "a")
- line = "{} ".format(int(time.time()))
- line += "won {} of {} bets ({:.2f}%) at {:.2f}% chance, ".format(_C.wincount, _C.betcount,
- float(_C.wincount/_C.betcount*100), _C.chance)
- line += "Balance: {:.8f} {}, ".format(_C.balance, "CLAM")
- line += " bmax: {:.8f} ".format(_C.maxbalance)
- line += " lastmaxmax: {} ".format(_C.lastmaxmax)
- line += " MaxPayIn: {:.8f} ".format(_C.MaxPayIn)
- line += " minstreak: {}, maxstreak: {}, maxdiff: {:.8f}".format(_C.minstreak, _C.maxstreak, _C.maxdiff)
- line += ", {}, ".format(_C.botname)
- line += "{} \n".format(_C.exitReason)
- logfile.write(line)
- logfile.close()
- _C.seconds = int (_C.end - _C.begin)
- print("\n"*(_R.height-30))
- print("\033[1m\n\npybot exit: {}\n".format(_C.exitReason))
- print(" Balance: {:13.8f} {}\n\033[0m".format(_C.balance, "CLAM"))
- print(" Profit: {:13.8f} {} ({:2f}%)\n\033[0m".format(
- _C.balance - _C.bstart,
- "CLAM", float((_C.balance-_C.bstart)*100/_C.bstart) if _C.bstart > 0 else 0))
- print("\n {} bets done in {} seconds ({:2f} bets/sec) ".format(
- _C.betcount, _C.seconds,float(_C.betcount/_C.seconds) if _C.seconds else _C.betcount))
- print(" bmax: {:.8f} ".format(_C.maxbalance))
- print(" MaxPayIn: {:.8f}\n".format(_C.MaxPayIn))
- print(" minstreak: {}, maxstreak: {}, ".format(_C.minstreak, _C.maxstreak))
- print(" maxdiff: {:.8f} \n".format(_C.maxdiff))
- else:
- print("\033[1m\n\npybot exit: {}\n".format(_C.exitReason))
- print("\033[1m\n\npybot exit: no betting :P\n\033[0m")
- if (_C.kbd == ord('D')):
- sys.exit(9)
- main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement