Advertisement
coinwalk

jdbot.py

Jul 3rd, 2023
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.72 KB | None | 0 0
  1. import curses
  2. import curses.textpad
  3. import requests
  4. import json
  5. import io
  6. import os
  7. import sys, getopt
  8. from pathlib import Path
  9. import re
  10. import random
  11. import time
  12. import lupa
  13. from parse import parse
  14. import websocket
  15. from requests.structures import CaseInsensitiveDict
  16.  
  17.  
  18.  
  19. server = 'just-dice.com'
  20.  
  21. username = "XXXX"
  22. password = "XXXX"
  23.  
  24. _path = os.path.abspath(os.path.dirname(__file__))
  25. account_file = Path(_path+'/account.jd')
  26.  
  27. ##
  28. ## stores a configuration.
  29. ########################################################
  30. class Config:
  31. def __init__(self):
  32. self.WS = None
  33. self.manualSession = False
  34. self.manualActive = False
  35. self.recovery = False
  36. self.exitOnMax = False
  37. self.noprofitensure = False
  38. self.stopbetting = False
  39. self.profitensure = False
  40. self.hitsFlag = False
  41. self.OnStopCmd = True
  42. self.alarmOn = True
  43. self.stopifwin = False
  44. self.balance = 0.0
  45. self.maxbalance = 0.0
  46. self.minbalance = 0.0
  47. self.bstart = -1.0
  48. self.before = 0
  49. self.SessionCookie = "c0ffee00000000000000000000c0ffee"
  50. self.sid = ""
  51. self.csrf = ""
  52. self.maxdiff = 0
  53. self.wagered = 0
  54. self.wincount = 0
  55. self.losecount = 0
  56. self.betcount = 0
  57. self.lastmax = 0
  58. self.lastmaxmax = 0
  59. self.currentstreak = 0
  60. self.currentprofit = 0
  61. self.minstreak = 0
  62. self.maxstreak = 0
  63. self.chance = 49.5
  64. self.chance2 = 57.0
  65. self.MaxPayIn = 0
  66. self.nextbet = 0.0000001
  67. self.basebet = self.nextbet
  68. self.goal = 0
  69. self.goalDelta = 0
  70. self.myRange = 0
  71. self.secret = 0
  72. self.win = None
  73. self.streakwin = [0 for i in range(204800)]
  74. self.streaklose = [0 for i in range(204800)]
  75. self.gain = 0
  76. self.keeplogfile = False
  77. self.kbd = 0
  78. self.infoval = ""
  79. self.testMode = False
  80. self.nobetdisplay = False
  81. self.bnowfile = _path+"/bnow.CLAM"
  82. self.exitReason = ""
  83. self.botname = ""
  84. self.begin = time.time()
  85. self.end = time.time()
  86. self.now = time.time()
  87. self.seconds = 0
  88. self.oldseconds = 0
  89. self.stopamount = 0.2
  90. self.percentualStop = 0
  91. self.turnlimit = 0
  92. self.profitensurance = 0
  93. self.lua = 0
  94. self.side = 1
  95. ## End Config
  96. _C = Config()
  97.  
  98. ##
  99. ## for work with curses regions
  100. ########################################################
  101. class Regions:
  102. def init(self, w):
  103. self.w = w
  104. (height, width) = w.getmaxyx ();
  105. self.height, self.width = (height, width)
  106. self.header1 = curses.newwin (7, width//2-10, 0, 0)
  107. self.header2 = curses.newwin (7, width-self.header1.getmaxyx()[1], 0, self.header1.getmaxyx()[1]+1)
  108. self.stat = curses.newwin (2, width, 7, 0)
  109. heightavail=height-9
  110. self.betregion = curses.newwin (heightavail//2+4, width, 9+1, 0)
  111. self.manualline = curses.newwin (1, width, 9+self.betregion.getmaxyx()[0]+1, 0)
  112. self.msgregion = curses.newwin (heightavail//2-4, width, 9+self.betregion.getmaxyx()[0]+1+1, 0)
  113. self.betregion.scrollok(True)
  114. self.msgregion.scrollok(True)
  115. self.w.addstr(9, 0, " balance chance high betsize profit lucky ")
  116. w.refresh()
  117.  
  118. # refreshes curses regions from list
  119. def refresh (self, regions):
  120. for r in regions:
  121. getattr(self, r).refresh()
  122.  
  123. # prints manualline region
  124. def print_m_line(self, msg=""):
  125. if len(msg) == 0: # manual betting mode
  126. if not _C.manualActive:
  127. self.clear_m_line()
  128. return
  129. if _C.balance > _C.before:
  130. s = " +{:.8f} D {:.8f}".format(_C.balance-_C.before, _C.balance - _C.goal)
  131. else:
  132. s = " {:.8f} D {:.8f}".format(_C.balance-_C.before, _C.balance - _C.goal)
  133. self.manualline.addstr(0, 0, "{:<14}{:>15.4f}% {:>15.4f}%{:>15.8f}{}".format("", _C.chance2, _C.chance, _C.nextbet, s))
  134. self.manualline.refresh()
  135. else: # msg mode
  136. self.clear_m_line()
  137. self.manualline.addstr(msg)
  138. self.manualline.refresh()
  139.  
  140. def clear_m_line(self):
  141. self.manualline.move(0, 0)
  142. self.manualline.clrtoeol()
  143. self.manualline.refresh()
  144.  
  145. # prints statistics in header1, header2 and stat regions
  146. def update_status(self):
  147. self.header1.attron(curses.color_pair(2))
  148. self.header1.addstr(0, 0, " minimum:{:15.8f}".format(_C.minbalance))
  149. self.header1.addstr(1, 0, " current:{:15.8f} ({:.8f}) ".format(_C.balance, _C.maxbalance-_C.stopamount))
  150. self.header1.addstr(2, 0, " diff:{:15.8f} (max. {:.8f}) ".format(_C.maxbalance - _C.balance, _C.maxdiff))
  151. self.header1.addstr(3, 0, " maximum:{:15.8f}".format(_C.maxbalance))
  152. if _C.goal > 0 :
  153. self.header1.addstr(3, 25, "(goal: {:.8f})".format(_C.goal))
  154. self.header1.addstr(4, 0, " profit:{:15.8f} ({:.3f}%) ".format(_C.balance - _C.bstart,
  155. 0 if _C.bstart == 0 else float(_C.balance*100/_C.bstart-100)))
  156. self.header1.addstr(5, 0, "MaxPayIn:{:15.8f}".format(_C.MaxPayIn))
  157. self.header1.addstr(6, 0, " wagered:{:15.8f}".format(_C.wagered))
  158. self.header1.attroff(curses.color_pair(2))
  159.  
  160. if _C.profitensure:
  161. self.header1.addstr(1,43, "{:.8f}".format(float((_C.bstart + _C.maxbalance)/200000000)), curses.color_pair(2))
  162.  
  163. self.header1.refresh()
  164.  
  165. _C.end = time.time()
  166. _C.seconds = int(_C.end - _C.begin)
  167. if _C.seconds > 0:
  168. betsPerSecond = float(_C.betcount/_C.seconds)
  169. profitPerSecond = (_C.balance-_C.bstart)/_C.seconds
  170. else:
  171. betsPerSecond = 0
  172. profitPerSecond = 0
  173. minutes = int(_C.seconds/60)
  174. hours = int(minutes/60)
  175. minutes = minutes%60
  176. _C.seconds = _C.seconds%60
  177.  
  178. self.header2.addstr(1, 0, "won {} of {} bets ({:.4f}% {:.2f} bets/s ) ".format(
  179. _C.wincount, _C.betcount, float(_C.wincount / _C.betcount * 100 if _C.betcount else 0), betsPerSecond))
  180. if _C.betcount - _C.lastmax > _C.lastmaxmax :
  181. _C.lastmaxmax = _C.betcount - _C.lastmax;
  182. self.header2.addstr(2, 0, "last max: {:>5} ({}) {:.2f}% ".format(
  183. _C.betcount - _C.lastmax, _C.lastmaxmax, float(_C.balance * 100 / _C.maxbalance if _C.maxbalance else 0)))
  184. self.header2.addstr(3, 0, "streak: {:>5} (min {} max {}) ".format(
  185. _C.currentstreak, _C.minstreak, _C.maxstreak))
  186. if _C.seconds != _C.oldseconds:
  187. self.header2.addstr(4, 0, "{}:{:02}:{:02} {:0.2f}/min {:0.2f}/hour ".format(
  188. hours,minutes,_C.seconds, profitPerSecond*60, profitPerSecond*3600))
  189. _C.oldseconds=_C.seconds
  190. self.header2.addstr(5, 0, f"info: {_C.infoval}")
  191. self.header2.refresh()
  192.  
  193. for n in range(6,-1,-1):
  194. if -1*_C.minstreak - n > 0:
  195. self.stat.addstr(0, 1+n*6, "{:4}".format(-1*_C.minstreak - n), curses.color_pair(3))
  196. self.stat.addstr(1, 1+n*6, "{:4}".format(_C.streaklose[-1*_C.minstreak - n]))
  197.  
  198. for n in range(6,-1,-1):
  199. if _C.maxstreak-n > 0:
  200. self.stat.addstr(0, self.width-16-n*6, "{:4}".format(_C.maxstreak-n), curses.color_pair(1))
  201. self.stat.addstr(1, self.width-16-n*6, "{:4}".format(_C.streakwin[_C.maxstreak-n]))
  202. self.stat.refresh()
  203.  
  204. ## End Regions
  205. _R = Regions()
  206.  
  207. ##
  208. ## low/high hits statistic
  209. ########################################################
  210. class HitsStat():
  211. min_hits = (250,125,100,65,55,40,33,27,24,20,15,13,10,9,8,7,7,6,5)
  212.  
  213. def __init__(self):
  214. self.low = [{"count" : 0, "use" : False} for i in range(20)]
  215. self.high = [{"count" : 0, "use" : False} for i in range(20)]
  216. self.chances = []
  217. self.lowFlag = False
  218. self.highFlag = False
  219. self.chancesCurrent = 0
  220.  
  221. def check(self, R):
  222. posLow = R // 500
  223. posHigh = 19 - posLow
  224. self.lowFlag = False
  225. self.highFlag = False
  226. for i in range(19):
  227. if posLow > i:
  228. self.low[i]["count"] += 1
  229. if self.low[i]["count"] >= self.min_hits[i]:
  230. self.low[i]["use"] = True
  231. self.lowFlag = True
  232. elif posLow <= i:
  233. self.low[i]["count"] = 0
  234. self.low[i]["use"] = False
  235.  
  236. if posHigh > i:
  237. self.high[i]["count"] += 1
  238. if self.high[i]["count"] >= self.min_hits[i]:
  239. self.high[i]["use"] = True
  240. self.highFlag = True
  241. elif posHigh <= i:
  242. self.high[i]["count"] = 0
  243. self.high[i]["use"] = False
  244. return (self.lowFlag, self.highFlag)
  245.  
  246. def once_in(self, count, chance):
  247. return 1/(1-chance/100)**count
  248.  
  249. def print_msg(self):
  250. self.chances.clear()
  251. s = ""
  252. if self.lowFlag:
  253. s += "L: "
  254. for i in range(19):
  255. if self.low[i]["use"]:
  256. s += "c{} ({} once in {:.0f})| ".format((i+1)*5, self.low[i]["count"], self.once_in(self.low[i]["count"], (i+1)*5))
  257. self.chances.append((i+1)*5)
  258. #msg(s)
  259. if self.highFlag:
  260. s += "H: "
  261. for i in range(19):
  262. if self.high[i]["use"]:
  263. s += "c{} ({} once in {:.0f})| ".format((i+1)*5, self.high[i]["count"], self.once_in(self.high[i]["count"], (i+1)*5))
  264. self.chances.append((i+1)*5)
  265. #msg(s)
  266. self.chances.append(57)
  267.  
  268. # switching chance2
  269. def toggle_chances(self):
  270. if len(self.chances) > 0:
  271. if self.chancesCurrent >= len(self.chances):
  272. self.chancesCurrent = 0
  273. _C.chance2 = self.chances[self.chancesCurrent]
  274. self.chancesCurrent += 1
  275.  
  276. ## End HitsStat
  277. _H = HitsStat()
  278.  
  279.  
  280.  
  281. ########################################################
  282. # converts float to string (to avoid scientific notation)
  283. def float_to_str(f):
  284. float_string = repr(f)
  285. if 'e' in float_string: # detect scientific notation
  286. digits, exp = float_string.split('e')
  287. digits = digits.replace('.', '').replace('-', '')
  288. exp = int(exp)
  289. # minus 1 for decimal point in the sci notation
  290. zero_padding = '0' * (abs(int(exp)) - 1)
  291. sign = '-' if f < 0 else ''
  292. if exp > 0:
  293. float_string = '{}{}{}.0'.format(sign, digits, zero_padding)
  294. else:
  295. float_string = '{}0.{}{}'.format(sign, zero_padding, digits)
  296. return float_string
  297.  
  298. ########################################################
  299. def login():
  300. con_cookies = {}
  301.  
  302. headers = CaseInsensitiveDict()
  303. headers["Host"] = server
  304. headers["User-Agent"] = "'User-Agent': 'Firefox'"
  305. headers["Connection"] = "Keep-Alive"
  306.  
  307. try:
  308. #read connect.sid and hash cookies from file (if they were saved already)
  309. if account_file.is_file():
  310. with open(account_file) as data_file:
  311. con_cookies = json.load(data_file)
  312. else:
  313. # print("# get connect.sid cookie")
  314. headers["Cookie"] = "hash=b30adf82007d8544fa8ac14227ace6dfd1f7c1ee0b39c951ea101798cda5bbdb"
  315. response = requests.get(f"https://{server}/", headers=headers)
  316. if 'Set-Cookie' in response.headers.keys():
  317. con_cookies["sid"] = response.headers['Set-Cookie'].split(";")[0].split("=")[1]
  318.  
  319. # print(con_cookies)
  320. # print("# get hash cookie")
  321. headers["Cookie"] = f"hash=b30adf82007d8544fa8ac14227ace6dfd1f7c1ee0b39c951ea101798cda5bbdb; connect.sid={con_cookies['sid']}"
  322. d = {'username' : username, 'password' : password, 'code' : ""}
  323. response = requests.post(f"https://{server}", data=d, headers=headers)
  324. if 'Set-Cookie' in response.headers.keys():
  325. con_cookies["hash"] = response.headers['Set-Cookie'].split(";")[0].split("=")[1]
  326.  
  327.  
  328. with io.open(account_file, 'w', encoding='utf8') as outfile:
  329. str_ = json.dumps(con_cookies,
  330. indent=4, sort_keys=True,
  331. separators=(',', ': '), ensure_ascii=False)
  332. outfile.write(str(str_))
  333.  
  334.  
  335.  
  336. # print(con_cookies)
  337. # print("# get io cookie")
  338. headers["Referer"] = f"https://{server}/"
  339. headers["Cookie"] = f"hash={con_cookies['hash']}; connect.sid={con_cookies['sid']}"
  340. response = requests.get(f"https://{server}/socket.io/?EIO=3&transport=polling&t={int(time.time()*1000)}-0",
  341. headers=headers)
  342. if 'Set-Cookie' in response.headers.keys():
  343. con_cookies["io"] = response.headers['Set-Cookie'].split(";")[0].split("=")[1]
  344.  
  345. # print(con_cookies)
  346. # print("# get csrf and other stuff")
  347. headers["Cookie"] = f"io=3{con_cookies['io']}; hash={con_cookies['hash']}; connect.sid={con_cookies['sid']}"
  348. response = requests.get(
  349. f"https://{server}/socket.io/?EIO=3&transport=polling&t={int(time.time()*1000)}-1&sid={con_cookies['io']}",
  350. headers=headers)
  351.  
  352. rest_txt = response.text.split("ÿ42")[1]
  353. rest_txt = rest_txt[:rest_txt.rfind("]")+1]
  354.  
  355. stats = json.loads(rest_txt)[1]
  356. del stats["chat"]
  357. _C.csrf = stats["csrf"]
  358. _C.sid = con_cookies['io']
  359. _C.SessionCookie = headers["Cookie"]
  360. _C.balance = float(stats["balance"])
  361. _C.uid = stats['uid']
  362. return True
  363.  
  364. except Exception as err:
  365. _C.exitReason = f"login error ({err})"
  366. return False
  367.  
  368.  
  369.  
  370. ########################################################
  371. def do_bet(bet):
  372. try:
  373. # msg(bet)
  374. _C.WS.send(bet)
  375. # 42["jderror","bet should be a string"]
  376. # 42["jderror","You already have a roll pending. Are you playing from multiple locations?"]
  377. result = _C.WS.recv()
  378. waiting = True
  379. count = 0
  380. while waiting:
  381. count += 1
  382. if "result" in result:
  383. r = json.loads(result[2:])[1]
  384. if r['uid'] == _C.uid:
  385. return result
  386. if "jderror" in result or count > 20:
  387. msg(f"Count: {count}")
  388. msg(result)
  389. waiting = False
  390. break
  391. result = _C.WS.recv()
  392. _C.exitReason = f'Bet error ({result})'
  393. return None
  394.  
  395.  
  396. except Exception as err:
  397. _C.exitReason = f'Bet request - error occurred: {err}'
  398. return None
  399.  
  400.  
  401. ########################################################
  402. # shows textbox for input float values (betsize, chances)
  403. # TODO: fix font/color
  404. def text_input(old_value, h, w, y, x):
  405. window = curses.newwin(h, w, y, x)
  406. window.clear()
  407. curses.curs_set(1)
  408. window.bkgd(' ', curses.color_pair(2) | curses.A_BOLD | curses.A_REVERSE)
  409. # window.addstr(0, 0, "{:15.8f}".format(old_value))
  410. window.addstr(0, 0, float_to_str(old_value))
  411. window.refresh()
  412. textbox = curses.textpad.Textbox(window)
  413. # textbox.stripspaces = 0
  414.  
  415. class EscapeInterrupt(Exception):
  416. "Signal that the ESC key has been pressed"
  417. # filter keys (only [0-9.]) and set more convinient controls
  418. def validate(ch):
  419. if ch == 27:
  420. raise EscapeInterrupt()
  421. # Fix backspace for iterm
  422. if ch not in (10, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 262, 260, 330, 360, 261, 127):
  423. return 12
  424. if ch == curses.KEY_HOME: #
  425. ch = 1
  426. if ch == curses.KEY_LEFT:
  427. ch = 2
  428. if ch == 330: # DEL
  429. ch = 4
  430. if ch == curses.KEY_END:
  431. ch = 5
  432. if ch == curses.KEY_RIGHT:
  433. ch = 6
  434. if ch == 127: # BACKSPACE
  435. ch = 263
  436. return ch
  437. try:
  438. out = textbox.edit(validate=validate)
  439. except EscapeInterrupt:
  440. out = str(old_value)
  441. try:
  442. float(out)
  443. except ValueError:
  444. out = str(old_value)
  445. curses.curs_set(0)
  446. window.erase()
  447. del window
  448. return out
  449.  
  450.  
  451. ########################################################
  452. def get_random_int(a,b):
  453. return random.SystemRandom().randint(a, b)
  454.  
  455.  
  456. ########################################################
  457. # init/reset lua state before running script
  458. def init_lua():
  459. source = open(_C.botname).read()
  460. _C.lua.globals()["balance"] = _C.balance
  461. _C.lua.globals()["print"] = msg
  462. _C.lua.globals()["stop"] = stoplua
  463. _C.lua.globals()["infoval"] = ""
  464. _C.lua.globals()["side"] = _C.side
  465. _C.lua.execute(source)
  466. _C.chance = float(int(_C.lua.globals()["chance"]*10000)/10000)
  467. _C.nextbet = _C.lua.globals()["nextbet"]
  468. _C.basebet = _C.nextbet;
  469. _C.side = _C.lua.globals()["side"]
  470.  
  471.  
  472. ########################################################
  473. class BetInfo:
  474. def __init__(self, betsize, chance, side=0):
  475. if side == 0:
  476. self.Which = "lo" if get_random_int(0, 999999) < 500000 else "hi"
  477. elif side == -1:
  478. self.Which = "lo"
  479. else:
  480. self.Which = "hi"
  481. self.BetSize = betsize
  482. self.Chance = chance
  483.  
  484. def set_result(self, res):
  485. # [
  486. # "result",
  487. # {
  488. # "bankroll": "3730713.91797571",
  489. # "bet": "0",
  490. # "betid": 5406701465,
  491. # "bets": "283",
  492. # "chance": "33.33",
  493. # "date": 1651234642,
  494. # "high": false,
  495. # "luck": "94.62%",
  496. # "lucky": 733854,
  497. # "max_profit": "341299.73",
  498. # "name": "yorK (3615997)",
  499. # "nonce": 65,
  500. # "payout": 2.97029703,
  501. # "ret": "0",
  502. # "this_profit": "-0",
  503. # "uid": "3615997",
  504. # "wagered": "0.00000000",
  505. # "win": false,
  506. # "stats":
  507. # {
  508. # "bets": 5406701465,
  509. # "losses": 3292547495,
  510. # "luck": 5406187554.532714,
  511. # "profit": -917006.16165835,
  512. # "wagered": 74982197.07890135,
  513. # "wins": 2114152617
  514. # },
  515. # "investment": 0,
  516. # "percent": 0,
  517. # "invest_pft": 0,
  518. # "balance": "0.00000000",
  519. # "profit": "0.00000000"
  520. # }
  521. # ]
  522. res = json.loads(res[2:])[1]
  523. # msg(res)
  524.  
  525. self.bet = res['bet']
  526. self.betid = res['betid']
  527. self.chance = float(res['chance'])
  528. self.high = res['high']
  529. self.lucky = int(res['lucky'])
  530. self.payout = float(res['payout'])
  531. self.profit = float(res['this_profit'])
  532. self.win = res['win']
  533. self.balance = float(res['balance'])
  534.  
  535. # self.bet = 0.0
  536. # self.betid = 0
  537. # self.chance = 50
  538. # self.high = True
  539. # self.lucky = 25.25
  540. # self.payout = 0.0
  541. # self.profit = 0.0
  542. # self.win = True
  543. # self.balance = 0.0
  544.  
  545.  
  546. def request(self, log=False) :
  547. # ws.send(f'42["bet","{csrf}",{{"chance":"{chance}","bet":"{betsize}","which":"{which}"}}]')
  548. bet = {"chance" : self.Chance, "bet" : self.BetSize, "which" : self.Which}
  549. return f'42["bet","{_C.csrf}",{{"chance":"{bet["chance"]}","bet":"{bet["bet"]:.8f}","which":"{bet["which"]}"}}]' if not log else bet
  550.  
  551.  
  552.  
  553.  
  554. ########################################################
  555. def betlog(line):
  556. logfile = open(_path+"/betlog", "a")
  557. logfile.write(f"{line}\n")
  558. logfile.close()
  559. if os.stat(_path+"/betlog").st_size > 10485760 and not _C.keeplogfile:
  560. os.rename(_path+"/betlog",_path+"/betlog.old")
  561.  
  562.  
  563. def interactive_mode():
  564. _C.nobetdisplay = False
  565. #ask back to user what to do next
  566. if _C.OnStopCmd and _C.alarmOn:
  567. print("\a")
  568. _C.alarmOn = False
  569. if not _C.hitsFlag:
  570. _C.goal = _C.maxbalance
  571. ekey = 1
  572. ekey = _R.w.getch()
  573. while ekey not in (ord("q"), ord("c"), ord("m"), ord('+'), ord('w')):
  574. _R.w.timeout(5)
  575. ekey = _R.w.getch()
  576. # if (hardstop==1) ekey='q';
  577. if _C.balance > _C.maxbalance:
  578. ekey = ord("q")
  579. if ekey == ord("q"):
  580. _C.kbd = ord("Q")
  581. return 0
  582. if ekey == ord("m"):
  583. _C.hitsFlag = False
  584. manual_mode()
  585. return 0
  586. if ekey == ord("w") and not _C.hitsFlag:
  587. _C.stopifwin = True
  588. if ekey == ord("c"):
  589. _C.stopifwin = False
  590. if ekey == ord("+"):
  591. _C.stopamount *= 110/100
  592. return 0
  593.  
  594.  
  595.  
  596. ##
  597. ## Single bet
  598. ##
  599. ## :param betsize: The betsize
  600. ## :type betsize: float
  601. ## :param side: The range -1, 0, 1
  602. ## :type side: int
  603. ## :param chance: The chance or None
  604. ## :type chance: float
  605. ##
  606. def bet(betsize, side=0, chance=None):
  607. if chance is None:
  608. chance = _C.chance
  609. b = BetInfo(betsize, chance, side)
  610. # msg(b.request())
  611.  
  612. if b.BetSize > _C.MaxPayIn:
  613. _C.MaxPayIn = b.BetSize
  614. _C.wagered += b.BetSize;
  615.  
  616.  
  617. if not _C.noprofitensure:
  618. if _C.balance > _C.bstart * 2 and _C.bstart > 0:
  619. _C.profitensure = True
  620. _R.header1.addstr(1, 29, "STOP2 @", curses.color_pair(3) | curses.A_BOLD)
  621. if _C.maxdiff > 2000*_C.basebet and _C.balance > _C.bstart + 2*_C.maxdiff and _C.bstart > 0:
  622. _C.profitensure = True
  623. _R.header1.addstr(1, 29, "STOP3 @", curses.color_pair(3) | curses.A_BOLD)
  624. if _C.maxbalance - 2000*_C.basebet > _C.bstart and _C.bstart > 0:
  625. _C.profitensure = True
  626. _R.header1.addstr(1, 29, "STOP4 @", curses.color_pair(3) | curses.A_BOLD)
  627. if _C.profitensurance > 0 and _C.maxbalance - _C.profitensurance > _C.bstart and _C.bstart > 0:
  628. _C.profitensure = True
  629. _R.header1.addstr(1, 29, "STOP5 @", curses.color_pair(3) | curses.A_BOLD)
  630.  
  631. if _C.hitsFlag:
  632. _R.betregion.addstr("\nHits STOP. ", curses.color_pair(2) | curses.A_BOLD)
  633. _R.betregion.addstr("Press ")
  634. _R.betregion.addstr("c", curses.color_pair(2) | curses.A_BOLD)
  635. _R.betregion.addstr("ontinue / ")
  636. _R.betregion.addstr("q", curses.color_pair(2) | curses.A_BOLD)
  637. _R.betregion.addstr("uit / ")
  638. _R.betregion.addstr("m", curses.color_pair(2) | curses.A_BOLD)
  639. _R.betregion.addstr("anual (")
  640. _R.betregion.addstr("w", curses.color_pair(2) | curses.A_BOLD)
  641. _R.betregion.addstr(" - single bet, ")
  642. _R.betregion.addstr("+", curses.color_pair(2) | curses.A_BOLD)
  643. _R.betregion.addstr(" - stopamount*1.1)\n")
  644. _R.betregion.refresh()
  645.  
  646. if not _C.manualActive:
  647. interactive_mode()
  648. if _C.kbd == ord("Q"):
  649. return 0
  650.  
  651. else:
  652. if not _C.manualActive:
  653. if _C.balance >= _C.goal and _C.goal > 0:
  654. _C.exitReason = "GOAL REACHED {:.8f} >= {:.8f}".format(_C.balance, _C.goal)
  655. _C.kbd = ord("Q")
  656. return 0
  657.  
  658. #if _C.profitensure and _C.balance-b.BetSize < (_C.bstart + _C.maxbalance)/2:
  659. #_C.exitReason = "PROFIT ENSURANCE {:.8f} < {:.8f}".format(
  660. #float(_C.balance - b.BetSize),
  661. #float((_C.balance + _C.maxbalance) / 2))
  662. #_C.kbd = ord("Q")
  663. #return 0
  664.  
  665. #if ((_C.balance - b.BetSize < _C.maxbalance - _C.stopamount and _C.stopamount > 0 and _C.maxbalance > 0)
  666. #or _C.stopifwin):
  667. #_R.betregion.addstr("\nNext bet: {:.8f} - now at {:.2f}% of maxbalance. Press ".format(
  668. #betsize, float(_C.balance*100/_C.maxbalance)))
  669. #_R.betregion.addstr("c", curses.color_pair(2) | curses.A_BOLD)
  670. #_R.betregion.addstr("ontinue / ")
  671. #_R.betregion.addstr("q", curses.color_pair(2) | curses.A_BOLD)
  672. #_R.betregion.addstr("uit / ")
  673. #_R.betregion.addstr("m", curses.color_pair(2) | curses.A_BOLD)
  674. #_R.betregion.addstr("anual (")
  675. #_R.betregion.addstr("w", curses.color_pair(2) | curses.A_BOLD)
  676. #_R.betregion.addstr(" - single bet, ")
  677. #_R.betregion.addstr("+", curses.color_pair(2) | curses.A_BOLD)
  678. #_R.betregion.addstr(" - stopamount*1.1)\n")
  679.  
  680. #_R.betregion.refresh()
  681. #_C.exitOnMax = True
  682.  
  683. #if _C.balance < _C.bstart or _C.stopifwin:
  684. #interactive_mode()
  685. #if _C.balance > _C.bstart and _C.kbd != ord("X"):
  686. #_C.exitReason = "_C.balance > _C.bstart {:.8f} >= {:.8f}".format(_C.balance, _C.bstart)
  687. #_C.kbd = ord("Q")
  688. #return 0
  689. #else:
  690. #_C.kbd = ord("Q")
  691. #_C.exitReason = "ELSE: {:.8f} >= {:.8f}".format(_C.balance, _C.bstart)
  692. #return 0
  693.  
  694. betlog(b.request(log=True))
  695.  
  696.  
  697. res = do_bet(b.request())
  698.  
  699. if res is None:
  700. _C.stopbetting = True
  701. msg(f'chance: {b.Chance} amount : {b.BetSize:.8f}')
  702. msg(b.request())
  703. msg(_C.exitReason)
  704. # print("\a")
  705. return 0
  706. else:
  707. b.set_result(res)
  708. betlog(f'{res}'.replace("'",'"').replace(" ", ""))
  709. _C.secret = b.lucky/10000
  710.  
  711. if _C.bstart == -1:
  712. _C.bstart = b.balance - b.bet
  713.  
  714. h_l = " "
  715. if _C.secret < 49.5:
  716. h_l = "L"
  717. elif _C.secret >= 50.5:
  718. h_l = "H"
  719. l_30 = " ";
  720. h_30 = " ";
  721. if _C.secret < 30.0000001: l_30 = "|"
  722. if _C.secret > 70.0000: h_30 = "|"
  723.  
  724.  
  725. _C.hitsFlag = any(_H.check(_C.secret*100))
  726. if _C.hitsFlag:
  727. _H.print_msg()
  728.  
  729. _C.balance = b.balance
  730. bprofit = b.profit
  731. _C.currentprofit = b.profit
  732. oncein = 1
  733. if b.win : #win
  734. color = 1
  735. color2 = 1
  736. _C.win = True
  737. if _C.currentstreak < 0:
  738. _C.streaklose[-1*_C.currentstreak] +=1
  739. _C.currentstreak = 1
  740. oncein = 100/_C.chance
  741. else:
  742. _C.currentstreak += 1
  743. oncein *= 100/chance
  744. if oncein + 0.9 >= 8000:
  745. _R.msgregion.addstr("{:12}: {:0.8f} {:0.8f} streak {:3} (once in {})\n".format(
  746. _C.betcount, _C.balance, _C.gain, _C.currentstreak, int(oncein+0.9)))
  747. _R.msgregion.refresh()
  748. _C.wincount += 1
  749. else:
  750. color2 = 3
  751. _C.win = False
  752. if _C.currentstreak > 0:
  753. _C.streakwin[_C.currentstreak] +=1
  754. _C.currentstreak = -1
  755. oncein = 100/(100-_C.chance)
  756. else:
  757. _C.currentstreak -= 1
  758. oncein *= 100/(100-_C.chance)
  759. if oncein + 0.9 >= 8000:
  760. _R.msgregion.addstr("{:12}: {:0.8f} {:0.8f} streak {:3} (once in {})\n".format(
  761. _C.betcount, _C.balance, _C.gain, _C.currentstreak, int(oncein+0.9)))
  762. _R.msgregion.refresh()
  763. _C.losecount += 1
  764.  
  765. if _C.currentstreak < _C.minstreak:
  766. _C.minstreak = _C.currentstreak;
  767. if _C.currentstreak > _C.maxstreak:
  768. _C.maxstreak = _C.currentstreak;
  769. _C.betcount += 1
  770.  
  771. if (_C.balance >= _C.maxbalance):
  772. _C.gain = _C.balance - _C.maxbalance
  773. _C.maxbalance = _C.balance
  774. _C.maxbets = _C.betcount - _C.lastmax
  775. _C.lastmax = _C.betcount
  776. _R.betregion.attron(curses.A_BOLD)
  777.  
  778. if _C.exitOnMax or _C.turnlimit > 0 and _C.betcount > _C.turnlimit:
  779. _C.exitReason = f'EXIT on MAX requested'
  780. _C.kbd = ord('Q')
  781.  
  782.  
  783. if _C.balance < _C.minbalance:
  784. _C.minbalance = _C.balance
  785. if (_C.maxbalance - _C.balance) > _C.maxdiff:
  786. _C.maxdiff = _C.maxbalance - _C.balance
  787.  
  788. if not _C.testMode:
  789. if not _C.nobetdisplay or _C.manualActive:
  790. color = int(_C.balance*100/_C.maxbalance) if _C.maxbalance > 0 else 0
  791. if color < 86:
  792. color = 86
  793. _R.betregion.attron(curses.color_pair(color2))
  794.  
  795. if _C.balance < _C.maxbalance:
  796. _R.betregion.addstr("{} ".format(h_l))
  797. _R.betregion.addstr("{:4} {:4} ".format(abs(_C.currentstreak), _C.betcount-_C.lastmax))
  798. _R.betregion.addstr("{:18.8f} ".format(_C.balance), curses.color_pair(color))
  799. _R.betregion.addstr("{}{:5.4f}%{} {:^13} {:16.8f} {:16.8f} {:<9} \n".format(
  800. l_30, chance, h_30, str(b.high), betsize, bprofit, _C.secret))
  801. else:
  802. _R.betregion.addstr("{} {:4} {:4} {:18.8f} {}{:5.4f}%{} {:^13} {:16.8f} {:16.8f} {:<9} +{:.8f}\n".format(
  803. h_l,
  804. abs(_C.currentstreak),
  805. _C.betcount-_C.lastmax,
  806. _C.balance,
  807. l_30,
  808. chance,
  809. h_30, str(b.high),
  810. betsize,
  811. bprofit,
  812. _C.secret,
  813. _C.gain))
  814.  
  815. _R.betregion.attroff(curses.color_pair(color))
  816. _R.betregion.attroff(curses.A_BOLD)
  817. _R.betregion.refresh()
  818.  
  819. _R.update_status()
  820.  
  821. logfile = open(_C.bnowfile, "a")
  822. logfile.write("{}:{:.8f}\n".format(0, _C.balance))
  823. logfile.close()
  824.  
  825.  
  826.  
  827.  
  828. ########################################################
  829. def manual_mode():
  830. cred = 0
  831. localcount = 0
  832. _C.manualActive= True
  833. _C.before= _C.balance
  834. if _C.manualSession:
  835. _C.nextbet = 0.00000001
  836. _C.basebet = _C.nextbet
  837. else:
  838. _C.recovery = True
  839.  
  840. _R.update_status()
  841. _C.kbd = _R.w.getch()
  842. _C.now = time.time()
  843. while _C.kbd not in (ord("Q"), ord("D"), ord("X")):
  844. if _C.exitOnMax and _C.balance>=_C.maxbalance:
  845. msg(f"{_C.goal} - {_C.balance - _C.goal}")
  846. _C.kbd = ord("Q")
  847. continue
  848. if _C.balance - _C.goal > 0 and _C.goal > 0:
  849. msg(f"{_C.goal} - {_C.balance - _C.goal}")
  850. _C.kbd = ord("Q")
  851. continue
  852.  
  853.  
  854. _R.print_m_line()
  855. _R.w.timeout(5)
  856. _C.kbd = _R.w.getch()
  857.  
  858. if _C.kbd == ord('z'):
  859. _C.nextbet *= 2
  860. if _C.nextbet > _C.balance:
  861. _C.nextbet = _C.balance-0.00000001
  862.  
  863. elif _C.kbd == ord('x'):
  864. _C.nextbet /= 2
  865. if _C.nextbet < 0.00000001:
  866. _C.nextbet = 0.00000001
  867.  
  868. elif _C.kbd == ord('a'):
  869. _C.nextbet *= 1.5
  870. if _C.nextbet > _C.balance:
  871. _C.nextbet = _C.balance-0.00000001
  872.  
  873. elif _C.kbd == ord('s'):
  874. _C.nextbet /= 1.5
  875. if _C.nextbet < 0.00000001:
  876. _C.nextbet = 0.00000001
  877.  
  878. elif _C.kbd == ord('u'):
  879. _H.toggle_chances()
  880.  
  881. elif _C.kbd == ord('R'):
  882. if len(_C.botname):
  883. msg("Restart lua")
  884. init_lua()
  885. _C.stopbetting = False
  886. _C.kbd = ord('X')
  887. if _C.goalDelta > 0:
  888. _C.goal = _C.balance + _C.goalDelta
  889. else:
  890. msg("Run with botname argument")
  891.  
  892. elif _C.kbd == ord('m'):
  893. if _C.chance > 5 and _C.chance < 95:
  894. _C.chance -= 5
  895. else:
  896. _C.chance -=1
  897. if _C.chance < 0.0001: _C.chance = 0.0001
  898.  
  899. elif _C.kbd == ord('n'):
  900. if _C.chance >= 95 or _C.chance < 5:
  901. _C.chance += 1
  902. else:
  903. _C.chance += 5
  904. if _C.chance > 98.99: _C.chance = 98.99
  905.  
  906. elif _C.kbd == ord('1'):
  907. _C.chance = 5
  908.  
  909. elif _C.kbd == ord('5'):
  910. _C.chance = 50 if _C.chance == 49.5 else 49.5
  911.  
  912. elif _C.kbd == ord('`'):
  913. _C.nextbet = 0.00000001
  914.  
  915. elif _C.kbd == ord('7'):
  916. _C.chance = 70
  917.  
  918. elif _C.kbd == ord('E'):
  919. nextbet = float("{:0.8f}".format(_C.nextbet))
  920. _C.nextbet = float(text_input(nextbet, *(1, 18, _R.manualline.getbegyx()[0], 49)))
  921.  
  922. elif _C.kbd == curses.ascii.ENQ:
  923. _C.chance = float(text_input(_C.chance, *(1, 15, _R.manualline.getbegyx()[0], 34)))
  924.  
  925. elif _C.kbd == ord('l'):
  926. bet(_C.nextbet)
  927.  
  928. elif _C.kbd == ord('o'):
  929. bet(_C.nextbet, chance=_C.chance2)
  930.  
  931. elif _C.kbd == ord('['):
  932. bet(_C.nextbet, -1, chance=_C.chance2)
  933.  
  934. elif _C.kbd == ord(']'):
  935. bet(_C.nextbet, 1, chance=_C.chance2)
  936.  
  937. elif _C.kbd == ord(','):
  938. bet(_C.nextbet, -1)
  939.  
  940. elif _C.kbd == ord('.'):
  941. bet(_C.nextbet, 1)
  942.  
  943. elif _C.kbd == ord('e'):
  944. _C.goal += 0.25
  945. # _C.exitOnMax = False
  946. _C.maxbalance += 0.25
  947. _R.update_status()
  948. elif _C.kbd == ord('r'):
  949. _C.goal -= 0.25
  950. # _C.exitOnMax = False
  951. _C.maxbalance -= 0.25
  952. _R.update_status()
  953.  
  954.  
  955. elif _C.kbd == ord('0'):
  956. _R.print_m_line("testMode is On. Press 'X' to stop")
  957. _C.nextbet = 0.00000004
  958. # _C.nobetdisplay = True
  959. # _C.testMode = True
  960. cred = 100000
  961. start = _C.betcount
  962. while cred > 0 and _C.currentstreak > -7:
  963. bet(_C.nextbet, -1)
  964. cred -= 1
  965. if _C.hitsFlag:
  966. cred = 0;
  967. if _R.w.getch() == ord("X"):
  968. _R.msgregion.addstr("testMode is off\n")
  969. _R.msgregion.refresh()
  970. cred = 0
  971. # _C.nobetdisplay = False
  972. # _C.testMode = False
  973. _R.msgregion.addstr("{:12} ({}) ".format(_C.betcount, _C.betcount-start))
  974. _R.msgregion.addstr("hunt streak {:3} (low)\n".format(_C.currentstreak), curses.color_pair(2))
  975. _R.msgregion.refresh()
  976.  
  977.  
  978. # elif _C.kbd == curses.KEY_MOUSE :
  979. # try:
  980. # pos = curses.getmouse()
  981. # except:
  982. # pos = None
  983. # if pos:
  984. # if pos[2] == _R.manualline.getbegyx()[0] and 16 < pos[1] < 31: # edit chance2 - mouse right click on chance2 in manualline
  985. # _C.chance2 = float(text_input(_C.chance2, *(1, 15, pos[2], 16)))
  986. # if pos[2] == _R.manualline.getbegyx()[0] and 32 < pos[1] < 48: # edit chance - mouse right click on chance in manualline
  987. # _C.chance = float(text_input(_C.chance, *(1, 15, pos[2], 34)))
  988. # if pos[2] == _R.manualline.getbegyx()[0] and 49 < pos[1] < 64: # edit chance - mouse right click on chance in manualline
  989. # nextbet = float("{:0.8f}".format(_C.nextbet))
  990. # _C.nextbet = float(text_input(nextbet, *(1, 18, pos[2], 49)))
  991. else:
  992. if _C.kbd>0:
  993. _R.msgregion.addstr("you pressed {} - Edit your code to make it do something useful\n".format(curses.unctrl(_C.kbd)))
  994. _R.msgregion.refresh()
  995. _C.manualActive = False
  996. _R.clear_m_line()
  997.  
  998. # the print() function for Lua scripts
  999. def msg(s):
  1000. _R.msgregion.addstr("{:12}: ".format(_C.betcount))
  1001. _R.msgregion.addstr("{}\n".format(s), curses.color_pair(2))
  1002. _R.msgregion.refresh()
  1003.  
  1004. def stoplua():
  1005. bailout("\nStop() called\n"+
  1006. "\nBalance: {:13.8f} {}\n\033[0m".format(_C.balance, "CLAM")+
  1007. "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)+
  1008. "\n {} bets done in {} seconds ({:2f} bets/sec) ".format(_C.betcount, _C.seconds,float(_C.betcount/_C.seconds) if _C.seconds else _C.betcount))
  1009. return 1
  1010.  
  1011. def bailout(msg):
  1012. curses.endwin()
  1013. print("\nFATAL ERROR:\n {}\n\n".format(msg))
  1014. # quit()
  1015. sys.exit(9)
  1016.  
  1017.  
  1018. ########################################################
  1019. ########################################################
  1020. def curses_main(w):
  1021. curses.curs_set(0);
  1022. curses.cbreak();
  1023. curses.noecho();
  1024. w.nodelay (True);
  1025. curses.mousemask(curses.BUTTON3_CLICKED)
  1026. w.refresh()
  1027. curses.start_color()
  1028. curses.use_default_colors();
  1029. curses.init_pair (1, curses.COLOR_GREEN, -1);
  1030. curses.init_pair (2, curses.COLOR_YELLOW, -1);
  1031. curses.init_pair (3, curses.COLOR_RED, -1);
  1032. curses.init_pair (4, curses.COLOR_CYAN, -1);
  1033. curses.init_pair (5, curses.COLOR_WHITE, -1);
  1034. curses.init_pair (100, curses.COLOR_GREEN, -1); # the following pairs are for color gradient
  1035. curses.init_pair (99, 48, -1); # on 256 color terminal. TODO: check if colors availble
  1036. curses.init_pair (98, 82, -1);
  1037. curses.init_pair (97,118, -1);
  1038. curses.init_pair (96,154, -1);
  1039. curses.init_pair (95,190, -1);
  1040. curses.init_pair (94,226, -1);
  1041. curses.init_pair (93,220, -1);
  1042. curses.init_pair (92,214, -1);
  1043. curses.init_pair (91,208, -1);
  1044. curses.init_pair (90,202, -1);
  1045. curses.init_pair (89,196, -1);
  1046. curses.init_pair (88,160, -1);
  1047. curses.init_pair (87,124, -1);
  1048. curses.init_pair (86, 88, -1);
  1049.  
  1050. _R.init(w)
  1051. _R.header2.addstr("{}: {}".format(_path, _C.botname))
  1052.  
  1053. _R.w.refresh()
  1054. _R.refresh(["header1", "header2", "stat", "betregion", "msgregion"])
  1055. _R.print_m_line()
  1056.  
  1057.  
  1058. if not login():
  1059. return 0
  1060.  
  1061. _C.WS = websocket.create_connection(f"wss://{server}/socket.io/?EIO=3&transport=websocket&sid={_C.sid}",
  1062. cookie = _C.SessionCookie)
  1063. _C.WS.send('2probe')
  1064. _C.WS.recv()
  1065. _C.WS.send('5')
  1066. _C.WS.recv()
  1067.  
  1068. _C.maxbalance=_C.balance;
  1069. _C.minbalance=_C.balance;
  1070. _C.bstart=_C.balance;
  1071.  
  1072. _R.update_status()
  1073.  
  1074. if _C.goalDelta > 0:
  1075. _C.goal = _C.balance + _C.goalDelta
  1076. if _C.percentualStop > 100:
  1077. _C.percentualStop = 100
  1078. if _C.percentualStop > 0:
  1079. _C.stopamount = _C.balance*_C.percentualStop/100
  1080.  
  1081. _C.kbd = -1
  1082. if _C.manualSession:
  1083. manual_mode();
  1084. else:
  1085. _C.lua = lupa.LuaRuntime()
  1086. try:
  1087. init_lua()
  1088.  
  1089. except Exception as err:
  1090. # _C.kbd = ord("Q")
  1091. # _C.exitReason = f'Lua Exception occured: {err}'
  1092. bailout(err)
  1093.  
  1094. while _C.kbd not in (ord("Q"), ord("D")):
  1095. w.timeout (0)
  1096. _C.kbd = w.getch()
  1097. if _C.kbd > 0 :
  1098. if _C.kbd == ord('h'):
  1099. _C.stopamount *= 110/100
  1100. _C.stopbetting = False
  1101.  
  1102. elif _C.kbd == ord('c'):
  1103. msg("Continue pressed...")
  1104. _C.stopbetting = False
  1105.  
  1106. elif _C.kbd == ord('p'):
  1107. _C.stopbetting = True
  1108. msg("Pause pressed...")
  1109.  
  1110. elif _C.kbd == ord('M'):
  1111. msg("manualMode pressed...")
  1112. manual_mode()
  1113.  
  1114. elif _C.kbd == ord('N'):
  1115. _C.nobetdisplay = not _C.nobetdisplay
  1116. msg(f"nobetdisplay is {'ON' if _C.nobetdisplay else 'OFF'}")
  1117.  
  1118. elif _C.kbd == ord('s'):
  1119. _R.header1.addstr(1, 30, "STOP5 @", curses.color_pair(3) | curses.A_BOLD)
  1120. _C.profitensure = True
  1121.  
  1122. elif _C.kbd == ord('x'):
  1123. _R.header1.addstr(0, 32, "EXIT on MAX balance", curses.color_pair(4) | curses.A_BOLD)
  1124. _C.exitOnMax = True
  1125. # elif _C.kbd == ord(''):
  1126. # elif _C.kbd == ord(''):
  1127.  
  1128. if _C.goal > 0 and _C.balance > _C.goal:
  1129. _C.exitOnMax = True
  1130.  
  1131. if not _C.stopbetting:
  1132. bet(_C.nextbet, _C.side)
  1133. _C.sessionprofit = _C.balance - _C.bstart;
  1134. _C.lua.globals()["balance"] = _C.balance
  1135. _C.lua.globals()["secret"] = _C.secret
  1136. _C.lua.globals()["win"] = _C.win
  1137. _C.lua.globals()["profit"] = _C.sessionprofit
  1138. _C.lua.globals()["currentprofit"] = _C.currentprofit
  1139. _C.lua.globals()["currentstreak"] = _C.currentstreak
  1140. _C.lua.globals()["previousbet"] = _C.nextbet
  1141. _C.lua.globals()["bets"] = _C.betcount
  1142. _C.lua.globals()["wins"] = _C.wincount
  1143. _C.lua.globals()["losses"] = _C.losecount
  1144. _C.lua.globals()["info"] = ""
  1145. _C.lua.globals()["side"] = _C.side
  1146.  
  1147. _C.lua.globals().dobet()
  1148.  
  1149. _C.chance = float(int(_C.lua.globals()["chance"]*100)/100)
  1150. _C.nextbet = _C.lua.globals()["nextbet"]
  1151. _C.basebet = _C.nextbet;
  1152. _C.infoval = _C.lua.globals()["info"]
  1153. _C.side = _C.lua.globals()["side"]
  1154.  
  1155.  
  1156.  
  1157.  
  1158. def print_usage_info() :
  1159. print("call it as: python main.py [options] <name_of_your_lua_file>");
  1160. print("\noptions:");
  1161. print(" -m # start a manual session\n");
  1162.  
  1163.  
  1164.  
  1165. def main(argv):
  1166. """
  1167. The curses.wrapper function is an optional function that
  1168. encapsulates a number of lower-level setup and teardown
  1169. functions, and takes a single function to run when
  1170. the initializations have taken place.
  1171. """
  1172.  
  1173. if len(argv) == 0 :
  1174. print_usage_info()
  1175. #login()
  1176. else :
  1177. try:
  1178. opts, args = getopt.getopt(argv, "mH:h:knNXt:g:G:P:")
  1179. except getopt.GetoptError:
  1180. print_usage_info()
  1181. quit()
  1182. for opt, arg in opts :
  1183. # print("opt - {} arg - {}".format(opt, arg) )
  1184. if opt == "-m":
  1185. _C.manualSession = True
  1186. continue
  1187. elif opt == "-H":
  1188. _C.stopamount = float(arg)
  1189. continue
  1190. elif opt == "-h":
  1191. _C.percentualStop = float(arg)
  1192. continue
  1193. elif opt == "-k":
  1194. _C.keeplogfile = True
  1195. continue
  1196. elif opt == "-n":
  1197. _C.noprofitensure = True
  1198. continue
  1199. elif opt == "-N":
  1200. _C.nobetdisplay = True
  1201. continue
  1202. elif opt == "-t":
  1203. _C.turnlimit = int(arg)
  1204. continue
  1205. elif opt == "-g":
  1206. _C.goal = float(arg)
  1207. continue
  1208. elif opt == "-G":
  1209. _C.goalDelta = float(arg)
  1210. continue
  1211. elif opt == "-P":
  1212. _C.profitensurance = float(arg)
  1213. continue
  1214. else:
  1215. print ("Unknown option {} ({})".format(opt, arg))
  1216. quit()
  1217.  
  1218.  
  1219. if not _C.manualSession:
  1220. if args:
  1221. _C.botname = args[-1]
  1222. else:
  1223. print ("you forgot botname\n")
  1224. print_usage_info()
  1225. quit()
  1226. # quit()
  1227. curses.wrapper(curses_main)
  1228. # curses.curs_set(1)
  1229. curses.endwin()
  1230.  
  1231. _C.WS.close()
  1232.  
  1233. if _C.betcount:
  1234. logfile = open(_path+"/pybot.log", "a")
  1235. line = "{} ".format(int(time.time()))
  1236. line += "won {} of {} bets ({:.2f}%) at {:.2f}% chance, ".format(_C.wincount, _C.betcount,
  1237. float(_C.wincount/_C.betcount*100), _C.chance)
  1238. line += "Balance: {:.8f} {}, ".format(_C.balance, "CLAM")
  1239. line += " bmax: {:.8f} ".format(_C.maxbalance)
  1240. line += " lastmaxmax: {} ".format(_C.lastmaxmax)
  1241. line += " MaxPayIn: {:.8f} ".format(_C.MaxPayIn)
  1242. line += " minstreak: {}, maxstreak: {}, maxdiff: {:.8f}".format(_C.minstreak, _C.maxstreak, _C.maxdiff)
  1243. line += ", {}, ".format(_C.botname)
  1244. line += "{} \n".format(_C.exitReason)
  1245. logfile.write(line)
  1246. logfile.close()
  1247.  
  1248.  
  1249. _C.seconds = int (_C.end - _C.begin)
  1250. print("\n"*(_R.height-30))
  1251. print("\033[1m\n\npybot exit: {}\n".format(_C.exitReason))
  1252. print(" Balance: {:13.8f} {}\n\033[0m".format(_C.balance, "CLAM"))
  1253. print(" Profit: {:13.8f} {} ({:2f}%)\n\033[0m".format(
  1254. _C.balance - _C.bstart,
  1255. "CLAM", float((_C.balance-_C.bstart)*100/_C.bstart) if _C.bstart > 0 else 0))
  1256. print("\n {} bets done in {} seconds ({:2f} bets/sec) ".format(
  1257. _C.betcount, _C.seconds,float(_C.betcount/_C.seconds) if _C.seconds else _C.betcount))
  1258. print(" bmax: {:.8f} ".format(_C.maxbalance))
  1259. print(" MaxPayIn: {:.8f}\n".format(_C.MaxPayIn))
  1260. print(" minstreak: {}, maxstreak: {}, ".format(_C.minstreak, _C.maxstreak))
  1261. print(" maxdiff: {:.8f} \n".format(_C.maxdiff))
  1262. else:
  1263. print("\033[1m\n\npybot exit: {}\n".format(_C.exitReason))
  1264. print("\033[1m\n\npybot exit: no betting :P\n\033[0m")
  1265.  
  1266. if (_C.kbd == ord('D')):
  1267. sys.exit(9)
  1268. main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement