From 0ba1aa3623d11e460b058c37e2bebca36e50e8a2 Mon Sep 17 00:00:00 2001 From: Stefan Krulj Date: Thu, 10 Jan 2013 01:17:24 +0100 Subject: [PATCH] Game of boggle added; Newline bug for monospaced messages fixed --- modules/active/boggle.py | 51 ++++++++++++++++++++++++++++++++++++++++ sys/brathuhn.py | 4 +++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 modules/active/boggle.py diff --git a/modules/active/boggle.py b/modules/active/boggle.py new file mode 100644 index 0000000..1e24c20 --- /dev/null +++ b/modules/active/boggle.py @@ -0,0 +1,51 @@ +import brathuhn, random, time + +DICE = [['A','A','A','F','R', 'S']] +DICE.append(['A','A','E','E','E','E']) +DICE.append(['A','A','F','I','R','S']) +DICE.append(['A','D','E','N','N','N']) +DICE.append(['A','E','E','E','E','M']) + +DICE.append(['A','E','E','G','M','U']) +DICE.append(['A','E','G','M','N','N']) +DICE.append(['A','F','I','R','S','Y']) +DICE.append(['B','J','K','Qu','X','Z']) +DICE.append(['C','C','E','N','S','T']) + +DICE.append(['C','E','I','I','L','T']) +DICE.append(['C','E','I','P','S','T']) +DICE.append(['C','E','I','L','P','T']) +DICE.append(['D','D','H','N','O','T']) +DICE.append(['D','H','H','L','O','R']) + +DICE.append(['D','H','L','N','O','R']) +DICE.append(['D','H','L','N','O','R']) +DICE.append(['E','I','I','I','T','T']) +DICE.append(['E','M','O','T','T','T']) +DICE.append(['E','N','S','S','S','U']) + +DICE.append(['F','I','P','R','S','Y']) +DICE.append(['G','O','R','R','V','W']) +DICE.append(['I','P','R','R','R','Y']) +DICE.append(['N','O','O','T','U','W']) +DICE.append(['O','O','O','T','T','U']) + +def timesup(a): + brathuhn.sendMsg(brathuhn.ROOM,"Time's up!",'groupchat') + +def boggle(msg,args): + if len(args)==1: + mymsg = "" + random.shuffle(DICE) + i = 0 + for d in DICE: + if i % 5 == 0: + mymsg += "\n" + i+=1 + mymsg += "%3s" % ( d[random.randint(0,5)] ) + brathuhn.sendMonoMsg(brathuhn.ROOM,mymsg,'groupchat') + brathuhn.sendMsg(brathuhn.ROOM,"you have 3 minutes",'groupchat') + brathuhn.callAt(timesup, time.time()+60*3, [1]) + else: + brathuhn.sendMsg(brathuhn.ROOM,"Usage: !boggle",'groupchat') +brathuhn.addCommand("boggle","Usage: !boggle",boggle) diff --git a/sys/brathuhn.py b/sys/brathuhn.py index 4debe05..34e55c4 100644 --- a/sys/brathuhn.py +++ b/sys/brathuhn.py @@ -116,7 +116,9 @@ def sendMonoMsg(to,body,mtype=None): c=mymsg.addChild('html', namespace='http://jabber.org/protocol/xhtml-im') c=c.addChild('body',namespace='http://www.w3.org/1999/xhtml') c=c.addChild('span', attrs={'style':'font-family: Courier New, monospace;'}) - c=c.addChild('pre',payload=body,attrs={'style':'background-color: #ffffff;'}) + for part in body.split('\n'): + c=c.addChild('pre',payload=part,attrs={'style':'background-color: #ffffff;'}) + c=c.addChild('br') cl.send(mymsg) def __help(msg,args):