diff --git a/src/plugins.py b/src/plugins.py index aaab6332d..729ebbcf2 100644 --- a/src/plugins.py +++ b/src/plugins.py @@ -323,10 +323,10 @@ def standardSubstitute(irc, msg, text): else: channel = None if channel: - text = _randomnickRe.sub('anyone', text) - else: user = random.choice(list(irc.state.channels[channel].users)) text = _randomnickRe.sub(user, text) + else: + text = _randomnickRe.sub('anyone', text) t = pow(2,30)*random.random()+time.time()/4.0 text = _randomdateRe.sub(time.ctime(t), text) text = _randomintRe.sub(str(random.randint(-1000, 1000)), text) diff --git a/test/test_plugins.py b/test/test_plugins.py index c59fa2987..cf3339ba0 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -90,12 +90,14 @@ class ToggleDictionaryTestCase(unittest.TestCase): '(bar: Off; foo: Off)') +class holder: + users = sets.Set(['foo', 'bar', 'baz']) + class FunctionsTestCase(unittest.TestCase): class irc: class state: - users = sets.Set(['foo', 'bar', 'baz']) + channels = {'#foo': holder()} nick = 'foobar' - pass def testStandardSubstitute(self): msg = ircmsgs.privmsg('#foo', 'filler', prefix='biff!quux@xyzzy') s = plugins.standardSubstitute(self.irc, msg, '$randomint') @@ -115,6 +117,8 @@ class FunctionsTestCase(unittest.TestCase): self.assert_(plugins.standardSubstitute(self.irc, msg, '$randomdate')) self.assert_(plugins.standardSubstitute(self.irc, msg, '$today')) self.assert_(plugins.standardSubstitute(self.irc, msg, '$now')) + n = plugins.standardSubstitute(self.irc, msg, '$randomnick') + self.failUnless(n in self.irc.state.channels['#foo'].users)