Merge lp:~stefanor/ibid/factoid-383388 into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera
Status: Merged
Approved by: Stefano Rivera
Approved revision: 672
Merged at revision: 680
Proposed branch: lp:~stefanor/ibid/factoid-383388
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: None lines
To merge this branch: bzr merge lp:~stefanor/ibid/factoid-383388
Reviewer Review Type Date Requested Status
Michael Gorven Approve
Jonathan Hitchcock Approve
Review via email: mp+7737@code.launchpad.net

This proposal supersedes a proposal from 2009-06-21.

To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote : Posted in a previous version of this proposal

Resubmitted, with stripping only on factoids, not on factoid values.

Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve
Revision history for this message
Michael Gorven (mgorven) wrote :

 review approve

review: Approve

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-06-17 11:58:36 +0000
3+++ ibid/plugins/factoid.py 2009-06-21 21:58:26 +0000
4@@ -1,6 +1,7 @@
5+import logging
6+from random import choice
7+import re
8 from time import localtime, strftime, time
9-import re
10-import logging
11
12 from sqlalchemy import Column, Integer, Unicode, DateTime, ForeignKey, UnicodeText, Table, or_
13 from sqlalchemy.orm import relation, eagerload
14@@ -17,6 +18,12 @@
15
16 log = logging.getLogger('plugins.factoid')
17
18+default_verbs = ('is', 'are', 'has', 'have', 'was', 'were', 'do', 'does', 'can', 'should', 'would')
19+default_interrogatives = ('what', 'wtf', 'where', 'when', 'who', "what's", "who's")
20+
21+def strip_name(unstripped):
22+ return re.match(r'^\s*(.*?)[?!.]*\s*$', unstripped, re.DOTALL).group(1)
23+
24 class FactoidName(Base):
25 __table__ = Table('factoid_names', Base.metadata,
26 Column('id', Integer, primary_key=True),
27@@ -108,7 +115,6 @@
28 action_re = re.compile(r'^\s*<action>\s*')
29 reply_re = re.compile(r'^\s*<reply>\s*')
30 escape_like_re = re.compile(r'([%_\\])')
31-verbs = ('is', 'are', 'has', 'have', 'was', 'were', 'do', 'does', 'can', 'should', 'would')
32
33 def escape_name(name):
34 return name.replace('%', '\\%').replace('_', '\\_').replace('$arg', '_%')
35@@ -236,6 +242,8 @@
36 @authorise
37 def alias(self, event, target, source):
38
39+ target = strip_name(target)
40+
41 if target.lower() == source.lower():
42 event.addresponse(u"That makes no sense, they *are* the same")
43 return
44@@ -263,7 +271,8 @@
45
46 regex_re = re.compile(r'^/(.*)/(r?)$')
47
48- @match(r'^search\s+(?:for\s+)?(?:(\d+)\s+)?(?:(facts?|values?)\s+)?(?:containing\s+)?(.+?)(?:\s+from\s+)?(\d+)?$')
49+ @match(r'^search\s+(?:for\s+)?(?:(\d+)\s+)?(?:(facts?|values?)\s+)?(?:containing\s+)?(.+?)(?:\s+from\s+)?(\d+)?$',
50+ version='deaddressed')
51 def search(self, event, limit, search_type, pattern, start):
52 limit = limit and min(int(limit), self.limit) or self.default
53 start = start and int(start) or 0
54@@ -310,9 +319,11 @@
55 u"""<factoid> [( #<number> | /<pattern>/[r] )]"""
56 feature = 'factoids'
57
58- verbs = verbs
59 priority = 900
60- interrogatives = Option('interrogatives', 'Question words to strip', ('what', 'wtf', 'where', 'when', 'who', "what's", "who's"))
61+
62+ interrogatives = Option('interrogatives', 'Question words to strip', default_interrogatives)
63+ verbs = Option('verbs', 'Verbs that split name from value', default_verbs)
64+
65 date_format = Option('date_format', 'Format string for dates', '%Y/%m/%d')
66 time_format = Option('time_format', 'Format string for times', '%H:%M:%S')
67
68@@ -321,10 +332,13 @@
69 RPC.__init__(self)
70
71 def setup(self):
72- self.get.im_func.pattern = re.compile(r'^(?:(?:%s)\s+(?:(%s)\s+)?)?(.+?)(?:\s+#(\d+))?(?:\s+/(.+?)/(r?))?$' % ('|'.join(self.interrogatives), '|'.join(self.verbs)), re.I)
73+ self.get.im_func.pattern = re.compile(
74+ r'^(?:(?:%s)\s+(?:(?:%s)\s+)?)?(.+?)(?:\s+#(\d+))?(?:\s+/(.+?)/(r?))?$'
75+ % ('|'.join(self.interrogatives),
76+ '|'.join(self.verbs)), re.I)
77
78 @handler
79- def get(self, event, verb, name, number, pattern, is_regex):
80+ def get(self, event, name, number, pattern, is_regex):
81 response = self.remote_get(name, number, pattern, is_regex, event)
82 if response:
83 event.addresponse(response)
84@@ -373,7 +387,9 @@
85 u"""<name> (<verb>|=<verb>=) [also] <value>"""
86 feature = 'factoids'
87
88- verbs = verbs
89+ interrogatives = Option('interrogatives', 'Question words to strip', default_interrogatives)
90+ verbs = Option('verbs', 'Verbs that split name from value', default_verbs)
91+
92 priority = 910
93 permission = u'factoid'
94
95@@ -381,12 +397,23 @@
96 self.set_factoid.im_func.pattern = re.compile(
97 r'^(no[,.: ]\s*)?(.+?)\s+(?:=(\S+)=)?(?(3)|(%s))(\s+also)?\s+((?(3).+|(?!.*=\S+=).+))$'
98 % '|'.join(self.verbs), re.I)
99+ self.set_factoid.im_func.message_version = 'deaddressed'
100
101 @handler
102 @authorise
103 def set_factoid(self, event, correction, name, verb1, verb2, addition, value):
104 verb = verb1 and verb1 or verb2
105
106+ name = strip_name(name)
107+
108+ if name.lower() in self.interrogatives:
109+ event.addresponse(choice((
110+ u"I'm afraid I have no idea",
111+ u"Not a clue, sorry",
112+ u"Erk, dunno",
113+ )))
114+ return
115+
116 factoid = event.session.query(Factoid).join(Factoid.names)\
117 .filter(func.lower(FactoidName.name)==escape_name(name).lower()).first()
118 if factoid:
119@@ -427,9 +454,10 @@
120 permissions = (u'factoidadmin',)
121 priority = 890
122
123- @match(r'^(.+?)(?:\s+#(\d+)|\s+/(.+?)/(r?))?\s*\+=\s?(.+)$')
124+ @match(r'^(.+?)(?:\s+#(\d+)|\s+/(.+?)/(r?))?\s*\+=(.+)$', version='deaddressed')
125 @authorise
126 def append(self, event, name, number, pattern, is_regex, suffix):
127+ name = strip_name(name)
128 factoids = get_factoid(event.session, name, number, pattern, is_regex, all=True)
129 if len(factoids) == 0:
130 if pattern:

Subscribers

People subscribed via source and target branches