mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-04-25 09:17:55 +02:00
Changed the name of some variables ('whore' doesn't partse as 'who re{gexp}') and added tests.
This commit is contained in:
parent
0adde0c117
commit
31ef30d961
@ -309,29 +309,32 @@ class Toggleable(object):
|
|||||||
irc.error(msg, '%r isn\'t a valid name to toggle. '
|
irc.error(msg, '%r isn\'t a valid name to toggle. '
|
||||||
'Valid names are %s' % (name, self._toggleNames()))
|
'Valid names are %s' % (name, self._toggleNames()))
|
||||||
|
|
||||||
randomnickre = re.compile ("\$randomnick", re.I)
|
_randomnickRe = re.compile ("\$randomnick", re.I)
|
||||||
randomdatere = re.compile ("\$randomdate", re.I)
|
_randomdateRe = re.compile ("\$randomdate", re.I)
|
||||||
randomintre = re.compile ("\$randomint", re.I)
|
_randomintRe = re.compile ("\$randomint", re.I)
|
||||||
whore = re.compile ("\$who", re.I)
|
_whoRe = re.compile ("\$who", re.I)
|
||||||
botnickre = re.compile("\$botnick", re.I)
|
_botnickRe = re.compile("\$botnick", re.I)
|
||||||
todayre = re.compile("\$today", re.I)
|
_todayRe = re.compile("\$today", re.I)
|
||||||
|
_nowRe = re.compile("\$now", re.I)
|
||||||
def standardSubstitute(irc, msg, text):
|
def standardSubstitute(irc, msg, text):
|
||||||
"""Do the standard set of substitutions on text, and return it"""
|
"""Do the standard set of substitutions on text, and return it"""
|
||||||
nochannel = False
|
if ircutils.isChannel(msg.args[0]):
|
||||||
try:
|
channel = msg.args[0]
|
||||||
channel = privmsgs.getChannel(msg, None)
|
|
||||||
except:
|
|
||||||
nochannel = True
|
|
||||||
if nochannel:
|
|
||||||
text = randomnickre.sub('anyone', text)
|
|
||||||
else:
|
else:
|
||||||
text = randomnickre.sub(random.choice(irc.state.channels[channel].users._data.keys()),
|
channel = None
|
||||||
text)
|
if channel:
|
||||||
|
text = _randomnickRe.sub('anyone', text)
|
||||||
|
else:
|
||||||
|
user = random.choice(list(irc.state.channels[channel].users))
|
||||||
|
text = _randomnickRe.sub(user, text)
|
||||||
t = pow(2,30)*random.random()+time.time()/4.0
|
t = pow(2,30)*random.random()+time.time()/4.0
|
||||||
text = randomdatere.sub(time.ctime(t), text)
|
text = _randomdateRe.sub(time.ctime(t), text)
|
||||||
text = randomintre.sub(str(random.randint(-1000, 1000)), text)
|
text = _randomintRe.sub(str(random.randint(-1000, 1000)), text)
|
||||||
text = whore.sub(msg.nick, text)
|
text = _whoRe.sub(msg.nick, text)
|
||||||
text = botnickre.sub(irc.nick, text)
|
text = _botnickRe.sub(irc.nick, text)
|
||||||
text = todayre.sub(time.ctime(), text)
|
text = _todayRe.sub(time.ctime(), text)
|
||||||
|
text = _nowRe.sub(time.ctime(), text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
@ -31,6 +31,9 @@
|
|||||||
|
|
||||||
from test import *
|
from test import *
|
||||||
|
|
||||||
|
import sets
|
||||||
|
|
||||||
|
import irclib
|
||||||
import plugins
|
import plugins
|
||||||
|
|
||||||
class ToggleDictionaryTestCase(unittest.TestCase):
|
class ToggleDictionaryTestCase(unittest.TestCase):
|
||||||
@ -86,3 +89,36 @@ class ToggleDictionaryTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(t.toString(channel='#foo'),
|
self.assertEqual(t.toString(channel='#foo'),
|
||||||
'(bar: Off; foo: Off)')
|
'(bar: Off; foo: Off)')
|
||||||
|
|
||||||
|
|
||||||
|
class FunctionsTestCase(unittest.TestCase):
|
||||||
|
class irc:
|
||||||
|
class state:
|
||||||
|
users = sets.Set(['foo', 'bar', 'baz'])
|
||||||
|
nick = 'foobar'
|
||||||
|
pass
|
||||||
|
def testStandardSubstitute(self):
|
||||||
|
msg = ircmsgs.privmsg('#foo', 'filler', prefix='biff!quux@xyzzy')
|
||||||
|
s = plugins.standardSubstitute(self.irc, msg, '$randomint')
|
||||||
|
try:
|
||||||
|
int(s)
|
||||||
|
except ValueError:
|
||||||
|
self.fail('$randomnick wasn\'t an int.')
|
||||||
|
s = plugins.standardSubstitute(self.irc, msg, '$randomInt')
|
||||||
|
try:
|
||||||
|
int(s)
|
||||||
|
except ValueError:
|
||||||
|
self.fail('$randomnick wasn\'t an int.')
|
||||||
|
self.assertEqual(plugins.standardSubstitute(self.irc, msg, '$botnick'),
|
||||||
|
self.irc.nick)
|
||||||
|
self.assertEqual(plugins.standardSubstitute(self.irc, msg, '$who'),
|
||||||
|
msg.nick)
|
||||||
|
self.assert_(plugins.standardSubstitute(self.irc, msg, '$randomdate'))
|
||||||
|
self.assert_(plugins.standardSubstitute(self.irc, msg, '$today'))
|
||||||
|
self.assert_(plugins.standardSubstitute(self.irc, msg, '$now'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user