Merge pull request #60 from ossanna16/master

Fixes wait time bug
This commit is contained in:
shaunagm 2015-04-14 17:21:43 -04:00
commit ea79cc76c3
2 changed files with 8 additions and 3 deletions

9
bot.py
View File

@ -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):

View File

@ -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