Advertisement
coinwalk

need nodejs help

Jun 4th, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.42 KB | None | 0 0
  1. #!/usr/bin/env node
  2.  
  3. // run it like this:
  4. //
  5. // JDBOT_USERNAME=bolux JDBOT_PASSWORD=future2000 node jdbot.js
  6. //
  7. // or like this:
  8. //
  9. // JDBOT_HASH=096af33d16104d4d72db4026fc76471372183c132be8acac9aa03176af68ffc3 node jdbot.js
  10. //
  11. // and include a JDBOT_CODE=123456 at the start if you need 2FA to log in
  12.  
  13. var request = require('request');
  14. var url = "https://just-dice.com";
  15. var transport = 'websocket'; // Replace 'websocket' with the desired transport mechanism
  16. var cookie = 'hash=096af33d16104d4d72db4026fc76471372183c132be8acac9aa03176af68ffc3; connect.sid=s%3A6p2Au_V3ZKg2S45GOThxbkrd.9fBLOhWaMPNob9bXsWz5Q0BD7lwIyB0Fqy3cehAZo%2BA';
  17.  
  18. var socket = require('socket.io-client')(url, { transports: [transport], extraHeaders: { origin: url, cookie: cookie } });
  19.  
  20. // my local test instance doesn't have an SSL certificate
  21. if (process.env.JDBOT_TESTING == '1') {
  22. url = "https://test.com";
  23. process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
  24. }
  25.  
  26. // EITHER (A) call login_then_run_bot() with your 64 character hash:
  27. login_then_run_bot({hash: process.env.JDBOT_HASH,
  28. username: process.env.JDBOT_USERNAME,
  29. password: process.env.JDBOT_PASSWORD,
  30. code: process.env.JDBOT_CODE
  31. });
  32.  
  33. // OR (B) as a shortcut, call run_bot() with your full hash+sid cookie (as shown when you use login_then_run_bot()) to skip the login step:
  34. // cookie = 'hash=096af33d16104d4d72db4026fc76471372183c132be8acac9aa03176af68ffc3; connect.sid=s%3A6p2Au_V3ZKg2S45GOThxbkrd.9fBLOhWaMPNob9bXsWz5Q0BD7lwIyB0Fqy3cehAZo%2BA';
  35. // run_bot(cookie);
  36.  
  37. var version = '0.1.5',
  38. socket,
  39. csrf,
  40. uid,
  41. balance,
  42. max_profit,
  43. base, factor, steps, martingale = false, martingale_delay = 10,
  44. flatbet_seconds, flatbet_count,
  45. bet_in_progress,
  46. chance = '49.5',
  47. stake = '0',
  48. hilo = 'hi',
  49. bet_stake_threshold = 1,
  50. bet_profit_threshold = 1,
  51. show_all_my_bets = true,
  52. user_profit = {};
  53.  
  54. function init_readline() {
  55. var readline = require('readline').createInterface({
  56. input: process.stdin, output: process.stdout, terminal: false
  57. });
  58.  
  59. readline.on('line', handle_command);
  60.  
  61. readline.on('close', function() {
  62. console.log('Have a great day!');
  63. process.exit(0);
  64. });
  65. }
  66.  
  67. var last_command;
  68. function handle_command(txt) {
  69. // hit return to repeat last line
  70. if (txt === '') {
  71. if (last_command)
  72. return handle_command(last_command);
  73. txt = '.help';
  74. }
  75.  
  76. last_command = txt;
  77.  
  78. if (!socket) {
  79. console.log('not connected');
  80. return;
  81. }
  82.  
  83. // lines that don't begin with a dot are sent as if entered in the chat box
  84. if (!txt.match(/^[.]/)) {
  85. socket.emit('chat', csrf, txt);
  86. return;
  87. }
  88.  
  89. txt = txt.substring(1);
  90.  
  91. // split command into array of words
  92. txt = txt.split(/\s+/);
  93.  
  94. try {
  95. switch (txt[0]) {
  96.  
  97. case 'b':
  98. case 'bet':
  99. bet(stake, chance, hilo);
  100. break;
  101.  
  102. case 'c':
  103. case 'chance':
  104. validate_number(txt[1]);
  105. chance = tidy(txt[1], 4);
  106. console.log('set chance to', chance + '%');
  107. break;
  108.  
  109. case 'd':
  110. case 'deposit':
  111. socket.emit('deposit', csrf);
  112. break;
  113.  
  114. case 'f':
  115. case 'flat':
  116. case 'flatbet':
  117. // .flatbet <seconds>
  118. validate_integer(txt[1]); flatbet_seconds = parseInt(txt[1]);
  119.  
  120. console.log('flat betting stake', stake, 'chance', chance, 'for', flatbet_seconds, 'seconds');
  121. flatbet_count = 0;
  122. bet(stake, chance, hilo);
  123.  
  124. setTimeout(function() {
  125. console.log('flat betting timeout; made', flatbet_count, 'bets in', flatbet_seconds, 'seconds; ', flatbet_count/flatbet_seconds, 'bets per second');
  126. flatbet_seconds = 0;
  127. }, flatbet_seconds * 1000);
  128.  
  129. break;
  130.  
  131. case 'h':
  132. case 'hi':
  133. case 'high':
  134. hilo = 'hi';
  135. console.log('set hi/lo to hi');
  136. break;
  137.  
  138. case 'l':
  139. case 'lo':
  140. case 'low':
  141. hilo = 'lo';
  142. console.log('set hi/lo to lo');
  143. break;
  144.  
  145. case 'login':
  146. validate_string(txt[1]);
  147. validate_string(txt[2]);
  148. console.log('attempting to log in <username> <password> [2FA code]');
  149. socket.emit('login', csrf, txt[1], txt[2], txt[3]);
  150. break;
  151.  
  152. case 'm':
  153. case 'martin':
  154. case 'martingale':
  155. // .martingale <base> <factor> <steps>
  156. validate_number(txt[1]); base = parseFloat(txt[1]);
  157. validate_number(txt[2]); factor = parseFloat(txt[2]);
  158. validate_integer(txt[3]); steps = parseInt(txt[3]);
  159.  
  160. console.log('martingaling from base', txt[1] + ', multiplying by', txt[2], 'on loss, and making', txt[3], 'bets');
  161. martingale = true;
  162. steps--;
  163. bet(stake = base, chance, hilo);
  164. break;
  165.  
  166. case 'n':
  167. case 'name':
  168. validate_string(txt[1]);
  169. console.log('attempting to change name to "' + txt[1] + '"');
  170. socket.emit('name', csrf, txt[1]);
  171. break;
  172.  
  173. case 'passwd':
  174. validate_string(txt[1]);
  175. validate_string(txt[2]);
  176. console.log('attempting to change password <from> <to>');
  177. socket.emit('change_password', csrf, txt[1], txt[2]);
  178. break;
  179.  
  180. case 'p':
  181. case 'payout':
  182. validate_number(txt[1]);
  183. chance = tidy(99 / txt[1], 4);
  184. console.log('set chance to', chance + '%');
  185. break;
  186.  
  187. case 's':
  188. case 'stake':
  189. validate_number(txt[1]);
  190. stake = tidy(txt[1], 8);
  191. console.log('set stake to', stake);
  192. break;
  193.  
  194. case 't':
  195. case 'tog':
  196. case 'toggle':
  197. hilo = 'tog';
  198. console.log('set hi/lo to toggle');
  199. break;
  200.  
  201. case 'userpass':
  202. validate_string(txt[1]);
  203. validate_string(txt[2]);
  204. console.log('attempting to set username to "' + txt[1] + '"');
  205. socket.emit('setup_account', csrf, txt[1], txt[2]);
  206. break;
  207.  
  208. case 'w':
  209. case 'wd':
  210. case 'withdraw':
  211. validate_address(txt[1]);
  212. validate_number(txt[2]);
  213. console.log('withdrawing', txt[2], 'to', txt[1]);
  214. socket.emit('withdraw', csrf, txt[1], txt[2], txt[3]);
  215. break;
  216.  
  217. case '?':
  218. case 'help':
  219. show_help();
  220. break;
  221.  
  222. default:
  223. console.log('unknown command;', txt[0]);
  224. break;
  225. }
  226. } catch (err) {
  227. console.log(err);
  228. }
  229. }
  230.  
  231. function validate_address(addr) {
  232. if (addr === undefined)
  233. throw new Error("missing required address");
  234.  
  235. if (!addr.match(/^x[1-9a-km-zA-HJ-NP-Z]{33}$/))
  236. throw new Error("invalid CLAM address");
  237. }
  238.  
  239. function validate_integer(num) {
  240. if (num === undefined)
  241. throw new Error("missing required integer");
  242.  
  243. if (!num.match(/^[1-9][0-9]*$/))
  244. throw new Error("number should have nothing other than digits in it");
  245. }
  246.  
  247. function validate_number(num) {
  248. if (num === undefined)
  249. throw new Error("missing required number");
  250.  
  251. if (!num.match(/[0-9]/))
  252. throw new Error("number should have some digits in it");
  253.  
  254. if (num.match(/[.].*[.]/))
  255. throw new Error("number should have no more than one dot in it");
  256.  
  257. if (!num.match(/^[0-9.]*$/))
  258. throw new Error("number should have nothing other than digits and dots in it");
  259. }
  260.  
  261. function validate_string(str) {
  262. if (str === undefined)
  263. throw new Error("missing required string");
  264. }
  265.  
  266. function show_news(news) {
  267. console.log('NEWS:', news);
  268. }
  269.  
  270. function show_help() {
  271. console.log('type to chat, or (.b)et, (.c)hance, (.d)eposit, (.f)latbet, (.h)i, (.l)o, (.m)artingale (.n)ame (.p)ayout, (.s)take, (.t)oggle (.w)ithdraw (.help)');
  272. console.log('hit return on its own to repeat last line');
  273. }
  274.  
  275. function tidy(val, fixed)
  276. {
  277. if (fixed === undefined)
  278. fixed=8;
  279.  
  280. if (typeof(val) == 'number')
  281. val = val.toFixed(fixed);
  282.  
  283. val = val.replace(/([.].*?)0+$/, '$1'); // remove trailing zeroes after the decimal point
  284. val = val.replace(/[.]$/, ''); // remove trailing decimal point
  285. return val;
  286. }
  287.  
  288. var last_hilo;
  289.  
  290. function bet(stake, chance, hilo) {
  291. if (bet_in_progress) {
  292. console.log('you have a bet in progress already');
  293. return;
  294. }
  295.  
  296. // if we're toggling, toggle
  297. if (hilo == 'tog') {
  298. if (last_hilo == 'hi')
  299. last_hilo = 'lo';
  300. else
  301. last_hilo = 'hi';
  302. } else
  303. // else just remember what we bet in case we toggle next time
  304. last_hilo = hilo;
  305.  
  306. console.log('BET:', stake, '@', tidy(chance, 4) + '%', last_hilo);
  307. bet_in_progress = true;
  308. socket.emit('bet', csrf, {chance: tidy(chance, 4), bet: stake, which: last_hilo});
  309. }
  310.  
  311. function login_then_run_bot(credentials) {
  312. login(credentials, function(err, cookie) {
  313. if (err) {
  314. console.log('ERROR:', err);
  315. return;
  316. }
  317.  
  318. console.log('logged in; got cookie (secret - do not share!):');
  319. console.log(cookie);
  320. run_bot(cookie);
  321. });
  322. }
  323.  
  324. function login(credentials, cb) {
  325. var jar = request.jar();
  326.  
  327. req = {url: url, jar: jar, form: {}}
  328.  
  329. if (credentials.hash) {
  330. if (credentials.username || credentials.password)
  331. return cb('either specify a hash or a username and password');
  332. jar.setCookie(request.cookie('hash=' + credentials.hash), url);
  333. }
  334.  
  335. if (credentials.username) req.form.username = credentials.username;
  336. if (credentials.password) req.form.password = credentials.password;
  337. if (credentials.code) req.form.code = credentials.code;
  338.  
  339. request.post(req, function(err, res, body) {
  340. if (err)
  341. return cb(err);
  342.  
  343. // console.log(body);
  344.  
  345. if (body.match(/Please enter your 6 digit google authentification number/))
  346. return cb('that account requires a correct 2FA code and hash to log in; 2FA codes can only be used once each');
  347.  
  348. if (body.match(/Your account is set up to require a google authentification code for this action/))
  349. return cb('that account requires a 2FA code in addition to the username and password to log in');
  350.  
  351. if (body.match(/Please enter your username/))
  352. return cb('that account requires a correct username and password, and possibly 2FA code; 2FA codes can only be used once each');
  353.  
  354. var cookie = jar.getCookieString(url);
  355.  
  356. if (!cookie.match(/hash=/))
  357. return cb('bad hash');
  358.  
  359. return cb(null, cookie);
  360. });
  361. }
  362.  
  363. var first_login = true;
  364.  
  365. function run_bot(cookie) {
  366. if (first_login) {
  367. init_readline();
  368. first_login = false;
  369. }
  370.  
  371. show_help();
  372.  
  373. var transport = 'websocket';
  374. // var transport = 'polling';
  375.  
  376. var inits = 0;
  377.  
  378. socket = require("socket.io-client")(url, {transports: [transport],
  379. extraHeaders: {
  380. origin: url,
  381. cookie: cookie
  382. }});
  383.  
  384. socket.on('getver', function(key) {
  385. socket.emit('version', csrf, key, "jdbot:" + version);
  386. });
  387.  
  388. socket.on('error', function(err) {
  389. console.log('caught error:', err);
  390. });
  391.  
  392. socket.on('news', function(news) {
  393. show_news(news);
  394. });
  395.  
  396. socket.on('staked', function(dat) {
  397. var ourstake = dat.stake_pft ? '; your share = ' + tidy(dat.stake_share) + '; your total = ' + tidy(dat.stake_pft) + '' : '';
  398. console.log('STAKED: we just staked', tidy(dat.stake), '(total =', tidy(dat.total) + ourstake + ')');
  399. });
  400.  
  401. socket.on('tip', function(from, name, amount, comment, ignored) {
  402. // only show tips if we didn't ignore the sender
  403. if (!ignored)
  404. console.log('TIP: you received', amount, 'from (' + from + ') <' + name + '>' + (comment ? ' [' + comment + ']' : ''));
  405. });
  406.  
  407. socket.on('init', function(data) {
  408. uid = data.uid;
  409. if (!inits++) {
  410. // only do this stuff the first time we connect, not on reconnection
  411.  
  412. // data is something like this:
  413. //
  414. // { api: 0,
  415. // balance: '988.00000000',
  416. // bankroll: '500215.49619137',
  417. // bet: 0.5,
  418. // bets: '2474',
  419. // chance: 33,
  420. // chat:
  421. // [ '{"user":"1243","name":"tammie","txt":"chat text 1"}',
  422. // '1437445872584',
  423. // '{"user":"1","name":"@derpy","txt":"etc."}',
  424. // '1437452160715',
  425. // '{"user":"1","name":"@derpy","txt":"etc.}',
  426. // '1437452172081' ],
  427. // csrf: 'f68wiCdKcdf6',
  428. // edge: 1,
  429. // fee: 0.001,
  430. // ga: { active: false, failures: 0, last: '327860', ok: 1437123260013 },
  431. // ignores: [],
  432. // investment: 500181.4929641858,
  433. // invest_pft: 181.49296418577433,
  434. // login: '<p>You can log into the same account from a different computer or browser using <a href="/e47004523222720bdf835f741505f7acd9d7ead728893b65fd4ac59b07a33a20">this link</a>.<br/>Protect this secret link as it can be used to access your account balance.</p><p>If you prefer to use a more traditional and secure approach then<button id="setup_account">set up a username and password</button>.</p>',
  435. // losses: '1305',
  436. // luck: '96.28%',
  437. // max_profit: '130001.07',
  438. // name: 'dooglus',
  439. // news: 'no news is set',
  440. // nonce: '477',
  441. // offsite: 25500000,
  442. // percent: 99.99986921944092,
  443. // profit: '-108.01000000',
  444. // seed: '770695475991960934442523',
  445. // settings:
  446. // { max_bet: 1,
  447. // chat_watch_player: null,
  448. // alert_words: 'dooglus',
  449. // alert: 1,
  450. // hilite: 1,
  451. // pmding: 1,
  452. // chat_min_risk: 1,
  453. // chat_min_change: 1,
  454. // styleme: 1 },
  455. // shash: 'bf7feb2c04020f94262d9f01fa62fa4ce527e58f357372969ccb46c2ab85d3ed',
  456. // stake_pft: 98.6989727076143,
  457. // uid: '1',
  458. // username: null,
  459. // wagered: '2295.81000000',
  460. // wins: '1169',
  461. // stats:
  462. // { bets: '3315',
  463. // wins: 1542,
  464. // losses: 1773,
  465. // luck: 3217.2707228742447,
  466. // wagered: 2824.9700003,
  467. // profit: -94.09198439,
  468. // commission: 22.264911885550614,
  469. // taken: 0,
  470. // purse: 26000215.49619137,
  471. // cold: 25500000,
  472. // balance: 60827.14134891,
  473. // sum1: 561042.63754028,
  474. // sum2: 561064.90245217 },
  475. // wdaddr: '' }
  476.  
  477. csrf = data.csrf;
  478. balance = data.balance;
  479. max_profit = data.max_profit;
  480. console.log('connected as (' + uid + ') <' + data.name + '>');
  481. show_news(data.news);
  482. // console.log('csrf is', csrf);
  483. } else {
  484. console.log('reconnected');
  485. // console.log('csrf was', csrf, 'and now is', data.csrf);
  486. csrf = data.csrf;
  487. }
  488. });
  489.  
  490. socket.on('set_hash', function(hash) {
  491. console.log('INFO:', 'server requested that we reconnect...');
  492. socket.close();
  493. run_bot(cookie);
  494. });
  495.  
  496. socket.on('chat', function(txt, date) {
  497. console.log('CHAT:', txt);
  498. });
  499.  
  500. // this triggers for every bet the server tells us about; they're not all ours
  501. socket.on('result', function(result) {
  502. // result is something like this:
  503. //
  504. // { bankroll: '500227.64420698',
  505. // bet: '1',
  506. // betid: 2409,
  507. // bets: '2177',
  508. // chance: '49.5',
  509. // date: 1437439984,
  510. // high: true,
  511. // luck: '96.37%',
  512. // lucky: 750994,
  513. // max_profit: '130001.13',
  514. // name: 'derpy (1)',
  515. // nonce: 180,
  516. // payout: 2,
  517. // ret: '2',
  518. // this_profit: '+1',
  519. // uid: '1',
  520. // wagered: '2194.01000000',
  521. // win: true,
  522. // stats:
  523. // { bets: 2409,
  524. // wins: 1158,
  525. // losses: 1251,
  526. // luck: 2338.4848484848394,
  527. // wagered: 2243.84,
  528. // profit: -106.24,
  529. // commission: 22.264911885550614,
  530. // taken: 0,
  531. // purse: 26000227.64420698,
  532. // cold: 25500000,
  533. // balance: 60814.9933333,
  534. // sum1: 561042.63754028,
  535. // sum2: 561064.90245217 },
  536. // investment: 500193.64096390456,
  537. // percent: 99.99986921944092,
  538. // invest_pft: 193.6409639045596,
  539. // balance: '989.70000000',
  540. // profit: '-106.31000000' }
  541.  
  542. var this_profit = parseFloat(result.this_profit);
  543.  
  544. if (user_profit[result.uid] === undefined)
  545. user_profit[result.uid] = 0;
  546.  
  547. user_profit[result.uid] += this_profit;
  548. if ((show_all_my_bets && result.uid == uid) || this_profit >= bet_profit_threshold || result.bet >= bet_stake_threshold)
  549. console.log('RESULT:', result.name,
  550. '[betid', result.betid + ',',
  551. 'bets', result.bets + ',',
  552. 'nonce', result.nonce + ']',
  553. 'bet', result.bet,
  554. 'on', result.high ? 'hi' : 'lo',
  555. 'at', result.chance + '%',
  556. 'and', result.win ? 'won;' : 'lost;',
  557. 'profit', result.this_profit,
  558. 'cumulative profit', tidy(user_profit[result.uid]));
  559.  
  560. if (result.balance !== undefined)
  561. console.log('BALANCE:', result.balance);
  562.  
  563. max_profit = result.max_profit;
  564. if (result.uid == uid) {
  565. // console.log("that's me!");
  566. balance = result.balance;
  567. }
  568. });
  569.  
  570. socket.on('address', function(addr, img, confs) {
  571. console.log('DEPOSIT:', addr);
  572. });
  573.  
  574. socket.on('invest_error', function(txt) {
  575. console.log('ERROR:', txt);
  576. });
  577.  
  578. socket.on('divest_error', function(txt) {
  579. console.log('ERROR:', txt);
  580. });
  581.  
  582. socket.on('jderror', function(txt) {
  583. console.log('ERROR:', txt);
  584. });
  585.  
  586. socket.on('jdmsg', function(txt) {
  587. console.log('INFO:', txt);
  588. });
  589.  
  590. socket.on('form_error', function(txt) {
  591. console.log('FORM ERROR:', txt);
  592. });
  593.  
  594. socket.on('login_error', function(txt) {
  595. console.log('LOGIN ERROR:', txt);
  596. });
  597.  
  598. socket.on('balance', function(data) {
  599. let balance = data;
  600. console.log('BALANCE:', balance);
  601. });
  602.  
  603. socket.on('max_profit', function(mp) {
  604. max_profit = mp;
  605. console.log('MAX PROFIT:', max_profit);
  606. });
  607.  
  608. socket.on('disconnect', function() {
  609. console.log('disconnected');
  610. });
  611. }
  612. let crazy = balance;
  613. let old = balance;
  614. let score = balance;
  615. let lol = balance;
  616. let bird = balance;
  617. let arnie = bird / 1440000;
  618. let james = arnie;
  619. let jim = arnie;
  620. let jly = 0;
  621. let future = 0;
  622. let madman = james;
  623. let kool = balance;
  624. let have = balance;
  625. let junky = balance;
  626.  
  627. function xiggie() {
  628. let fart = balance;
  629. if (fart < crazy && future <= 3) {
  630. future += 1;
  631. jim += arnie;
  632. jly = tidy(old - fart);
  633. james = tidy(jly + jim - arnie);
  634. madman = james;
  635. lol = fart;
  636. crazy = fart;
  637. }
  638.  
  639. if (fart < crazy && future > 3 && fart < score) {
  640. future += 1;
  641. james = madman;
  642. crazy = fart;
  643. }
  644.  
  645. if (fart > crazy && fart < score) {
  646. james = madman;
  647. crazy = fart;
  648. }
  649.  
  650. if (future > 3 && fart < lol - james * 1.9) {
  651. james += james;
  652. madman = james;
  653. lol = fart;
  654. }
  655.  
  656. if (fart >= score) {
  657. arnie = fart / 1440000;
  658. jim = arnie;
  659. james = arnie;
  660. jly = 0;
  661. future = 0;
  662. old = fart;
  663. lol = fart;
  664. crazy = fart;
  665. madman = james;
  666. score = fart;
  667. }
  668. return james;
  669. }
  670. function go() {
  671. stake = xiggie();
  672. chance = 49.5;
  673. hilo = 'lo'
  674. bet(stake, chance, hilo);
  675. setTimeout(() => go(), 100);
  676. }
  677. go();
  678.  
  679.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement