Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: decisionbot.py

Issue 29337738: Issue 3703 - Add "coin flip" feature to abpbot (Closed)
Patch Set: Addressed feedback Created Feb. 25, 2016, 8:28 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « abpbot.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 """
2 Decisionbot - A simple IRC bot to help make "coin flip" decisions.
3
4 botname: x or y?
5 => x
6
7 botname: a or b or c?
8 => b
9 """
10 import random
Sebastian Noack 2016/02/25 20:47:53 Nit: Please add an empty line between the docstrin
kzar 2016/02/25 20:52:40 Done.
11 import re
12
13 from irclib import nm_to_n
14
15
16 class Decisionbot():
17 def __init__(self, config, queue):
18 self.queue = queue
19
20 nickname = config.get("main", "nickname")
21 self.question_regexp = re.compile("^%s:?(.+\s+or\s+.+)\?+\s*$" %
Sebastian Noack 2016/02/25 20:47:53 I just realized that you don't use r"" strings. Bu
kzar 2016/02/25 20:52:40 Done.
22 re.escape(nickname), re.IGNORECASE)
23 self.question_delim_regexp = re.compile("\s+or\s+", re.IGNORECASE)
24
25 def on_pubmsg(self, connection, event):
26 channel = event.target()
27 message = event.arguments()[0]
28 sender = nm_to_n(event.source())
29
30 match = self.question_regexp.search(message)
31 if (match):
32 choices = self.question_delim_regexp.split(match.group(1).strip("? \t"))
33 if len(choices) > 1:
34 self.say_public(channel, "%s: %s" % (sender, random.choice(choices)))
35
36 def say_public(self, channel, text):
37 self.queue.send(text, channel)
OLDNEW
« no previous file with comments | « abpbot.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld