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