funny commit message
This commit is contained in:
parent
c6f73395c0
commit
45033a64a3
143
src/index.mjs
143
src/index.mjs
|
@ -20,116 +20,141 @@ const parseCards = msg => {
|
|||
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;
|
||||
const env = {
|
||||
hand: false,
|
||||
board: false,
|
||||
winchance: false,
|
||||
called: false,
|
||||
joined: false,
|
||||
callamount: 0,
|
||||
pot: 0,
|
||||
bank: 0
|
||||
};
|
||||
|
||||
bot.on("message", e => {
|
||||
if(e.message === ".me") {
|
||||
return e.reply(JSON.stringify(e.self.me));
|
||||
if(e.message.match(new RegExp(`^${e.self.me.nickname}: Your bank account`))) {
|
||||
env.bank = +e.message.match(/is: (\d+) \(/)[1];
|
||||
}
|
||||
if(e.message === ".pj" || e.message === "pj" && !hand && !joined) {
|
||||
joined = true;
|
||||
return e.reply("pj");
|
||||
if(e.message === ".pj" || e.message === "pj" && !env.hand && !env.joined) {
|
||||
env.joined = true;
|
||||
return e.reply("bb\npj");
|
||||
}
|
||||
if(e.message === ".pl" && !hand) {
|
||||
joined = false;
|
||||
if(e.message === ".pl" && !env.hand) {
|
||||
env.joined = false;
|
||||
return e.reply("pl");
|
||||
}
|
||||
if(e.message === ".bb" && !hand)
|
||||
if(e.message === ".bb" && !env.hand)
|
||||
return e.reply("bb");
|
||||
if(e.message === ".bl" && !hand)
|
||||
if(e.message === ".bl" && !env.hand)
|
||||
return e.reply("bank loan");
|
||||
if(e.message === ".s" && hand)
|
||||
if(e.message === ".s" && env.hand)
|
||||
return e.reply("s");
|
||||
if(e.message === ".f")
|
||||
return e.reply("f");
|
||||
if(e.message === ".d" && !hand)
|
||||
if(e.message === ".d" && !env.hand)
|
||||
return e.reply("d");
|
||||
|
||||
if(e.user.nick !== 'hirc' || !hand)
|
||||
if(e.user.nick !== 'hirc' || !env.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}`);
|
||||
env.callamount = +e.message.match(/pays (\d+) \(/)[1];
|
||||
env.pot += env.callamount;
|
||||
if(e.message.includes(e.self.me.nickname)) {
|
||||
env.bank -= +e.message.match(/pays (\d+) \(/)[1];
|
||||
}
|
||||
console.log(`callamount: ${env.callamount}; potsize: ${env.pot}; winchance: ${env.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.includes('raises the pot')) {
|
||||
env.callamount = +e.message.match(/pot by (\d+)/)[1];
|
||||
env.pot += env.callamount;
|
||||
console.log(`callamount: ${env.callamount}; potsize: ${env.pot}; winchance: ${env.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}`);
|
||||
env.callamount = +e.message.match(/calls (\d+)\./)[1];
|
||||
env.pot += env.callamount;
|
||||
console.log(`callamount: ${env.callamount}; potsize: ${env.pot}; winchance: ${env.winchance}`);
|
||||
}
|
||||
if(e.message.match(/check/)) {
|
||||
callphase = false;
|
||||
console.log(`callphase: ${callphase ? 'yes': 'no'}; callamount: ${callamount}; potsize: ${pot}; winchance: ${winchance}`);
|
||||
if(e.message.includes('check')) {
|
||||
console.log(`callamount: ${env.callamount}; potsize: ${env.pot}; winchance: ${env.winchance}`);
|
||||
}
|
||||
|
||||
if(e.message.match(new RegExp(`^Current player: ${e.self.me.nickname}( |$)`)) && hand) {
|
||||
if(!winchance)
|
||||
if(e.message.match(new RegExp(`^Current player: ${e.self.me.nickname}( |$)`)) && env.hand) {
|
||||
if(!env.winchance) { // preflop
|
||||
const callby = +e.message.match(/\((\d+) to call\)/)?.[1] || 0;
|
||||
if(callby > 0) {
|
||||
env.bank -= callby;
|
||||
}
|
||||
return e.reply('c');
|
||||
}
|
||||
|
||||
if(winchance >= 55 && callamount) {
|
||||
if((~~(Math.random() * 2)) === 1) {
|
||||
return e.reply(`r ${callamount + (~~(Math.random() * 2 + 2) * 10)}`)
|
||||
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.match(/to call/)) {
|
||||
if(winchance >= 30) {
|
||||
if(called)
|
||||
if(e.message.includes('to call')) {
|
||||
if(env.winchance >= 30) {
|
||||
if(env.called) {
|
||||
env.bank -= env.callamount;
|
||||
return e.reply('c');
|
||||
}
|
||||
else {
|
||||
called = true;
|
||||
return e.reply( (~~(Math.random() * 2)) === 1 ? 'c' : 'f' );
|
||||
env.called = true;
|
||||
|
||||
if((~~(Math.random() * 2)) === 1) {
|
||||
env.bank -= env.callamount;
|
||||
return e.reply('c');
|
||||
}
|
||||
else {
|
||||
return e.reply('f');
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return e.reply(((~~Math.random() * 5) === 1) ? 'f' : 'c');
|
||||
if((~~Math.random() * 5) === 1) {
|
||||
return e.reply('f');
|
||||
}
|
||||
else {
|
||||
env.bank -= env.callamount;
|
||||
return e.reply('c');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
env.bank -= env.callamount;
|
||||
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}%)`);
|
||||
hand = false;
|
||||
board = false;
|
||||
winchance = false;
|
||||
called = false;
|
||||
joined = false;
|
||||
pot = 0;
|
||||
callphase = false;
|
||||
e.reply('my bank balance: ' + env.bank);
|
||||
env.hand = false;
|
||||
env.board = false;
|
||||
env.winchance = false;
|
||||
env.called = false;
|
||||
env.joined = false;
|
||||
env.pot = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
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];
|
||||
winchance = (9999 - rank.rank) / 100;
|
||||
const rank = rankHands('texas', env.board, [env.hand])[0];
|
||||
env.winchance = (9999 - rank.rank) / 100;
|
||||
}
|
||||
});
|
||||
|
||||
bot.on("notice", msg => {
|
||||
if(msg.match(/^Your hand/)) {
|
||||
hand = parseCards(msg);
|
||||
env.hand = parseCards(msg);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user