From c816dee66fc5c3bf8e95d6bfe9ac65cfc090cd64 Mon Sep 17 00:00:00 2001 From: Stathis Xantinidis Date: Thu, 7 Nov 2024 09:56:26 +0200 Subject: [PATCH] fix a bug where it produces an error and stops the hunt when that happens (#69) This hopefully fixes the "If the hunt starts a day and ends the day after, this will produce an error" [here](https://github.com/oddluck/limnoria-plugins/blob/8a87fa68922fc78cd0e1618ba394461000d92ba3/DuckHunt/plugin.py#L146) --- DuckHunt/plugin.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/DuckHunt/plugin.py b/DuckHunt/plugin.py index b1a2df4..ec76f2f 100644 --- a/DuckHunt/plugin.py +++ b/DuckHunt/plugin.py @@ -141,10 +141,32 @@ class DuckHunt(callbacks.Plugin): if self.worsttimes[channel][player] > value: self.channelworsttimes[channel][player] = value + # # week scores + # for player, value in self.scores[channel].items(): + # # FIXME: If the hunt starts a day and ends the day after, this will produce an error: + # if not player in self.channelweek[channel][self.woy][self.dow]: + # # It's a new player + # self.channelweek[channel][self.woy][self.dow][player] = value + # else: + # # It's a player that already has a saved score + # self.channelweek[channel][self.woy][self.dow][player] += value + # week scores for player, value in self.scores[channel].items(): - # FIXME: If the hunt starts a day and ends the day after, this will produce an error: - if not player in self.channelweek[channel][self.woy][self.dow]: + # Ensure that the channel exists + if channel not in self.channelweek: + self.channelweek[channel] = {} + + # Ensure that the week of year (self.woy) exists for the channel + if self.woy not in self.channelweek[channel]: + self.channelweek[channel][self.woy] = {} + + # Ensure that the day of week (self.dow) exists for the week + if self.dow not in self.channelweek[channel][self.woy]: + self.channelweek[channel][self.woy][self.dow] = {} + + # Now it's safe to check for the player + if player not in self.channelweek[channel][self.woy][self.dow]: # It's a new player self.channelweek[channel][self.woy][self.dow][player] = value else: