mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 11:12:47 +01:00
Add --raw option to factoids.whatis, which disables variable substitution on the factoid.
also add test for this.
This commit is contained in:
parent
b12d8a8a04
commit
dfeb50de2d
@ -241,12 +241,17 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
||||
db.commit()
|
||||
|
||||
def _replyFactoids(self, irc, msg, key, channel, factoids,
|
||||
number=0, error=True):
|
||||
number=0, error=True, raw=False):
|
||||
def format_fact(text):
|
||||
if raw:
|
||||
return text
|
||||
else:
|
||||
return ircutils.standardSubstitute(irc, msg, text)
|
||||
|
||||
if factoids:
|
||||
if number:
|
||||
try:
|
||||
irc.reply(ircutils.standardSubstitute(irc, msg,
|
||||
factoids[number-1][0]))
|
||||
irc.reply(format_fact(factoids[number-1][0]))
|
||||
self._updateRank(channel, [factoids[number-1]])
|
||||
except IndexError:
|
||||
irc.error(_('That\'s not a valid number for that key.'))
|
||||
@ -259,15 +264,13 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
||||
return ircutils.standardSubstitute(irc, msg,
|
||||
formatter, env)
|
||||
if len(factoids) == 1:
|
||||
irc.reply(ircutils.standardSubstitute(irc, msg,
|
||||
prefixer(factoids[0][0])))
|
||||
irc.reply(format_fact(prefixer(factoids[0][0])))
|
||||
else:
|
||||
factoidsS = []
|
||||
counter = 1
|
||||
for factoid in factoids:
|
||||
factoidsS.append(format('(#%i) %s', counter,
|
||||
ircutils.standardSubstitute(irc, msg,
|
||||
factoid[0])))
|
||||
format_fact(factoid[0])))
|
||||
counter += 1
|
||||
irc.replies(factoidsS, prefixer=prefixer,
|
||||
joiner=', or ', onlyPrefixFirst=True)
|
||||
@ -297,13 +300,19 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
||||
self._replyApproximateFactoids(irc, msg, channel, key, error=False)
|
||||
|
||||
@internationalizeDocstring
|
||||
def whatis(self, irc, msg, args, channel, words):
|
||||
"""[<channel>] <key> [<number>]
|
||||
def whatis(self, irc, msg, args, channel, optlist, words):
|
||||
"""[<channel>] [--raw] <key> [<number>]
|
||||
|
||||
Looks up the value of <key> in the factoid database. If given a
|
||||
number, will return only that exact factoid. <channel> is only
|
||||
necessary if the message isn't sent in the channel itself.
|
||||
number, will return only that exact factoid. If '--raw' option is
|
||||
given, no variable substitution will take place on the factoid.
|
||||
<channel> is only necessary if the message isn't sent in the channel
|
||||
itself.
|
||||
"""
|
||||
raw = False
|
||||
for (option, arg) in optlist:
|
||||
if option == 'raw':
|
||||
raw = True
|
||||
number = None
|
||||
if len(words) > 1:
|
||||
if words[-1].isdigit():
|
||||
@ -313,12 +322,19 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
||||
key = ' '.join(words)
|
||||
factoids = self._lookupFactoid(channel, key)
|
||||
if factoids:
|
||||
self._replyFactoids(irc, msg, key, channel, factoids, number)
|
||||
self._replyFactoids(irc, msg, key, channel, factoids, number, raw=raw)
|
||||
else:
|
||||
self._replyApproximateFactoids(irc, msg, channel, key)
|
||||
<<<<<<< HEAD
|
||||
whatis = wrap(whatis, ['channel', many('something')])
|
||||
|
||||
@internationalizeDocstring
|
||||
=======
|
||||
whatis = wrap(whatis, ['channel',
|
||||
getopts({'raw': '',}),
|
||||
many('something')])
|
||||
|
||||
>>>>>>> e4c51ef... Add --raw option to factoids.whatis, which disables variable substitution on the factoid.
|
||||
def alias(self, irc, msg, args, channel, oldkey, newkey, number):
|
||||
"""[<channel>] <oldkey> <newkey> [<number>]
|
||||
|
||||
@ -429,16 +445,11 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
||||
else:
|
||||
s = [ "#%d %s (%d)" % (i+1, key[0], key[1]) for i, key in enumerate(factkeys) ]
|
||||
irc.reply(", ".join(s))
|
||||
<<<<<<< HEAD
|
||||
rank = wrap(rank, ['channel'])
|
||||
|
||||
@internationalizeDocstring
|
||||
=======
|
||||
rank = wrap(rank, ['channel',
|
||||
getopts({'plain': '', 'alpha': '',}),
|
||||
optional('int')])
|
||||
|
||||
>>>>>>> f1517a7... some enhancements Factoids.rank:
|
||||
|
||||
@internationalizeDocstring
|
||||
def lock(self, irc, msg, args, channel, key):
|
||||
"""[<channel>] <key>
|
||||
|
||||
|
@ -177,6 +177,7 @@ class FactoidsTestCase(ChannelPluginTestCase):
|
||||
def testStandardSubstitute(self):
|
||||
self.assertNotError('learn foo as this is $channel, and hour is $hour')
|
||||
self.assertRegexp('whatis foo', 'this is #test, and hour is \d{1,2}')
|
||||
self.assertRegexp('whatis --raw foo', 'this is \$channel, and hour is \$hour')
|
||||
self.assertNotError('learn bar as this is $$channel escaped')
|
||||
self.assertRegexp('whatis bar', 'this is \$channel')
|
||||
self.assertNotError('learn bar as this is $minute')
|
||||
|
Loading…
Reference in New Issue
Block a user