mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 11:42:52 +01:00
Added RFE #802856, so regexps aren't required by searchfactoids.
This commit is contained in:
parent
073040d92e
commit
949deee935
@ -327,9 +327,11 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
||||
|
||||
_sqlTrans = string.maketrans('*?', '%_')
|
||||
def searchfactoids(self, irc, msg, args):
|
||||
"""[<channel>] <regexp>
|
||||
"""[<channel>] <regexp|string>
|
||||
|
||||
Searches the keyspace for keys matching <regexp>.
|
||||
Searches the keyspace for keys matching <regexp>. If <regexp|string>
|
||||
isn't a regexp (i.e, it's not of the form m/foo/ or /bar/) then the
|
||||
literal string is searched for.
|
||||
"""
|
||||
channel = privmsgs.getChannel(msg, args)
|
||||
regexp = privmsgs.getArgs(args)
|
||||
@ -338,6 +340,10 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
||||
def p(s):
|
||||
return int(bool(r.search(s)))
|
||||
except ValueError, e:
|
||||
if not regexp.startswith('m/') or regexp[0] == '/' == regexp[-1]:
|
||||
def p(s):
|
||||
return int(regexp in s)
|
||||
else:
|
||||
irc.error(msg, 'Invalid regular expression.')
|
||||
return
|
||||
db = self.getDb(channel)
|
||||
|
@ -76,6 +76,8 @@ class FactoidsTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||
self.assertRegexp('searchfactoids /^.+i/', 'jemfinch.*strike')
|
||||
self.assertNotRegexp('searchfactoids /^.+i/', 'inkedmn')
|
||||
self.assertRegexp('searchfactoids /^j/', 'jemfinch.*jamessan')
|
||||
self.assertRegexp('searchfactoids ke',
|
||||
'inkedmn.*strike|strike.*inkedmn')
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
Loading…
Reference in New Issue
Block a user