first commit

This commit is contained in:
2023-07-10 19:50:31 +02:00
parent 3709188485
commit f3c6bdff1c
4 changed files with 177 additions and 0 deletions

125
src/index.mjs Normal file
View File

@ -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);
}
});