Merge lp:~mgorven/ibid/regex-factoids-397725 into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Michael Gorven
Status: Rejected
Rejected by: Jonathan Hitchcock
Proposed branch: lp:~mgorven/ibid/regex-factoids-397725
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: None lines
To merge this branch: bzr merge lp:~mgorven/ibid/regex-factoids-397725
Reviewer Review Type Date Requested Status
Stefano Rivera Needs Fixing
Review via email: mp+8987@code.launchpad.net

This proposal supersedes a proposal from 2009-07-15.

To post a comment you must log in.
Revision history for this message
Michael Gorven (mgorven) wrote : Posted in a previous version of this proposal

This isn't actually ready to go in, but I'd like comments on the approach. The
only thing which isn't currently handled is using the bot's names in the
regexes.

Revision history for this message
Stefano Rivera (stefanor) wrote : Posted in a previous version of this proposal

Not looking bad:
* You should use re.I|re.DOTALL, as some sources produce multi-line input
* I'd {pre,suf}fix r'\b' to the matches
* Some responses just don't make sense:
Query: who created you?
Response: hithere
^ Firstly, that's an invalid response, second I read it as "hit here"

Would you like a pile of clueless user logs?

Revision history for this message
Stefano Rivera (stefanor) wrote : Posted in a previous version of this proposal

Query: bad bot
Response: sorry, baas

I'm not happy with having "sorry baas" in there, too contentious.

Query: yo there
Response: buongiorno

"buon giorno" is two words. In fact all the two-word contractions should be expanded for the response and ' ' replaced with r'\s*' in the regex.

Other oddities:

Query: morning
Response: hey
Query: afternoon
Response: Excuse me?
Query: 'day
Response: Sorry...
Query: g'day
Response: *blink*
Query: goodday
Response: hello

Query: you rock
Response: stefanor: thankyou!
Query: you are so cool
INFO:plugins.factoid:Creating factoid 1 with name 'you' by 1
INFO:plugins.factoid:Added value 'are so cool' to factoid 1 (you) by None/1 (stefanor)
Response: Done
Response: I already know stuff about you
Query: you're so cool
Response: *blink*

review: Needs Fixing
Revision history for this message
Stefano Rivera (stefanor) wrote : Posted in a previous version of this proposal

> Query: morning
> Response: hey

Query: evening
Response: Huh?

Query: how goes?
Response: Huh?
Query: how's life?
Response: *blink*
Query: how do you do?
INFO:plugins.factoid:Creating factoid 2 with name 'how' by 1
INFO:plugins.factoid:Added value 'do you do?' to factoid 2 (how) by None/1 (stefanor)
Response: Alrighty
Query: how are you?
Response: I already know stuff about how

Obviously you don't have to fix *all* of these :)

Revision history for this message
Stefano Rivera (stefanor) wrote :

