mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
Added a few more substitutes and allowed a few more names to be more compatible with blootbot.
This commit is contained in:
parent
cebcf5f0c7
commit
1b462c8b55
@ -241,14 +241,16 @@ class PeriodicFileDownloader(object):
|
||||
world.threadsSpawned += 1
|
||||
|
||||
|
||||
_randomnickRe = re.compile(r'\$randomnick', re.I)
|
||||
_randomnickRe = re.compile(r'\$rand(?:om)?nick', re.I)
|
||||
_randomdateRe = re.compile(r'\$randomdate', re.I)
|
||||
_randomintRe = re.compile(r'\$randomint', re.I)
|
||||
_randomintRe = re.compile(r'\$rand(?:omint)?', re.I)
|
||||
_channelRe = re.compile(r'\$channel', re.I)
|
||||
_whoRe = re.compile(r'\$(?:who|nick)', re.I)
|
||||
_botnickRe = re.compile(r'\$botnick', re.I)
|
||||
_todayRe = re.compile(r'\$today', re.I)
|
||||
_nowRe = re.compile(r'\$now', re.I)
|
||||
_todayRe = re.compile(r'\$(?:today|date)', re.I)
|
||||
_nowRe = re.compile(r'\$(?:now|time)', re.I)
|
||||
_userRe = re.compile(r'\$user', re.I)
|
||||
_hostRe = re.compile(r'\$host', re.I)
|
||||
def standardSubstitute(irc, msg, text):
|
||||
"""Do the standard set of substitutions on text, and return it"""
|
||||
if ircutils.isChannel(msg.args[0]):
|
||||
@ -273,6 +275,8 @@ def standardSubstitute(irc, msg, text):
|
||||
text = _botnickRe.sub(irc.nick, text)
|
||||
text = _todayRe.sub(time.ctime(), text)
|
||||
text = _nowRe.sub(time.ctime(), text)
|
||||
text = _userRe.sub(msg.user, text)
|
||||
text = _hostRe.sub(msg.host, text)
|
||||
return text
|
||||
|
||||
|
||||
|
@ -36,25 +36,6 @@ import sets
|
||||
import irclib
|
||||
import plugins
|
||||
|
||||
class ConfigurableDictionaryTestCase(unittest.TestCase):
|
||||
def test(self):
|
||||
t = plugins.ConfigurableDictionary([('foo', bool, False, 'bar')])
|
||||
self.assertEqual(t.help('foo'), 'bar')
|
||||
self.assertEqual(t.help('f-o-o'), 'bar')
|
||||
self.assertRaises(KeyError, t.help, 'bar')
|
||||
self.assertEqual(t.get('foo'), False)
|
||||
self.assertEqual(t.get('f-o-o'), False)
|
||||
t.set('foo', True)
|
||||
self.assertEqual(t.get('foo'), True)
|
||||
t.set('foo', False, '#foo')
|
||||
self.assertEqual(t.get('foo', '#foo'), False)
|
||||
self.assertEqual(t.get('foo'), True)
|
||||
self.assertRaises(KeyError, t.set, 'bar', True)
|
||||
self.assertRaises(KeyError, t.set, 'bar', True, '#foo')
|
||||
t.set('f-o-o', False)
|
||||
self.assertEqual(t.get('foo'), False)
|
||||
|
||||
|
||||
class holder:
|
||||
users = sets.Set(map(str, range(1000)))
|
||||
|
||||
@ -65,6 +46,11 @@ class FunctionsTestCase(unittest.TestCase):
|
||||
nick = 'foobar'
|
||||
def testStandardSubstitute(self):
|
||||
msg = ircmsgs.privmsg('#foo', 'filler', prefix='biff!quux@xyzzy')
|
||||
s = plugins.standardSubstitute(self.irc, msg, '$rand')
|
||||
try:
|
||||
int(s)
|
||||
except ValueError:
|
||||
self.fail('$rand wasn\'t an int.')
|
||||
s = plugins.standardSubstitute(self.irc, msg, '$randomInt')
|
||||
try:
|
||||
int(s)
|
||||
@ -87,6 +73,8 @@ class FunctionsTestCase(unittest.TestCase):
|
||||
self.fail ('Two $randomints in the same string were the same')
|
||||
self.assert_(plugins.standardSubstitute(self.irc, msg, '$today'))
|
||||
self.assert_(plugins.standardSubstitute(self.irc, msg, '$now'))
|
||||
n = plugins.standardSubstitute(self.irc, msg, '$randnick')
|
||||
self.failUnless(n in self.irc.state.channels['#foo'].users)
|
||||
n = plugins.standardSubstitute(self.irc, msg, '$randomnick')
|
||||
self.failUnless(n in self.irc.state.channels['#foo'].users)
|
||||
n = plugins.standardSubstitute(self.irc, msg, '$randomnick '*100)
|
||||
|
Loading…
Reference in New Issue
Block a user