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
=== modified file 'ibid/plugins/factoid.py'
--- ibid/plugins/factoid.py 2009-06-17 11:58:36 +0000
+++ ibid/plugins/factoid.py 2009-06-21 21:58:26 +0000
@@ -1,6 +1,7 @@
1import logging
2from random import choice
3import re
1from time import localtime, strftime, time4from time import localtime, strftime, time
2import re
3import logging
45
5from sqlalchemy import Column, Integer, Unicode, DateTime, ForeignKey, UnicodeText, Table, or_6from sqlalchemy import Column, Integer, Unicode, DateTime, ForeignKey, UnicodeText, Table, or_
6from sqlalchemy.orm import relation, eagerload7from sqlalchemy.orm import relation, eagerload
@@ -17,6 +18,12 @@
1718
18log = logging.getLogger('plugins.factoid')19log = logging.getLogger('plugins.factoid')
1920
21default_verbs = ('is', 'are', 'has', 'have', 'was', 'were', 'do', 'does', 'can', 'should', 'would')
22default_interrogatives = ('what', 'wtf', 'where', 'when', 'who', "what's", "who's")
23
24def strip_name(unstripped):
25 return re.match(r'^\s*(.*?)[?!.]*\s*$', unstripped, re.DOTALL).group(1)
26
20class FactoidName(Base):27class FactoidName(Base):
21 __table__ = Table('factoid_names', Base.metadata,28 __table__ = Table('factoid_names', Base.metadata,
22 Column('id', Integer, primary_key=True),29 Column('id', Integer, primary_key=True),
@@ -108,7 +115,6 @@
108action_re = re.compile(r'^\s*<action>\s*')115action_re = re.compile(r'^\s*<action>\s*')
109reply_re = re.compile(r'^\s*<reply>\s*')116reply_re = re.compile(r'^\s*<reply>\s*')
110escape_like_re = re.compile(r'([%_\\])')117escape_like_re = re.compile(r'([%_\\])')
111verbs = ('is', 'are', 'has', 'have', 'was', 'were', 'do', 'does', 'can', 'should', 'would')
112118
113def escape_name(name):119def escape_name(name):
114 return name.replace('%', '\\%').replace('_', '\\_').replace('$arg', '_%')120 return name.replace('%', '\\%').replace('_', '\\_').replace('$arg', '_%')
@@ -236,6 +242,8 @@
236 @authorise242 @authorise
237 def alias(self, event, target, source):243 def alias(self, event, target, source):
238244
245 target = strip_name(target)
246
239 if target.lower() == source.lower():247 if target.lower() == source.lower():
240 event.addresponse(u"That makes no sense, they *are* the same")248 event.addresponse(u"That makes no sense, they *are* the same")
241 return249 return
@@ -263,7 +271,8 @@
263271
264 regex_re = re.compile(r'^/(.*)/(r?)$')272 regex_re = re.compile(r'^/(.*)/(r?)$')
265273
266 @match(r'^search\s+(?:for\s+)?(?:(\d+)\s+)?(?:(facts?|values?)\s+)?(?:containing\s+)?(.+?)(?:\s+from\s+)?(\d+)?$')274 @match(r'^search\s+(?:for\s+)?(?:(\d+)\s+)?(?:(facts?|values?)\s+)?(?:containing\s+)?(.+?)(?:\s+from\s+)?(\d+)?$',
275 version='deaddressed')
267 def search(self, event, limit, search_type, pattern, start):276 def search(self, event, limit, search_type, pattern, start):
268 limit = limit and min(int(limit), self.limit) or self.default277 limit = limit and min(int(limit), self.limit) or self.default
269 start = start and int(start) or 0278 start = start and int(start) or 0
@@ -310,9 +319,11 @@
310 u"""<factoid> [( #<number> | /<pattern>/[r] )]"""319 u"""<factoid> [( #<number> | /<pattern>/[r] )]"""
311 feature = 'factoids'320 feature = 'factoids'
312321
313 verbs = verbs
314 priority = 900322 priority = 900
315 interrogatives = Option('interrogatives', 'Question words to strip', ('what', 'wtf', 'where', 'when', 'who', "what's", "who's"))323
324 interrogatives = Option('interrogatives', 'Question words to strip', default_interrogatives)
325 verbs = Option('verbs', 'Verbs that split name from value', default_verbs)
326
316 date_format = Option('date_format', 'Format string for dates', '%Y/%m/%d')327 date_format = Option('date_format', 'Format string for dates', '%Y/%m/%d')
317 time_format = Option('time_format', 'Format string for times', '%H:%M:%S')328 time_format = Option('time_format', 'Format string for times', '%H:%M:%S')
318329
@@ -321,10 +332,13 @@
321 RPC.__init__(self)332 RPC.__init__(self)
322333
323 def setup(self):334 def setup(self):
324 self.get.im_func.pattern = re.compile(r'^(?:(?:%s)\s+(?:(%s)\s+)?)?(.+?)(?:\s+#(\d+))?(?:\s+/(.+?)/(r?))?$' % ('|'.join(self.interrogatives), '|'.join(self.verbs)), re.I)335 self.get.im_func.pattern = re.compile(
336 r'^(?:(?:%s)\s+(?:(?:%s)\s+)?)?(.+?)(?:\s+#(\d+))?(?:\s+/(.+?)/(r?))?$'
337 % ('|'.join(self.interrogatives),
338 '|'.join(self.verbs)), re.I)
325339
326 @handler340 @handler
327 def get(self, event, verb, name, number, pattern, is_regex):341 def get(self, event, name, number, pattern, is_regex):
328 response = self.remote_get(name, number, pattern, is_regex, event)342 response = self.remote_get(name, number, pattern, is_regex, event)
329 if response:343 if response:
330 event.addresponse(response)344 event.addresponse(response)
@@ -373,7 +387,9 @@
373 u"""<name> (<verb>|=<verb>=) [also] <value>"""387 u"""<name> (<verb>|=<verb>=) [also] <value>"""
374 feature = 'factoids'388 feature = 'factoids'
375389
376 verbs = verbs390 interrogatives = Option('interrogatives', 'Question words to strip', default_interrogatives)
391 verbs = Option('verbs', 'Verbs that split name from value', default_verbs)
392
377 priority = 910393 priority = 910
378 permission = u'factoid'394 permission = u'factoid'
379 395
@@ -381,12 +397,23 @@
381 self.set_factoid.im_func.pattern = re.compile(397 self.set_factoid.im_func.pattern = re.compile(
382 r'^(no[,.: ]\s*)?(.+?)\s+(?:=(\S+)=)?(?(3)|(%s))(\s+also)?\s+((?(3).+|(?!.*=\S+=).+))$'398 r'^(no[,.: ]\s*)?(.+?)\s+(?:=(\S+)=)?(?(3)|(%s))(\s+also)?\s+((?(3).+|(?!.*=\S+=).+))$'
383 % '|'.join(self.verbs), re.I)399 % '|'.join(self.verbs), re.I)
400 self.set_factoid.im_func.message_version = 'deaddressed'
384401
385 @handler402 @handler
386 @authorise403 @authorise
387 def set_factoid(self, event, correction, name, verb1, verb2, addition, value):404 def set_factoid(self, event, correction, name, verb1, verb2, addition, value):
388 verb = verb1 and verb1 or verb2405 verb = verb1 and verb1 or verb2
389406
407 name = strip_name(name)
408
409 if name.lower() in self.interrogatives:
410 event.addresponse(choice((
411 u"I'm afraid I have no idea",
412 u"Not a clue, sorry",
413 u"Erk, dunno",
414 )))
415 return
416
390 factoid = event.session.query(Factoid).join(Factoid.names)\417 factoid = event.session.query(Factoid).join(Factoid.names)\
391 .filter(func.lower(FactoidName.name)==escape_name(name).lower()).first()418 .filter(func.lower(FactoidName.name)==escape_name(name).lower()).first()
392 if factoid:419 if factoid:
@@ -427,9 +454,10 @@
427 permissions = (u'factoidadmin',)454 permissions = (u'factoidadmin',)
428 priority = 890455 priority = 890
429456
430 @match(r'^(.+?)(?:\s+#(\d+)|\s+/(.+?)/(r?))?\s*\+=\s?(.+)$')457 @match(r'^(.+?)(?:\s+#(\d+)|\s+/(.+?)/(r?))?\s*\+=(.+)$', version='deaddressed')
431 @authorise458 @authorise
432 def append(self, event, name, number, pattern, is_regex, suffix):459 def append(self, event, name, number, pattern, is_regex, suffix):
460 name = strip_name(name)
433 factoids = get_factoid(event.session, name, number, pattern, is_regex, all=True)461 factoids = get_factoid(event.session, name, number, pattern, is_regex, all=True)
434 if len(factoids) == 0:462 if len(factoids) == 0:
435 if pattern:463 if pattern:

Subscribers

People subscribed via source and target branches