funny commit message

This commit is contained in:
Flummi 2023-07-11 02:13:55 +02:00
parent c6f73395c0
commit 45033a64a3
Signed by: Flummi
GPG Key ID: AA2AEF822A6F4817

View File

@ -20,116 +20,141 @@ const parseCards = msg => {
return output; return output;
}; };
let hand = false; const env = {
let board = false; hand: false,
let winchance = false; board: false,
let called = false; winchance: false,
let joined = false; called: false,
let callphase = true; joined: false,
let callamount = 0; callamount: 0,
let pot = 0; pot: 0,
bank: 0
};
bot.on("message", e => { bot.on("message", e => {
if(e.message === ".me") { if(e.message.match(new RegExp(`^${e.self.me.nickname}: Your bank account`))) {
return e.reply(JSON.stringify(e.self.me)); env.bank = +e.message.match(/is: (\d+) \(/)[1];
} }
if(e.message === ".pj" || e.message === "pj" && !hand && !joined) { if(e.message === ".pj" || e.message === "pj" && !env.hand && !env.joined) {
joined = true; env.joined = true;
return e.reply("pj"); return e.reply("bb\npj");
} }
if(e.message === ".pl" && !hand) { if(e.message === ".pl" && !env.hand) {
joined = false; env.joined = false;
return e.reply("pl"); return e.reply("pl");
} }
if(e.message === ".bb" && !hand) if(e.message === ".bb" && !env.hand)
return e.reply("bb"); return e.reply("bb");
if(e.message === ".bl" && !hand) if(e.message === ".bl" && !env.hand)
return e.reply("bank loan"); return e.reply("bank loan");
if(e.message === ".s" && hand) if(e.message === ".s" && env.hand)
return e.reply("s"); return e.reply("s");
if(e.message === ".f") if(e.message === ".f")
return e.reply("f"); return e.reply("f");
if(e.message === ".d" && !hand) if(e.message === ".d" && !env.hand)
return e.reply("d"); return e.reply("d");
if(e.user.nick !== 'hirc' || !hand) if(e.user.nick !== 'hirc' || !env.hand)
return; return;
if(e.message.match(/(small|big) blind/)) { if(e.message.match(/(small|big) blind/)) {
callamount = +e.message.match(/pays (\d+) \(/)[1]; env.callamount = +e.message.match(/pays (\d+) \(/)[1];
callphase = true; env.pot += env.callamount;
pot += callamount; if(e.message.includes(e.self.me.nickname)) {
console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`); env.bank -= +e.message.match(/pays (\d+) \(/)[1];
} }
if(e.message.match(/raises the pot/)) { console.log(`callamount: ${env.callamount}; potsize: ${env.pot}; winchance: ${env.winchance}`);
callamount = +e.message.match(/pot by (\d+)/)[1]; }
callphase = true; if(e.message.includes('raises the pot')) {
pot += callamount; env.callamount = +e.message.match(/pot by (\d+)/)[1];
console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`); env.pot += env.callamount;
console.log(`callamount: ${env.callamount}; potsize: ${env.pot}; winchance: ${env.winchance}`);
} }
if(e.message.match(/calls \d+\./)) { if(e.message.match(/calls \d+\./)) {
callamount = +e.message.match(/calls (\d+)\./)[1]; env.callamount = +e.message.match(/calls (\d+)\./)[1];
pot += callamount; env.pot += env.callamount;
console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`); console.log(`callamount: ${env.callamount}; potsize: ${env.pot}; winchance: ${env.winchance}`);
} }
if(e.message.match(/check/)) { if(e.message.includes('check')) {
callphase = false; console.log(`callamount: ${env.callamount}; potsize: ${env.pot}; winchance: ${env.winchance}`);
console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`);
} }
if(e.message.match(new RegExp(`^Current player: ${e.self.me.nickname}( |$)`)) && hand) { if(e.message.match(new RegExp(`^Current player: ${e.self.me.nickname}( |$)`)) && env.hand) {
if(!winchance) if(!env.winchance) { // preflop
const callby = +e.message.match(/\((\d+) to call\)/)?.[1] || 0;
if(callby > 0) {
env.bank -= callby;
}
return e.reply('c'); return e.reply('c');
}
if(env.winchance >= 55 && env.callamount) {
if(~~(Math.random() * 2) === 1) {
const raiseby = env.callamount + (~~(Math.random() * 2 + 2) * 10);
env.bank -= raiseby;
return e.reply(`r ${raiseby}`);
}
else {
return e.reply('c');
}
}
if(e.message.includes('to call')) {
if(env.winchance >= 30) {
if(env.called) {
env.bank -= env.callamount;
return e.reply('c');
}
else {
env.called = true;
if(winchance >= 55 && callamount) {
if((~~(Math.random() * 2)) === 1) { if((~~(Math.random() * 2)) === 1) {
return e.reply(`r ${callamount + (~~(Math.random() * 2 + 2) * 10)}`) env.bank -= env.callamount;
return e.reply('c');
} }
else { else {
return e.reply('f');
}
}
}
else {
if((~~Math.random() * 5) === 1) {
return e.reply('f');
}
else {
env.bank -= env.callamount;
return e.reply('c'); return e.reply('c');
} }
} }
}
if(e.message.match(/to call/)) { env.bank -= env.callamount;
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'); return e.reply('c');
} }
if(e.message.match(/Game ended/) || e.message.match(/wins the pot/)) { if(e.message.includes('Game ended') || e.message.includes('wins the pot')) {
//e.reply(`my hand: ${hand.join(', ')} (${winchance}%)`); //e.reply(`my hand: ${hand.join(', ')} (${winchance}%)`);
hand = false; e.reply('my bank balance: ' + env.bank);
board = false; env.hand = false;
winchance = false; env.board = false;
called = false; env.winchance = false;
joined = false; env.called = false;
pot = 0; env.joined = false;
callphase = false; env.pot = 0;
return; return;
} }
if(e.message.match(/^(Flop|Turn|River)/) && e.user.nick === 'hirc') { if(e.message.match(/^(Flop|Turn|River)/) && e.user.nick === 'hirc') {
board = parseCards(e.message); env.board = parseCards(e.message);
console.log(board, hand); console.log(env.board, env.hand);
const rank = rankHands('texas', board, [hand])[0]; const rank = rankHands('texas', env.board, [env.hand])[0];
winchance = (9999 - rank.rank) / 100; env.winchance = (9999 - rank.rank) / 100;
} }
}); });
bot.on("notice", msg => { bot.on("notice", msg => {
if(msg.match(/^Your hand/)) { if(msg.match(/^Your hand/)) {
hand = parseCards(msg); env.hand = parseCards(msg);
} }
}); });