muh
This commit is contained in:
parent
839452d394
commit
f3fbf27a69
110
src/index.mjs
110
src/index.mjs
@ -1,10 +1,11 @@
|
||||
import cuffeo from 'cuffeo';
|
||||
import { rankHands } from '@xpressit/winning-poker-hand-rank';
|
||||
import handranker from './inc/handranker.mjs';
|
||||
import cfg from '../config.json' assert { type: 'json' };
|
||||
|
||||
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, '');
|
||||
|
||||
@ -12,68 +13,77 @@ const parseCards = msg => {
|
||||
const output = [];
|
||||
for(const c of stripColors(msg).match(/(\w+)([♠♣️♦♥️️])/g)) {
|
||||
if(c.length === 3)
|
||||
output.push(`T${g_suits[c[2]]}`);
|
||||
output.push(`T${suits[c[2]]}`);
|
||||
else
|
||||
output.push(`${c[0]}${g_suits[c[1]]}`);
|
||||
output.push(`${c[0]}${suits[c[1]]}`);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
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;
|
||||
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" && !g_hand && !g_joined) {
|
||||
g_joined = true;
|
||||
if(e.message === ".me") {
|
||||
return e.reply(JSON.stringify(e.self.me));
|
||||
}
|
||||
if(e.message === ".pj" || e.message === "pj" && !hand && !joined) {
|
||||
joined = true;
|
||||
return e.reply("pj");
|
||||
}
|
||||
if(e.message === ".pl" && !g_hand)
|
||||
if(e.message === ".pl" && !hand) {
|
||||
joined = false;
|
||||
return e.reply("pl");
|
||||
if(e.message === ".bb" && !g_hand)
|
||||
}
|
||||
if(e.message === ".bb" && !hand)
|
||||
return e.reply("bb");
|
||||
if(e.message === ".bl" && !g_hand)
|
||||
if(e.message === ".bl" && !hand)
|
||||
return e.reply("bank loan");
|
||||
if(e.message === ".s" && g_hand)
|
||||
if(e.message === ".s" && hand)
|
||||
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;
|
||||
|
||||
if(e.message.match(/(small|big) blind/)) {
|
||||
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}`);
|
||||
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/)) {
|
||||
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}`);
|
||||
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+\./)) {
|
||||
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}`);
|
||||
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/)) {
|
||||
g_callphase = false;
|
||||
console.log(`callphase: ${g_callphase ? 'yes': 'no'}; callamount: ${g_callamount}; potsize: ${g_pot}; winchance: ${g_winchance}`);
|
||||
callphase = false;
|
||||
console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`);
|
||||
}
|
||||
|
||||
if(e.message.startsWith("Current player: schmirc") && g_hand) {
|
||||
if(!g_winchance)
|
||||
if(e.message.match(new RegExp(`^Current player: ${e.self.me.nickname} \(`)) && hand) {
|
||||
if(!winchance)
|
||||
return e.reply('c');
|
||||
|
||||
if(g_winchance >= 55 && g_callamount) {
|
||||
if(winchance >= 55 && callamount) {
|
||||
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 {
|
||||
return e.reply('c');
|
||||
@ -81,11 +91,11 @@ bot.on("message", e => {
|
||||
}
|
||||
|
||||
if(e.message.match(/to call/)) {
|
||||
if(g_winchance >= 30) {
|
||||
if(g_called)
|
||||
if(winchance >= 30) {
|
||||
if(called)
|
||||
return e.reply('c');
|
||||
else {
|
||||
g_called = true;
|
||||
called = true;
|
||||
return e.reply( (~~(Math.random() * 2)) === 1 ? 'c' : 'f' );
|
||||
}
|
||||
}
|
||||
@ -97,24 +107,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: ${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;
|
||||
//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') {
|
||||
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];
|
||||
g_winchance = (9999 - rank.rank) / 100;
|
||||
const rank = rankHands('texas', board, [hand])[0];
|
||||
winchance = (9999 - rank.rank) / 100;
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user