From 839452d394179686b14536e2f500ba7f896f189c Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 10 Jul 2023 20:14:00 +0200 Subject: [PATCH] global schmobal --- src/index.mjs | 94 +++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/src/index.mjs b/src/index.mjs index e4f7bb5..85ab582 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -19,61 +19,61 @@ const parseCards = msg => { return output; }; -let hand = false; -let board = false; -let winchance = false; -let called = false; -let joined = false; -let callphase = true; -let callamount = 0; -let pot = 0; +let g_hand = false; +let g_board = false; +let g_winchance = false; +let g_called = false; +let g_joined = false; +let g_callphase = true; +let g_callamount = 0; +let g_pot = 0; bot.on("message", e => { - if(e.message === ".pj" || e.message === "pj" && !hand && !joined) { - joined = true; + if(e.message === ".pj" || e.message === "pj" && !g_hand && !g_joined) { + g_joined = true; return e.reply("pj"); } - if(e.message === ".pl" && !hand) + if(e.message === ".pl" && !g_hand) return e.reply("pl"); - if(e.message === ".bb" && !hand) + if(e.message === ".bb" && !g_hand) return e.reply("bb"); - if(e.message === ".bl" && !hand) + if(e.message === ".bl" && !g_hand) return e.reply("bank loan"); - if(e.message === ".s" && hand) + if(e.message === ".s" && g_hand) return e.reply("s"); - if(e.user.nick !== 'hirc' || !hand) + if(e.user.nick !== 'hirc' || !g_hand) return; if(e.message.match(/(small|big) blind/)) { - callamount = +e.message.match(/pays (\d+) \(/)[1]; - callphase = true; - pot += callamount; - console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`); + g_callamount = +e.message.match(/pays (\d+) \(/)[1]; + g_callphase = true; + g_pot += g_callamount; + console.log(`callphase: ${g_callphase ? 'yes': 'no'}; callamount: ${g_callamount}; potsize: ${g_pot}; winchance: ${g_winchance}`); } if(e.message.match(/raises the pot/)) { - callamount = +e.message.match(/pot by (\d+)/)[1]; - callphase = true; - pot += callamount; - console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`); + g_callamount = +e.message.match(/pot by (\d+)/)[1]; + g_callphase = true; + g_pot += g_callamount; + console.log(`callphase: ${g_callphase ? 'yes': 'no'}; callamount: ${g_callamount}; potsize: ${g_pot}; winchance: ${g_winchance}`); } if(e.message.match(/calls \d+\./)) { - callamount = +e.message.match(/calls (\d+)\./)[1]; - pot += callamount; - console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`); + g_callamount = +e.message.match(/calls (\d+)\./)[1]; + g_pot += g_callamount; + console.log(`callphase: ${g_callphase ? 'yes': 'no'}; callamount: ${g_callamount}; potsize: ${g_pot}; winchance: ${g_winchance}`); } if(e.message.match(/check/)) { - callphase = false; - console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`); + g_callphase = false; + console.log(`callphase: ${g_callphase ? 'yes': 'no'}; callamount: ${g_callamount}; potsize: ${g_pot}; winchance: ${g_winchance}`); } - if(e.message.startsWith("Current player: schmirc") && hand) { - if(!winchance) + if(e.message.startsWith("Current player: schmirc") && g_hand) { + if(!g_winchance) return e.reply('c'); - if(winchance >= 55 && callamount) { + if(g_winchance >= 55 && g_callamount) { if((~~(Math.random() * 2)) === 1) { - return e.reply(`r ${callamount + (~~(Math.random() * 2 + 2) * 10)}`) + return e.reply(`r ${g_callamount + (~~(Math.random() * 2 + 2) * 10)}`) } else { return e.reply('c'); @@ -81,11 +81,11 @@ bot.on("message", e => { } if(e.message.match(/to call/)) { - if(winchance >= 30) { - if(called) + if(g_winchance >= 30) { + if(g_called) return e.reply('c'); else { - called = true; + g_called = true; return e.reply( (~~(Math.random() * 2)) === 1 ? 'c' : 'f' ); } } @@ -97,24 +97,24 @@ bot.on("message", e => { return e.reply('c'); } if(e.message.match(/Game ended/) || e.message.match(/wins the pot/)) { - //e.reply(`my hand: ${hand.join(', ')} (${winchance}%)`); - hand = false; - board = false; - winchance = false; - called = false; - joined = false; - pot = 0; - callphase = false; + //e.reply(`my hand: ${g_hand.join(', ')} (${g_winchance}%)`); + g_hand = false; + g_board = false; + g_winchance = false; + g_called = false; + g_joined = false; + g_pot = 0; + g_callphase = false; return; } if(e.message.match(/^(Flop|Turn|River)/) && e.user.nick === 'hirc') { - board = parseCards(e.message); + g_board = parseCards(e.message); - console.log(board, hand); + console.log(g_board, g_hand); - const rank = rankHands('texas', board, [hand])[0]; - winchance = (9999 - rank.rank) / 100; + const rank = rankHands('texas', g_board, [g_hand])[0]; + g_winchance = (9999 - rank.rank) / 100; } });