Compare commits

..

3 Commits

Author SHA1 Message Date
4cbdf71f0a
remove dependency 2023-07-15 06:57:19 +02:00
e5ca195346
verbose & debug in console or chat 2023-07-15 06:56:45 +02:00
bc47818a9d
debug verbose level (without trigger lol) 2023-07-15 06:56:15 +02:00
4 changed files with 60 additions and 46 deletions

View File

@ -2,6 +2,7 @@
"bot": { "bot": {
"autojoin": false, "autojoin": false,
"debug": false, "debug": false,
"verbose": 3,
"pokerbot": "hirc", "pokerbot": "hirc",
"channel": "#poker" "channel": "#poker"
}, },

6
package-lock.json generated
View File

@ -12,15 +12,9 @@
], ],
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@xpressit/winning-poker-hand-rank": "^0.1.6",
"cuffeo": "^1.2.2" "cuffeo": "^1.2.2"
} }
}, },
"node_modules/@xpressit/winning-poker-hand-rank": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/@xpressit/winning-poker-hand-rank/-/winning-poker-hand-rank-0.1.6.tgz",
"integrity": "sha512-l7b8GAKOT6k79qKF/SesCgQLvCjHZkhihf5QhgcL9w3hiya2JeCVyg07TVayoyO8PzDq56MH+yKk5rcbDMYScw=="
},
"node_modules/cuffeo": { "node_modules/cuffeo": {
"version": "1.2.2", "version": "1.2.2",
"resolved": "https://registry.npmjs.org/cuffeo/-/cuffeo-1.2.2.tgz", "resolved": "https://registry.npmjs.org/cuffeo/-/cuffeo-1.2.2.tgz",

View File

@ -35,6 +35,18 @@ export default new class {
} }
}; };
debug(msg, level = 2) {
const verbose = this.config.get('verbose');
if(level < verbose)
return;
switch(this.config.get('debug')) {
case 'chat': this.sendMsg(msg); break;
case true:
case 'console': console.log(msg); break;
default: return;
}
};
parseCards(msg, output = []) { parseCards(msg, output = []) {
for(const c of this.stripColors(msg).match(/(\w+)([♠♣️♦♥️️])/g)) for(const c of this.stripColors(msg).match(/(\w+)([♠♣️♦♥️️])/g))
output.push(c.length === 3 ? `T${this.suits[c[2]]}` : `${c[0]}${this.suits[c[1]]}`); output.push(c.length === 3 ? `T${this.suits[c[2]]}` : `${c[0]}${this.suits[c[1]]}`);

View File

@ -20,20 +20,19 @@ export const env = {
bot.on("notice", msg => { bot.on("notice", msg => {
if(msg.match(/^Your hand/)) { if(msg.match(/^Your hand/)) {
env.hand = helper.parseCards(msg); env.hand = helper.parseCards(msg);
if(cfg.get('debug')) helper.debug('hand: ' + env.hand.join(', '));
console.log('hand:', env.hand);
} }
}); });
bot.on("message", async e => { bot.on("message", async e => {
if(e.channel !== cfg.get('channel')) if(e.channel !== cfg.get('channel'))
return; return;
if(e.message.startsWith(".cards ")) { if(e.message.startsWith('.cards ')) {
let cards = []; let cards = [];
try { try {
cards = JSON.parse(e.message.slice(7)); cards = JSON.parse(e.message.slice(7));
} catch(err) { } catch(err) {
return e.reply('das ist kein Array du Pflaumennase'); return e.reply('That is not an array.');
} }
const hand = cards.slice(0, 2); const hand = cards.slice(0, 2);
@ -73,9 +72,13 @@ bot.on("message", async e => {
if(e.message.match(new RegExp(`^${e.self.me.nickname}: Your bank account`))) { if(e.message.match(new RegExp(`^${e.self.me.nickname}: Your bank account`))) {
env.bank = +e.message.match(/is: (\d+) \(/)[1]; env.bank = +e.message.match(/is: (\d+) \(/)[1];
} }
if(e.message === ".debug") { if(e.message.startsWith(".debug")) {
const tmp = await cfg.set('debug', !cfg.get('debug')); const tmp = e.message.match(/\.debug (\w+)/)?.[1];
return e.reply(`debug mode ${tmp ? '[color=green]enabled[/color]' : '[color=red]disabled[/color]'}`); if(!tmp)
return e.reply(`debug mode ${await cfg.set('debug', !cfg.get('debug')) ? '[color=green]enabled[/color]' : '[color=red]disabled[/color]'}`);
if(!['console', 'chat'].includes(tmp))
return e.reply(`debug mode ${await cfg.set('debug', false) ? '[color=green]enabled[/color]' : '[color=red]disabled[/color]'}`);
return e.reply(`debug mode [color=green]enabled[/color] (${await cfg.set('debug', tmp)})`);
} }
if(e.message === ".aj" || e.message === ".autojoin") { if(e.message === ".aj" || e.message === ".autojoin") {
const tmp = await cfg.set('autojoin', !cfg.get('autojoin')); const tmp = await cfg.set('autojoin', !cfg.get('autojoin'));
@ -116,8 +119,7 @@ bot.on("message", async e => {
env.pot += env.callamount; env.pot += env.callamount;
if(e.message.includes(e.self.me.nickname)) { if(e.message.includes(e.self.me.nickname)) {
env.bank -= env.callamount; env.bank -= env.callamount;
if(cfg.get('debug')) helper.debug(`bank: ${env.bank}`);
e.reply(`bank: ${env.bank}`);
} }
return; return;
} }
@ -126,8 +128,7 @@ bot.on("message", async e => {
env.pot += env.callamount; env.pot += env.callamount;
if(e.message.includes(e.self.me.nickname)) { if(e.message.includes(e.self.me.nickname)) {
env.bank -= env.callamount; env.bank -= env.callamount;
if(cfg.get('debug')) helper.debug(`bank: ${env.bank}`);
e.reply(`bank: ${env.bank}`);
} }
return; return;
} }
@ -137,13 +138,12 @@ bot.on("message", async e => {
const oldstate = env.gamestate; const oldstate = env.gamestate;
env.gamestate = 'preflop'; env.gamestate = 'preflop';
if(cfg.get('debug') && oldstate !== env.gamestate) if(oldstate !== env.gamestate)
e.reply(`${oldstate} -> ${env.gamestate}`); helper.debug(`${oldstate} -> ${env.gamestate}`);
if(e.message.includes(e.self.me.nickname)) { if(e.message.includes(e.self.me.nickname)) {
env.bank -= env.callamount; env.bank -= env.callamount;
if(cfg.get('debug')) helper.debug(`bank: ${env.bank}`);
e.reply(`bank: ${env.bank}`);
} }
return; return;
} }
@ -160,57 +160,70 @@ bot.on("message", async e => {
// bot's turn // bot's turn
if(e.message.match(new RegExp(`Current player: ${e.self.me.nickname}( |$)`))) { if(e.message.match(new RegExp(`Current player: ${e.self.me.nickname}( |$)`))) {
let action = 'c'; // default let action = 'c'; // default
let debug = false;
if(env.gamestate === 'preflop' || !env.odds) { // preflop if(env.gamestate === 'preflop' || !env.odds) { // preflop
env.lastaction = action; env.lastaction = action;
helper.debug('preflop, (checkcall) :(', 3);
return e.reply(action); // checkcall return e.reply(action); // checkcall
} }
if(e.message.endsWith('to call)')) { // callphase if(e.message.includes('to call')) { // callphase
env.callamount = +e.message.match(/\((\d+) to call\)/)[1]; env.callamount = +e.message.match(/\((\d+) to call\)/)[1];
if(env.callamount > env.bank) // not enough money lol if(env.callamount > env.bank) // not enough money lol
return e.reply(['huan!', 'f']); return e.reply(['huan!', 'f']);
if(env.odds < 6500) { if(env.odds <= 30) {
if(helper.rand(5) === 1 && env.callamount < (helper.rand(2, 6) * 10)) { // bad hand, call anyway console.log('callphase', env);
action = 'c'; if(helper.rand(20) === 1 && env.callamount < (helper.rand(2, 6) * 10)) { // bad hand, call anyway
action = 'call';
debug = `bad hand, call anyway (${env.odds}, callphase, 5%)`;
} }
else { // bad hand, fold else { // bad hand, fold
action = 'f'; action = 'fold';
debug = `bad hand (${env.odds}, callphase, 95%)`;
} }
} }
else if(env.odds > 55) { // decent hand, raise else if(env.odds > 30 && env.odds <= 50) { // decent hand, raise
if(helper.rand(5) === 1) { // 20% if(helper.rand(10) === 1) { // 10%
action = 'r ' + (env.callamount + helper.rand(5) * 10); action = 'raise ' + (env.callamount + helper.rand(5) * 10);
debug = `decent hand (${env.odds}, callphase, 20%)`;
} }
} }
else if(env.odds > 70) { // good hand lol else if(env.odds > 50 && env.odds <= 70) { // good hand lol
if(helper.rand(2) === 1) { // 50% if(helper.rand(2) === 1) { // 50%
action = 'r ' + (env.callamount + helper.rand(6) * 10); action = 'raise ' + (env.callamount + helper.rand(6) * 10);
debug = `good hand lol (${env.odds}, callphase, 70%)`;
} }
} }
else if(env.odds > 85) { // fuck them all else if(env.odds > 70) { // fuck them all
action = 'r ' + (env.callamount + helper.rand(7) * 10); action = 'raise ' + (env.callamount + helper.rand(7) * 10);
debug = `fuck them all (${env.odds}, callphase)`;
} }
} }
else { // checkphase else { // checkphase
if(env.odds > 55) { // decend hand, raise console.log('checkphase', env);
if(env.odds > 55 && env.odds <= 70) { // decend hand, raise
if(helper.rand(5) === 1) { // 20% if(helper.rand(5) === 1) { // 20%
action = 'r ' + (env.callamount + helper.rand(5) * 10); action = 'raise ' + (env.callamount + helper.rand(5) * 10);
debug = `decent hand (${env.odds}, checkphase, 20%)`;
} }
} }
else if(env.odds > 70) { // good hand lol else if(env.odds > 70 && env.odds <= 85) { // good hand lol
if(helper.rand(2) === 1) { // 50% if(helper.rand(2) === 1) { // 50%
action = 'r ' + (env.callamount + helper.rand(6) * 10); action = 'r ' + (env.callamount + helper.rand(6) * 10);
debug = `good hand lol (${env.odds}, callphase, 50%)`;
} }
} }
else if(env.odds > 85) { // fuck them all else if(env.odds > 85) { // fuck them all
action = 'r ' + (env.callamount + helper.rand(7) * 10); action = 'raise ' + (env.callamount + helper.rand(7) * 10);
debug = `fuck them all (${env.odds}, callphase)`;
} }
} }
if(action) { if(action) {
env.lastaction = action; env.lastaction = action;
helper.debug(debug ? debug : 'check lol', 3);
return e.reply(action); return e.reply(action);
} }
} }
@ -221,8 +234,7 @@ bot.on("message", async e => {
const oldstate = env.gamestate; const oldstate = env.gamestate;
env.gamestate = e.message.match(/(\w+): /)[1].toLowerCase(); env.gamestate = e.message.match(/(\w+): /)[1].toLowerCase();
if(cfg.get('debug')) helper.debug(`${oldstate} -> ${env.gamestate}`, 2);
e.reply(`${oldstate} -> ${env.gamestate}`);
const rank = handranker.rankHands(env.board, env.hand); const rank = handranker.rankHands(env.board, env.hand);
env.odds = rank.percentage; env.odds = rank.percentage;
@ -239,14 +251,12 @@ bot.on("message", async e => {
env.bank += +e.message.match(/pot(: | of size )(\d+)/)[2]; env.bank += +e.message.match(/pot(: | of size )(\d+)/)[2];
} }
if(cfg.get('debug')) helper.debug(`bank: ${env.bank}`);
e.reply(`bank: ${env.bank}`);
} }
const oldstate = env.gamestate; const oldstate = env.gamestate;
env.gamestate = 'not started, ' + (cfg.get('autojoin') ? 'autojoin' : 'no autojoin'); env.gamestate = 'not started, ' + (cfg.get('autojoin') ? 'autojoin' : 'no autojoin');
if(cfg.get('debug')) helper.debug(`${oldstate} -> ${env.gamestate}`, 2);
e.reply(`${oldstate} -> ${env.gamestate}`);
env.hand = false; env.hand = false;
env.board = false; env.board = false;
@ -256,7 +266,4 @@ bot.on("message", async e => {
env.lastaction = false; env.lastaction = false;
return; return;
} }
if(cfg.get('debug'))
console.log(env);
}); });