From 686d72e1a2ea6c70fc287d9af5ce0bba956c8dae Mon Sep 17 00:00:00 2001 From: Juhani Haverinen Date: Tue, 1 Apr 2014 22:25:16 +0300 Subject: [PATCH] Add #TdX dice notation --- botcmd.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/botcmd.py b/botcmd.py index b39321f..57eb96f 100644 --- a/botcmd.py +++ b/botcmd.py @@ -1,6 +1,7 @@ import eliza import threading import random +import re concmd=['/q','/lt','/st','/lg'] @@ -16,6 +17,8 @@ authcmdlock=threading.Lock() authfuncs={} authfunclock=threading.Lock() +die_expr=re.compile("#[0-9]*d([0-9]+|%)") + msglock.acquire() f=open('msgs.txt','r') for line in f: @@ -173,6 +176,19 @@ def parse((line,irc)): irc.send('PRIVMSG %s :Nothing here'%chan) elif line[3][1:] in ('oonbotti:', 'oonbotti', 'oonbotti,', 'oonbotti2', 'oonbotti2:', 'oonbotti2,'): irc.send('PRIVMSG %s :%s: %s'%(chan,nick,doctor.respond(' '.join(line[4:])))) + elif die_expr.match(line[3][1:]): + die=line[3][2:].split('d') + times=int(die[0]) if die[0] else 1 + die=100 if die[1]=='%' else int(die[1]) + if die<4 and times<1: + irc.send('PRIVMSG %s :Dice are limited to physically possible ones'%chan) + else: + rolls=[random.randint(1, die) for i in xrange(times)] + result=reduce((lambda x,y:x+y), rolls) + if times>1: + irc.send('PRIVMSG %s :%s (%s)'%(chan, str(result), ', '.join([str(i) for i in rolls]))) + else: + irc.send('PRIVMSG %s :%s'%(chan, str(result))) elif line[1]=='NOTICE' and line[0].split('!')[0]==':NickServ' and line[4]=='ACC': authfunclock.acquire() authcmdlock.acquire()