@@ 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 <dice>", "dee, shuf[fle] <A>, <B>, and <C>", and "dee, pick <A>, <B>, or <C>"')
+
+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()