From f3c6bdff1cb82d333d850e85d6b06783416da386 Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 10 Jul 2023 19:50:31 +0200 Subject: [PATCH] first commit --- .gitignore | 2 + package-lock.json | 35 +++++++++++++ package.json | 15 ++++++ src/index.mjs | 125 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+) create mode 100644 .gitignore create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/index.mjs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..36420af --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +config.json \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..e168b6d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,35 @@ +{ + "name": "schmirc", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "schmirc", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@xpressit/winning-poker-hand-rank": "^0.1.6", + "cuffeo": "^1.2.2" + } + }, + "node_modules/@xpressit/winning-poker-hand-rank": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/@xpressit/winning-poker-hand-rank/-/winning-poker-hand-rank-0.1.6.tgz", + "integrity": "sha512-l7b8GAKOT6k79qKF/SesCgQLvCjHZkhihf5QhgcL9w3hiya2JeCVyg07TVayoyO8PzDq56MH+yKk5rcbDMYScw==" + }, + "node_modules/cuffeo": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cuffeo/-/cuffeo-1.2.2.tgz", + "integrity": "sha512-Pd2AL/Zp5RCAbaSbT7rLUOyxSEVCFovihaIaje7uYzpQMzIwPbFapQ/mn2d2iz+Tbkjs9LF+FD5JzAvANh9Wzw==", + "dependencies": { + "flumm-fetch": "^1.0.1" + } + }, + "node_modules/flumm-fetch": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/flumm-fetch/-/flumm-fetch-1.0.1.tgz", + "integrity": "sha512-pZ5U0hheCSW43vfGZQMunr03U7rUOX+iy2y13Tu4nc3iRL+E/Qfeo5nZ2B2JMYKOGIx1A1anUYOz+ulyhouyjg==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..0cec7ca --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "schmirc", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "node ./src/index.mjs" + }, + "author": "Flummi", + "license": "ISC", + "dependencies": { + "@xpressit/winning-poker-hand-rank": "^0.1.6", + "cuffeo": "^1.2.2" + } +} diff --git a/src/index.mjs b/src/index.mjs new file mode 100644 index 0000000..f6c0268 --- /dev/null +++ b/src/index.mjs @@ -0,0 +1,125 @@ +import cuffeo from 'cuffeo'; +import { rankHands } from '@xpressit/winning-poker-hand-rank'; +import cfg from '../config.json' assert { type: 'json' }; + +const bot = await new cuffeo(cfg.clients); + +const g_cards = { "♠": "S", "♣": "C", "♦": "D", "♥": "H" }; + +const stripColors = msg => msg.replace(/\x03\d{0,2}(,\d{0,2}|\x02\x02)?/g, ''); + +const parseCards = msg => { + const output = []; + for(const c of stripColors(msg).match(/(\w+)([♠♣️♦♥️️])/g)) { + if(c.length === 3) + output.push(`T${g_cards[c[2]]}`); + else + output.push(`${c[0]}${g_cards[c[1]]}`); + } + 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; + +bot.on("message", e => { + if(e.message === ".pj" || e.message === "pj" && !hand && !joined) { + joined = true; + return e.reply("pj"); + } + if(e.message === ".pl" && !hand) + return e.reply("pl"); + if(e.message === ".bb" && !hand) + return e.reply("bb"); + if(e.message === ".bl" && !hand) + return e.reply("bank loan"); + if(e.message === ".s" && hand) + return e.reply("s"); + + if(e.user.nick !== 'hirc' || !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}`); + } + 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}`); + } + 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}`); + } + if(e.message.match(/check/)) { + callphase = false; + console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`); + } + + if(e.message.startsWith("Current player: schmirc") && hand) { + if(!winchance) + return e.reply('c'); + + if(winchance >= 55 && callamount) { + if((~~(Math.random() * 2)) === 1) { + return e.reply(`r ${callamount + (~~(Math.random() * 2 + 2) * 10)}`) + } + else { + return e.reply('c'); + } + } + + if(e.message.match(/to call/)) { + if(winchance >= 30) { + if(called) + return e.reply('c'); + else { + called = true; + return e.reply( (~~(Math.random() * 2)) === 1 ? 'c' : 'f' ); + } + } + else { + return e.reply(((~~Math.random() * 5) === 1) ? 'f' : 'c'); + } + } + + 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; + return; + } + + if(e.message.match(/^(Flop|Turn|River)/) && e.user.nick === 'hirc') { + board = parseCards(e.message); + + console.log(board, hand); + + const rank = rankHands('texas', board, [hand])[0]; + winchance = (9999 - rank.rank) / 100; + } +}); + +bot.on("notice", msg => { + if(msg.match(/^Your hand/)) { + hand = parseCards(msg); + } +});