From b9b06524b09f10f0a413f911665f45f7ff88866d Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Mon, 27 Oct 2025 18:34:30 -0400 Subject: [PATCH] fixes --- botlib.py | 2 +- dee.py | 83 ++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/botlib.py b/botlib.py index 62efa15445071ffa146aeb7aee15c446f967c9b0..5b3bc4c55870f27d137398415aac082e91e0f158 100755 --- a/botlib.py +++ b/botlib.py @@ -29,7 +29,7 @@ def split_list(words, pwords): if len(acc) == 0 and pwords[i] in ('and', 'or'): continue if words[i][-1] == ',': - acc.append(words[i].lstrip(',')) + acc.append(words[i].rstrip(',')) terms.append(acc) acc = [] else: diff --git a/dee.py b/dee.py index 5c346199fe85972c2e73916c1a3b724cb597f964..80b483c1f234d0664f8805b17d62118bfe2bfd74 100755 --- a/dee.py +++ b/dee.py @@ -2,7 +2,7 @@ import botlib from time import sleep -from random import randint +from random import randint, choice, shuffle import re from copy import copy @@ -14,6 +14,52 @@ def send(msg): global NAME botlib.send(f'{NAME}: {msg}') +def help(nick): + send(f'{nick}, my commands are: "dee, roll ", "dee, shuf[fle] , , and ", and "dee, pick , , or "') + +def handle_msg(nick, line, words, pwords): + global NAME + + print(nick, line, words, pwords) + + if not botlib.strip_direct_address(NAME, [], words, pwords): + return + + cmd = pwords[0] + pwords.pop(0) + words.pop(0) + + if cmd == 'help': + help(nick) + elif len(pwords) < 1: + send(f'{nick}, {cmd} what?') + elif cmd == 'roll': + dice(nick, words, pwords) + elif cmd == 'pick': + pick(nick, words, pwords) + elif cmd in ('shuf', 'shuffle'): + shuf(nick, words, pwords) + else: + send(f'{nick}, I would, if I knew how!') + +def handle_action(line, words, pwords): + pass + + +### CHOICES, CHOICES ### + +def pick(nick, words, pwords): + terms = botlib.split_list(words, pwords) + picked = choice(terms) + send(f'{nick}, how about {" ".join(picked)}?') + +def shuf(nick, words, pwords): + terms = botlib.split_list(words, pwords) + shuffle(terms) + send(f'{nick}: {", ".join(map(" ".join, terms))}') + + +### DICE ### class DiceParseException(Exception): pass @@ -34,8 +80,6 @@ offset = op num op = 'plus' | 'minus' | '+' | '-' num = int() or human-readable number - - ''' last_dice = 6 @@ -88,13 +132,13 @@ def parse_dice(nick, words): if len(words) == 0: return count, last_dice, 0 - if words[0] in ('plus', 'add', 'minus', 'sub', 'subtract'): + if words[0] in ('plus', 'add', '+', 'minus', 'sub', 'subtract', '-'): try: offset = parse_number(words[1]) except (IndexError, ValueError): raise DiceParseException(f'{words[0]} what?') - if words[0] not in ('plus', 'add'): + if words[0] not in ('plus', 'add', '+'): offset *= -1 return count, last_dice, offset @@ -147,6 +191,9 @@ def dice(nick, words, pwords): if count > 1 or offset != '': result += f'{offset} = {rollsum}' + + if size == 0: + result += ', obviously' if result == nick: send(f'{nick}, done, i guess') @@ -156,32 +203,6 @@ def dice(nick, words, pwords): send(f'{nick}, roll them yourself!') -def handle_msg(nick, line, words, pwords): - global NAME - - print(nick, line, words, pwords) - - if not botlib.strip_direct_address(NAME, [], words, pwords): - return - - cmd = pwords[0] - pwords.pop(0) - words.pop(0) - - if len(pwords) < 1: - send(f'{nick}, {cmd} what?') - elif cmd == 'roll': - dice(nick, words, pwords) - elif cmd == 'pick': - return - pick(nick, words, pwords) - elif cmd in ('shuf', 'shuffle'): - return - shuf(nick, words, pwords) - -def handle_action(line): - pass - ### BOOT ### botlib.parse_args()