diff --git a/plugin.py b/plugin.py index b8acc8d..621938d 100644 --- a/plugin.py +++ b/plugin.py @@ -266,6 +266,9 @@ class DuckHunt(callbacks.Plugin): # Init banging self.banging[currentChannel] = False + # Init shoots + self.shoots[currentChannel] = 0 + # Init averagetime self.averagetime[currentChannel] = 0; @@ -373,7 +376,9 @@ class DuckHunt(callbacks.Plugin): def score(self, irc, msg, args, nick): """ - : Shows the score for a given nick + + + Shows the score for a given nick """ currentChannel = msg.args[0] if irc.isChannel(currentChannel): @@ -397,7 +402,9 @@ class DuckHunt(callbacks.Plugin): def mergescores(self, irc, msg, args, channel, nickto, nickfrom): """ - [] : nickto gets the points of nickfrom and nickfrom is removed from the scorelist + [] + + nickto gets the points of nickfrom and nickfrom is removed from the scorelist """ if irc.isChannel(channel): try: @@ -421,7 +428,9 @@ class DuckHunt(callbacks.Plugin): def mergetimes(self, irc, msg, args, channel, nickto, nickfrom): """ - [] : nickto gets the best time of nickfrom if nickfrom time is better than nickto time, and nickfrom is removed from the timelist. Also works with worst times. + [] + + nickto gets the best time of nickfrom if nickfrom time is better than nickto time, and nickfrom is removed from the timelist. Also works with worst times. """ if irc.isChannel(channel): try: @@ -455,7 +464,9 @@ class DuckHunt(callbacks.Plugin): def rmtime(self, irc, msg, args, channel, nick): """ - [] : Remove 's best time + [] + + Remove 's best time """ if irc.isChannel(channel): self._read_scores(channel) @@ -472,7 +483,9 @@ class DuckHunt(callbacks.Plugin): def rmscore(self, irc, msg, args, channel, nick): """ - [] : Remove 's score + [] + + Remove 's score """ if irc.isChannel(channel): try: @@ -493,7 +506,9 @@ class DuckHunt(callbacks.Plugin): def listscores(self, irc, msg, args, size, channel): """ - [] []: Shows the -sized score list for (or for the current channel if no channel is given) + [] [] + + Shows the -sized score list for (or for the current channel if no channel is given) """ if irc.isChannel(channel): @@ -552,7 +567,9 @@ class DuckHunt(callbacks.Plugin): def listtimes(self, irc, msg, args, size, channel): """ - [] []: Shows the -sized time list for (or for the current channel if no channel is given) + [] [] + + Shows the -sized time list for (or for the current channel if no channel is given) """ if irc.isChannel(channel): @@ -833,7 +850,8 @@ class DuckHunt(callbacks.Plugin): irc.reply("Longest time: %s with %.2f seconds%s" % (key, value, recordmsg)) # Showing average shooting time: - irc.reply("Average shooting time: %.2f seconds" % ((self.averagetime[currentChannel] / self.shoots[currentChannel]))) + if (self.shoots[currentChannel] > 1): + irc.reply("Average shooting time: %.2f seconds" % ((self.averagetime[currentChannel] / self.shoots[currentChannel]))) # Write the scores and times to disk self._calc_scores(currentChannel) diff --git a/test.py b/test.py index ec4ac7c..8d88724 100644 --- a/test.py +++ b/test.py @@ -29,8 +29,18 @@ from supybot.test import * -class DuckHuntTestCase(PluginTestCase): - plugins = ('DuckHuntTestCase',) +class DuckHuntTestCase(ChannelPluginTestCase): + plugins = ('DuckHunt',) + + + def tests(self): + self.assertResponse("bang", "There is no hunt right now! You can start a hunt with the 'start' command") + self.assertResponse("stop", "Nothing to stop: there's no hunt right now.") + self.assertResponse("start", "The hunt starts now!") + self.assertResponse("start", "There is already a hunt right now!") + self.assertRegexp("bang", "^There was no duck!") + self.assertResponse("stop", "The hunt stops now!") + self.assertNotError("listscores") # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: