This commit is contained in:
Flummi 2023-07-11 00:48:32 +02:00
parent 839452d394
commit f3fbf27a69
Signed by: Flummi
GPG Key ID: AA2AEF822A6F4817

View File

@ -1,10 +1,11 @@
import cuffeo from 'cuffeo'; import cuffeo from 'cuffeo';
import { rankHands } from '@xpressit/winning-poker-hand-rank'; import { rankHands } from '@xpressit/winning-poker-hand-rank';
import handranker from './inc/handranker.mjs';
import cfg from '../config.json' assert { type: 'json' }; import cfg from '../config.json' assert { type: 'json' };
const bot = await new cuffeo(cfg.clients); const bot = await new cuffeo(cfg.clients);
const g_suits = { "♠": "S", "♣": "C", "♦": "D", "♥": "H" }; const suits = { "♠": "S", "♣": "C", "♦": "D", "♥": "H" };
const stripColors = msg => msg.replace(/\x03\d{0,2}(,\d{0,2}|\x02\x02)?/g, ''); const stripColors = msg => msg.replace(/\x03\d{0,2}(,\d{0,2}|\x02\x02)?/g, '');
@ -12,68 +13,77 @@ const parseCards = msg => {
const output = []; const output = [];
for(const c of stripColors(msg).match(/(\w+)([♠♣️♦♥️️])/g)) { for(const c of stripColors(msg).match(/(\w+)([♠♣️♦♥️️])/g)) {
if(c.length === 3) if(c.length === 3)
output.push(`T${g_suits[c[2]]}`); output.push(`T${suits[c[2]]}`);
else else
output.push(`${c[0]}${g_suits[c[1]]}`); output.push(`${c[0]}${suits[c[1]]}`);
} }
return output; return output;
}; };
let g_hand = false; let hand = false;
let g_board = false; let board = false;
let g_winchance = false; let winchance = false;
let g_called = false; let called = false;
let g_joined = false; let joined = false;
let g_callphase = true; let callphase = true;
let g_callamount = 0; let callamount = 0;
let g_pot = 0; let pot = 0;
bot.on("message", e => { bot.on("message", e => {
if(e.message === ".pj" || e.message === "pj" && !g_hand && !g_joined) { if(e.message === ".me") {
g_joined = true; return e.reply(JSON.stringify(e.self.me));
}
if(e.message === ".pj" || e.message === "pj" && !hand && !joined) {
joined = true;
return e.reply("pj"); return e.reply("pj");
} }
if(e.message === ".pl" && !g_hand) if(e.message === ".pl" && !hand) {
joined = false;
return e.reply("pl"); return e.reply("pl");
if(e.message === ".bb" && !g_hand) }
if(e.message === ".bb" && !hand)
return e.reply("bb"); return e.reply("bb");
if(e.message === ".bl" && !g_hand) if(e.message === ".bl" && !hand)
return e.reply("bank loan"); return e.reply("bank loan");
if(e.message === ".s" && g_hand) if(e.message === ".s" && hand)
return e.reply("s"); return e.reply("s");
if(e.message === ".f" && hand)
return e.reply("f");
if(e.message === ".d" && hand)
return e.reply("d");
if(e.user.nick !== 'hirc' || !g_hand) if(e.user.nick !== 'hirc' || !hand)
return; return;
if(e.message.match(/(small|big) blind/)) { if(e.message.match(/(small|big) blind/)) {
g_callamount = +e.message.match(/pays (\d+) \(/)[1]; callamount = +e.message.match(/pays (\d+) \(/)[1];
g_callphase = true; callphase = true;
g_pot += g_callamount; pot += callamount;
console.log(`callphase: ${g_callphase ? 'yes': 'no'}; callamount: ${g_callamount}; potsize: ${g_pot}; winchance: ${g_winchance}`); console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`);
} }
if(e.message.match(/raises the pot/)) { if(e.message.match(/raises the pot/)) {
g_callamount = +e.message.match(/pot by (\d+)/)[1]; callamount = +e.message.match(/pot by (\d+)/)[1];
g_callphase = true; callphase = true;
g_pot += g_callamount; pot += callamount;
console.log(`callphase: ${g_callphase ? 'yes': 'no'}; callamount: ${g_callamount}; potsize: ${g_pot}; winchance: ${g_winchance}`); console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`);
} }
if(e.message.match(/calls \d+\./)) { if(e.message.match(/calls \d+\./)) {
g_callamount = +e.message.match(/calls (\d+)\./)[1]; callamount = +e.message.match(/calls (\d+)\./)[1];
g_pot += g_callamount; pot += callamount;
console.log(`callphase: ${g_callphase ? 'yes': 'no'}; callamount: ${g_callamount}; potsize: ${g_pot}; winchance: ${g_winchance}`); console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`);
} }
if(e.message.match(/check/)) { if(e.message.match(/check/)) {
g_callphase = false; callphase = false;
console.log(`callphase: ${g_callphase ? 'yes': 'no'}; callamount: ${g_callamount}; potsize: ${g_pot}; winchance: ${g_winchance}`); console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`);
} }
if(e.message.startsWith("Current player: schmirc") && g_hand) { if(e.message.match(new RegExp(`^Current player: ${e.self.me.nickname} \(`)) && hand) {
if(!g_winchance) if(!winchance)
return e.reply('c'); return e.reply('c');
if(g_winchance >= 55 && g_callamount) { if(winchance >= 55 && callamount) {
if((~~(Math.random() * 2)) === 1) { if((~~(Math.random() * 2)) === 1) {
return e.reply(`r ${g_callamount + (~~(Math.random() * 2 + 2) * 10)}`) return e.reply(`r ${callamount + (~~(Math.random() * 2 + 2) * 10)}`)
} }
else { else {
return e.reply('c'); return e.reply('c');
@ -81,11 +91,11 @@ bot.on("message", e => {
} }
if(e.message.match(/to call/)) { if(e.message.match(/to call/)) {
if(g_winchance >= 30) { if(winchance >= 30) {
if(g_called) if(called)
return e.reply('c'); return e.reply('c');
else { else {
g_called = true; called = true;
return e.reply( (~~(Math.random() * 2)) === 1 ? 'c' : 'f' ); return e.reply( (~~(Math.random() * 2)) === 1 ? 'c' : 'f' );
} }
} }
@ -97,24 +107,24 @@ bot.on("message", e => {
return e.reply('c'); return e.reply('c');
} }
if(e.message.match(/Game ended/) || e.message.match(/wins the pot/)) { if(e.message.match(/Game ended/) || e.message.match(/wins the pot/)) {
//e.reply(`my hand: ${g_hand.join(', ')} (${g_winchance}%)`); //e.reply(`my hand: ${hand.join(', ')} (${winchance}%)`);
g_hand = false; hand = false;
g_board = false; board = false;
g_winchance = false; winchance = false;
g_called = false; called = false;
g_joined = false; joined = false;
g_pot = 0; pot = 0;
g_callphase = false; callphase = false;
return; return;
} }
if(e.message.match(/^(Flop|Turn|River)/) && e.user.nick === 'hirc') { if(e.message.match(/^(Flop|Turn|River)/) && e.user.nick === 'hirc') {
g_board = parseCards(e.message); board = parseCards(e.message);
console.log(g_board, g_hand); console.log(board, hand);
const rank = rankHands('texas', g_board, [g_hand])[0]; const rank = rankHands('texas', board, [hand])[0];
g_winchance = (9999 - rank.rank) / 100; winchance = (9999 - rank.rank) / 100;
} }
}); });