cleanup. more python3 stuff. keys->items etc.
This commit is contained in:
parent
83c6b73052
commit
8a4d3e84b4
36
plugin.py
36
plugin.py
|
|
@ -100,7 +100,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
|
||||
# scores
|
||||
# Adding current scores to the channel scores
|
||||
for player in list(self.scores[channel].keys()):
|
||||
for player in self.scores[channel].items():
|
||||
if not player in self.channelscores[channel]:
|
||||
# It's a new player
|
||||
self.channelscores[channel][player] = self.scores[channel][player]
|
||||
|
|
@ -110,7 +110,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
|
||||
# times
|
||||
# Adding times scores to the channel scores
|
||||
for player in list(self.toptimes[channel].keys()):
|
||||
for player in self.toptimes[channel].items():
|
||||
if not player in self.channeltimes[channel]:
|
||||
# It's a new player
|
||||
self.channeltimes[channel][player] = self.toptimes[channel][player]
|
||||
|
|
@ -122,7 +122,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
|
||||
# worst times
|
||||
# Adding worst times scores to the channel scores
|
||||
for player in list(self.worsttimes[channel].keys()):
|
||||
for player in self.worsttimes[channel].items():
|
||||
if not player in self.channelworsttimes[channel]:
|
||||
# It's a new player
|
||||
self.channelworsttimes[channel][player] = self.worsttimes[channel][player]
|
||||
|
|
@ -133,7 +133,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
self.channelworsttimes[channel][player] = self.worsttimes[channel][player]
|
||||
|
||||
# week scores
|
||||
for player in list(self.scores[channel].keys()):
|
||||
for player 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
|
||||
|
|
@ -619,7 +619,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
if self.channelweek[channel][week].get(day):
|
||||
# Getting all scores, to get the winner of the week
|
||||
msgstring = ''
|
||||
scores = sorted(iter(list(self.channelweek[channel][week][day].items())), key=lambda k_v2:(k_v2[1],k_v2[0]), reverse=True)
|
||||
scores = sorted(iter(self.channelweek[channel][week][day].items()), key=lambda k_v2:(k_v2[1],k_v2[0]), reverse=True)
|
||||
for item in scores:
|
||||
msgstring += "x" + item[0] + "x: "+ str(item[1]) + " | "
|
||||
|
||||
|
|
@ -663,7 +663,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
for i in (1,2,3,4,5,6,7):
|
||||
if self.channelweek[channel][week].get(i):
|
||||
# Getting winner of the day
|
||||
winnernick, winnerscore = max(iter(list(self.channelweek[channel][week][i].items())), key=lambda k_v:(k_v[1],k_v[0]))
|
||||
winnernick, winnerscore = max(iter(self.channelweek[channel][week][i].items()), key=lambda k_v:(k_v[1],k_v[0]))
|
||||
msgstring += self.dayname[i - 1] + ": x" + winnernick + "x ("+ str(winnerscore) + ") | "
|
||||
|
||||
# Getting all scores, to get the winner of the week
|
||||
|
|
@ -675,7 +675,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
if msgstring != "":
|
||||
irc.reply("Scores for week " + str(week) + ": " + msgstring)
|
||||
# Who's the winner at this point?
|
||||
winnernick, winnerscore = max(iter(list(weekscores.items())), key=lambda k_v1:(k_v1[1],k_v1[0]))
|
||||
winnernick, winnerscore = max(iter(weekscores.items()), key=lambda k_v1:(k_v1[1],k_v1[0]))
|
||||
irc.reply("Leader: x%sx with %i points." % (winnernick, winnerscore))
|
||||
|
||||
else:
|
||||
|
|
@ -729,7 +729,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
listsize = size
|
||||
|
||||
# Sort the scores (reversed: the higher the better)
|
||||
scores = sorted(iter(list(self.channelscores[channel].items())), key=lambda k_v9:(k_v9[1],k_v9[0]), reverse=True)
|
||||
scores = sorted(iter(self.channelscores[channel].items()), key=lambda k_v9:(k_v9[1],k_v9[0]), reverse=True)
|
||||
del scores[listsize:]
|
||||
|
||||
msgstring = ""
|
||||
|
|
@ -757,7 +757,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
if (self.channelscores.get(channel)):
|
||||
scores = self.channelscores[channel]
|
||||
total = 0
|
||||
for player in list(scores.keys()):
|
||||
for player in scores.items():
|
||||
total += scores[player]
|
||||
irc.reply(str(total) + " ducks have been shot in " + channel + "!")
|
||||
else:
|
||||
|
|
@ -795,7 +795,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
listsize = size
|
||||
|
||||
# Sort the times (not reversed: the lower the better)
|
||||
times = sorted(iter(list(self.channeltimes[channel].items())), key=lambda k_v10:(k_v10[1],k_v10[0]), reverse=False)
|
||||
times = sorted(iter(self.channeltimes[channel].items()), key=lambda k_v10:(k_v10[1],k_v10[0]), reverse=False)
|
||||
del times[listsize:]
|
||||
|
||||
msgstring = ""
|
||||
|
|
@ -811,7 +811,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
irc.reply("There aren't any best times for this channel yet.")
|
||||
|
||||
|
||||
times = sorted(iter(list(self.channelworsttimes[channel].items())), key=lambda k_v11:(k_v11[1],k_v11[0]), reverse=True)
|
||||
times = sorted(iter(self.channelworsttimes[channel].items()), key=lambda k_v11:(k_v11[1],k_v11[0]), reverse=True)
|
||||
del times[listsize:]
|
||||
|
||||
msgstring = ""
|
||||
|
|
@ -1020,7 +1020,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
if (self.scores.get(currentChannel)):
|
||||
|
||||
# Getting winner
|
||||
winnernick, winnerscore = max(iter(list(self.scores.get(currentChannel).items())), key=lambda k_v12:(k_v12[1],k_v12[0]))
|
||||
winnernick, winnerscore = max(iter(self.scores.get(currentChannel).items()), key=lambda k_v12:(k_v12[1],k_v12[0]))
|
||||
if self.registryValue('ducks', currentChannel):
|
||||
maxShoots = self.registryValue('ducks', currentChannel)
|
||||
else:
|
||||
|
|
@ -1035,7 +1035,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
#irc.reply("Winner: %s with %i points" % (winnernick, winnerscore))
|
||||
#irc.reply(self.scores.get(currentChannel))
|
||||
#TODO: Better display
|
||||
irc.reply(sorted(iter(list(self.scores.get(currentChannel).items())), key=lambda k_v4:(k_v4[1],k_v4[0]), reverse=True))
|
||||
irc.reply(sorted(iter(self.scores.get(currentChannel).items()), key=lambda k_v4:(k_v4[1],k_v4[0]), reverse=True))
|
||||
|
||||
|
||||
|
||||
|
|
@ -1043,12 +1043,12 @@ class DuckHunt(callbacks.Plugin):
|
|||
channelbestnick = None
|
||||
channelbesttime = None
|
||||
if self.channeltimes.get(currentChannel):
|
||||
channelbestnick, channelbesttime = min(iter(list(self.channeltimes.get(currentChannel).items())), key=lambda k_v5:(k_v5[1],k_v5[0]))
|
||||
channelbestnick, channelbesttime = min(iter(self.channeltimes.get(currentChannel).items()), key=lambda k_v5:(k_v5[1],k_v5[0]))
|
||||
|
||||
# Showing best time
|
||||
recordmsg = ''
|
||||
if (self.toptimes.get(currentChannel)):
|
||||
key,value = min(iter(list(self.toptimes.get(currentChannel).items())), key=lambda k_v6:(k_v6[1],k_v6[0]))
|
||||
key,value = min(iter(self.toptimes.get(currentChannel).items()), key=lambda k_v6:(k_v6[1],k_v6[0]))
|
||||
if (channelbesttime and value < channelbesttime):
|
||||
recordmsg = '. This is the new record for this channel! (previous record was held by ' + channelbestnick + ' with ' + str(round(channelbesttime,2)) + ' seconds)'
|
||||
else:
|
||||
|
|
@ -1064,13 +1064,13 @@ class DuckHunt(callbacks.Plugin):
|
|||
channelworstnick = None
|
||||
channelworsttime = None
|
||||
if self.channelworsttimes.get(currentChannel):
|
||||
channelworstnick, channelworsttime = max(iter(list(self.channelworsttimes.get(currentChannel).items())), key=lambda k_v7:(k_v7[1],k_v7[0]))
|
||||
channelworstnick, channelworsttime = max(iter(self.channelworsttimes.get(currentChannel).items()), key=lambda k_v7:(k_v7[1],k_v7[0]))
|
||||
|
||||
|
||||
# Showing worst time
|
||||
recordmsg = ''
|
||||
if (self.worsttimes.get(currentChannel)):
|
||||
key,value = max(iter(list(self.worsttimes.get(currentChannel).items())), key=lambda k_v8:(k_v8[1],k_v8[0]))
|
||||
key,value = max(iter(self.worsttimes.get(currentChannel).items()), key=lambda k_v8:(k_v8[1],k_v8[0]))
|
||||
if (channelworsttime and value > channelworsttime):
|
||||
recordmsg = '. This is the new longest time for this channel! (previous longest time was held by ' + channelworstnick + ' with ' + str(round(channelworsttime,2)) + ' seconds)'
|
||||
else:
|
||||
|
|
@ -1105,7 +1105,7 @@ class DuckHunt(callbacks.Plugin):
|
|||
for player, value in players.items():
|
||||
weekscores.setdefault(player, 0)
|
||||
weekscores[player] += value
|
||||
winnernick, winnerscore = max(iter(list(weekscores.items())), key=lambda k_v3:(k_v3[1],k_v3[0]))
|
||||
winnernick, winnerscore = max(iter(weekscores.items()), key=lambda k_v3:(k_v3[1],k_v3[0]))
|
||||
if (winnernick != self.leader[currentChannel]):
|
||||
if self.leader[currentChannel] != None:
|
||||
irc.reply("%s took the lead for the week over %s with %i points." % (winnernick, self.leader[currentChannel], winnerscore))
|
||||
|
|
|
|||
Loading…
Reference in New Issue