verbose & debug in console or chat

This commit is contained in:
Flummi 2023-07-15 06:56:45 +02:00
parent bc47818a9d
commit e5ca195346
Signed by: Flummi
GPG Key ID: AA2AEF822A6F4817
2 changed files with 59 additions and 40 deletions

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 = []) {
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]]}`);

View File

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