Some of the things this tries to do (such as "you are so cool", which I've seen in the wild quite a bit) get caught by normal factoid.

See my review on the previous proposal

review: Needs Fixing
Revision history for this message
Stefano Rivera (stefanor) wrote :

Another problem:
12:26 < tumbleweed> tibid: thanks
12:26 < tibid> tumbleweed: tumbleweed: np

Unmerged revisions

721. By Michael Gorven

Add some greetings and remove inappropriate response.

720. By Michael Gorven

Remove $nick since it doesn't work.

719. By Michael Gorven

Use Unicode strings.

718. By Michael Gorven

Anchor regexes at word boundaries.

717. By Michael Gorven

Make regex case insensitive and multiline.

716. By Michael Gorven

Rename to StaticFactoid.

715. By Michael Gorven

Allow regex factoids to be overridden or added individually.

714. By Michael Gorven

Move factoid interpolation to separate function and use in regex processor.

713. By Michael Gorven

Add simple statically configured regex factoid processor.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/factoid.py'
2--- ibid/plugins/factoid.py 2009-07-12 12:43:30 +0000
3+++ ibid/plugins/factoid.py 2009-07-18 10:36:21 +0000
4@@ -342,6 +342,23 @@
5 else:
6 event.addresponse(u"I couldn't find anything with that name")
7
8+def _interpolate(message, event):
9+ message = message.replace('$who', event.sender['nick'])
10+ message = message.replace('$channel', event.channel)
11+ utcnow = time()
12+ now = localtime(utcnow)
13+ message = message.replace('$year', str(now[0]))
14+ message = message.replace('$month', str(now[1]))
15+ message = message.replace('$day', str(now[2]))
16+ message = message.replace('$hour', str(now[3]))
17+ message = message.replace('$minute', str(now[4]))
18+ message = message.replace('$second', str(now[5]))
19+ message = message.replace('$date', format_date(utcnow, 'date'))
20+ message = message.replace('$time', format_date(utcnow, 'time'))
21+ message = message.replace('$dow', strftime('%A', now))
22+ message = message.replace('$unixtime', str(utcnow))
23+ return message
24+
25 class Get(Processor, RPC):
26 u"""<factoid> [( #<number> | /<pattern>/[r] )]"""
27 feature = 'factoids'
28@@ -382,20 +399,7 @@
29 reply = reply.replace('$%s' % position, capture)
30 position = position + 1
31
32- reply = reply.replace('$who', event.sender['nick'])
33- reply = reply.replace('$channel', event.channel)
34- utcnow = time()
35- now = localtime(utcnow)
36- reply = reply.replace('$year', str(now[0]))
37- reply = reply.replace('$month', str(now[1]))
38- reply = reply.replace('$day', str(now[2]))
39- reply = reply.replace('$hour', str(now[3]))
40- reply = reply.replace('$minute', str(now[4]))
41- reply = reply.replace('$second', str(now[5]))
42- reply = reply.replace('$date', format_date(utcnow, 'date'))
43- reply = reply.replace('$time', format_date(utcnow, 'time'))
44- reply = reply.replace('$dow', strftime('%A', now))
45- reply = reply.replace('$unixtime', str(utcnow))
46+ reply = _interpolate(reply, event)
47
48 (reply, count) = action_re.subn('', reply)
49 if count:
50@@ -415,7 +419,7 @@
51 interrogatives = Option('interrogatives', 'Question words to strip', default_interrogatives)
52 verbs = Option('verbs', 'Verbs that split name from value', default_verbs)
53
54- priority = 910
55+ priority = 800
56 permission = u'factoid'
57
58 def setup(self):
59@@ -605,4 +609,45 @@
60
61 event.addresponse(True)
62
63+greetings = (u'lo', u'ello', u'hello', u'hi', u'hithere', u'howdy', u'hey', u'heya', u'hiya', u'hola', u'salut', u'bonjour', u'sup', u'wussup', u'hoezit', u'wotcha', u'wotcher', u'yo', u'word', u'goodday', u'wasup', u'wassup', u'howzit', u'howsit', u'buongiorno', u'hoelykit', u'hoegaandit', u'goodmorning', u'morning', u'afternoon', u'evening')
64+static_default = {
65+ 'greet': {
66+ 'matches': [r'\b(' + '|'.join(greetings) + r')\b'],
67+ 'responses': greetings,
68+ },
69+ 'reward': {
70+ 'matches': [r'\bbot(\s+|\-)?snack\b'],
71+ 'responses': [u'thanks, $who', u'$who: thankyou!', u':)'],
72+ },
73+ 'praise': {
74+ 'matches': [r'\bgood(\s+fuckin[\'g]?)?\s+(lad|bo(t|y)|g([ui]|r+)rl)\b', r'\byou\s+(rock|rocks|rewl|rule|are\s+so+\s+co+l)\b'],
75+ 'responses': [u'thanks, $who', u'$who: thankyou!', u':)'],
76+ },
77+ 'thanks': {
78+ 'matches': [r'\bthank(s|\s*you)\b', r'^\s*ta\s*$', r'^\s*shot\s*$'],
79+ 'responses': [u'no problem, $who', u'$who: my pleasure', u'sure thing, $who', u'no worries, $who', u'$who: np', u'no probs, $who', u'$who: no problemo', u'$who: not at all'],
80+ },
81+ 'criticism': {
82+ 'matches': [r'\b((kak|bad|st(u|oo)pid|dumb)(\s+fuckin[\'g]?)?\s+(bo(t|y)|g([ui]|r+)rl))|(bot(\s|\-)?s(mack|lap))\b'],
83+ 'responses': [u'*whimper*', u'sorry, $who :(', u':(', u'*cringe*'],
84+ },
85+}
86+
87+class StaticFactoid(Processor):
88+ priority = 900
89+
90+ extras = Option('static', 'List of static factoids using regexes', {})
91+
92+ def setup(self):
93+ self.factoids = static_default.copy()
94+ self.factoids.update(self.extras)
95+
96+ @handler
97+ def static(self, event):
98+ for factoid in self.factoids.values():
99+ for match in factoid['matches']:
100+ if re.search(match, event.message['stripped'], re.I|re.DOTALL):
101+ event.addresponse(_interpolate(choice(factoid['responses']), event))
102+ return
103+
104 # vi: set et sta sw=4 ts=4:

Subscribers

People subscribed via source and target branches