From 17f2f45c8fcb63d2bdbccb5af6e25432069f15d5 Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 14 Apr 2015 17:18:39 -0400 Subject: [PATCH] Fixes wait time bug --- bot.py | 9 ++++++--- test_bot.py | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index e34c571..ae1421a 100644 --- a/bot.py +++ b/bot.py @@ -170,7 +170,7 @@ def message_response(bot, ircmsg, actor, ircsock, channel, greeters): # If someone tries to change the wait time... if ircmsg.find(bot.botnick + " --wait-time ") != -1: - bot.wait_time = wait_time_change(actor, ircmsg, ircsock, channel, greeters) # call this to check and change it + bot.wait_time = wait_time_change(actor, ircmsg, ircsock, channel, greeters, bot) # call this to check and change it # If the server pings us then we've got to respond! if ircmsg.find("PING :") != -1: @@ -206,17 +206,20 @@ def greeter_string(greeters): return greeterstring # Changes the wait time from the channel. -def wait_time_change(actor, ircmsg, ircsock, channel, channel_greeters): +def wait_time_change(actor, ircmsg, ircsock, channel, channel_greeters, bot): for admin in channel_greeters: if actor == admin: finder = re.search(r'\d\d*', re.search(r'--wait-time \d\d*', ircmsg) .group()) ircsock.send("PRIVMSG {0} :{1} the wait time is changing to {2} " "seconds.\n".format(channel, actor, finder.group())) - return int(finder.group()) + new_wait_time = int(finder.group()) + return new_wait_time ircsock.send("PRIVMSG {0} :{1} you are not authorized to make that " "change. Please contact one of the channel greeters, like {2}, for " "assistance.\n".format(channel, actor, greeter_string(channel_greeters))) + unchanged_wait_time = bot.wait_time + return unchanged_wait_time # Responds to server Pings. def pong(ircsock, ircmsg): diff --git a/test_bot.py b/test_bot.py index 5dc72c6..fae8f56 100644 --- a/test_bot.py +++ b/test_bot.py @@ -187,10 +187,12 @@ class TestMessageResponse(unittest.TestCase): def test_wait_time_from_admin(self): botcode.message_response(self.bot,"{} --wait-time 40".format(self.bot.botnick),"shauna",ircsock=self.ircsock, channel=settings.channel, greeters=settings.channel_greeters) # Channel-greeters may also be changed. :( self.assertEqual(self.ircsock.sent_message(), "PRIVMSG {} :shauna the wait time is changing to 40 seconds.\n".format(settings.channel)) + self.assertEqual(self.bot.wait_time, 40) def test_wait_time_from_non_admin(self): botcode.message_response(self.bot,"{} --wait-time 40".format(self.bot.botnick),"Impostor",ircsock=self.ircsock, channel=settings.channel, greeters=settings.channel_greeters) # Channel-greeters may also be changed. :( self.assertEqual(self.ircsock.sent_message(), "PRIVMSG {0} :Impostor you are not authorized to make that change. Please contact one of the channel greeters, like {1}, for assistance.\n".format(settings.channel,botcode.greeter_string(settings.channel_greeters))) + self.assertEqual(self.bot.wait_time, settings.wait_time) def test_pong(self): botcode.message_response(self.bot,"PING :","Shauna",ircsock=self.ircsock, channel=settings.channel, greeters=settings.channel_greeters) # Replace this with actual ping message