mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-26 04:51:09 -05:00
minor edits, cleanup
This commit is contained in:
parent
75e8faad97
commit
aa4e51ae37
@ -143,8 +143,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
self.channelweek[channel][self.woy][self.dow][player] += value
|
self.channelweek[channel][self.woy][self.dow][player] += value
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _write_scores(self, channel):
|
def _write_scores(self, channel):
|
||||||
"""
|
"""
|
||||||
Write scores and times to the disk
|
Write scores and times to the disk
|
||||||
@ -171,11 +169,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
outputfile.close()
|
outputfile.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _read_scores(self, channel):
|
def _read_scores(self, channel):
|
||||||
"""
|
"""
|
||||||
Reads scores and times from disk
|
Reads scores and times from disk
|
||||||
@ -210,7 +203,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
inputfile.close()
|
inputfile.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _initdayweekyear(self, channel):
|
def _initdayweekyear(self, channel):
|
||||||
self.dow = int(time.strftime("%u")) # Day of week
|
self.dow = int(time.strftime("%u")) # Day of week
|
||||||
self.woy = int(time.strftime("%V")) # Week of year
|
self.woy = int(time.strftime("%V")) # Week of year
|
||||||
@ -231,7 +223,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
self.channelweek[channel][self.woy][self.dow] = {}
|
self.channelweek[channel][self.woy][self.dow] = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _initthrottle(self, irc, msg, args, channel):
|
def _initthrottle(self, irc, msg, args, channel):
|
||||||
|
|
||||||
self._initdayweekyear(channel)
|
self._initdayweekyear(channel)
|
||||||
@ -380,7 +371,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
self._launch(irc, msg, '')
|
self._launch(irc, msg, '')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def stophunt(self, irc, msg, args):
|
def stophunt(self, irc, msg, args):
|
||||||
"""
|
"""
|
||||||
Stops the current hunt
|
Stops the current hunt
|
||||||
@ -403,6 +393,7 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
irc.error('You have to be on a channel')
|
irc.error('You have to be on a channel')
|
||||||
stophunt = wrap(stophunt)
|
stophunt = wrap(stophunt)
|
||||||
|
|
||||||
|
|
||||||
def fridaymode(self, irc, msg, args, channel, status):
|
def fridaymode(self, irc, msg, args, channel, status):
|
||||||
"""
|
"""
|
||||||
[<status>]
|
[<status>]
|
||||||
@ -428,6 +419,7 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
|
|
||||||
fridaymode = wrap(fridaymode, ['channel', 'admin', optional('anything')])
|
fridaymode = wrap(fridaymode, ['channel', 'admin', optional('anything')])
|
||||||
|
|
||||||
|
|
||||||
def launched(self, irc, msg, args):
|
def launched(self, irc, msg, args):
|
||||||
"""
|
"""
|
||||||
Is there a duck right now?
|
Is there a duck right now?
|
||||||
@ -447,7 +439,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
launched = wrap(launched)
|
launched = wrap(launched)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def score(self, irc, msg, args, nick):
|
def score(self, irc, msg, args, nick):
|
||||||
"""
|
"""
|
||||||
<nick>
|
<nick>
|
||||||
@ -473,11 +464,9 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
score = wrap(score, ['nick'])
|
score = wrap(score, ['nick'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def mergescores(self, irc, msg, args, channel, nickto, nickfrom):
|
def mergescores(self, irc, msg, args, channel, nickto, nickfrom):
|
||||||
"""
|
"""
|
||||||
[<channel>] <nickto> <nickfrom>
|
[<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):
|
if irc.isChannel(channel):
|
||||||
@ -511,12 +500,9 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
except:
|
except:
|
||||||
irc.error("Can't merge day scores")
|
irc.error("Can't merge day scores")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
irc.error('You have to be on a channel')
|
irc.error('You have to be on a channel')
|
||||||
|
|
||||||
|
|
||||||
mergescores = wrap(mergescores, ['channel', 'nick', 'nick', 'admin'])
|
mergescores = wrap(mergescores, ['channel', 'nick', 'nick', 'admin'])
|
||||||
|
|
||||||
|
|
||||||
@ -524,7 +510,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
def mergetimes(self, irc, msg, args, channel, nickto, nickfrom):
|
def mergetimes(self, irc, msg, args, channel, nickto, nickfrom):
|
||||||
"""
|
"""
|
||||||
[<channel>] <nickto> <nickfrom>
|
[<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):
|
if irc.isChannel(channel):
|
||||||
@ -548,19 +533,15 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
except:
|
except:
|
||||||
irc.replyError()
|
irc.replyError()
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
irc.error('You have to be on a channel')
|
irc.error('You have to be on a channel')
|
||||||
|
|
||||||
|
|
||||||
mergetimes = wrap(mergetimes, ['channel', 'nick', 'nick', 'admin'])
|
mergetimes = wrap(mergetimes, ['channel', 'nick', 'nick', 'admin'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def rmtime(self, irc, msg, args, channel, nick):
|
def rmtime(self, irc, msg, args, channel, nick):
|
||||||
"""
|
"""
|
||||||
[<channel>] <nick>
|
[<channel>] <nick>
|
||||||
|
|
||||||
Remove <nick>'s best time
|
Remove <nick>'s best time
|
||||||
"""
|
"""
|
||||||
if irc.isChannel(channel):
|
if irc.isChannel(channel):
|
||||||
@ -575,11 +556,9 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
rmtime = wrap(rmtime, ['channel', 'nick', 'admin'])
|
rmtime = wrap(rmtime, ['channel', 'nick', 'admin'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def rmscore(self, irc, msg, args, channel, nick):
|
def rmscore(self, irc, msg, args, channel, nick):
|
||||||
"""
|
"""
|
||||||
[<channel>] <nick>
|
[<channel>] <nick>
|
||||||
|
|
||||||
Remove <nick>'s score
|
Remove <nick>'s score
|
||||||
"""
|
"""
|
||||||
if irc.isChannel(channel):
|
if irc.isChannel(channel):
|
||||||
@ -598,12 +577,9 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
rmscore = wrap(rmscore, ['channel', 'nick', 'admin'])
|
rmscore = wrap(rmscore, ['channel', 'nick', 'admin'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def dayscores(self, irc, msg, args, channel):
|
def dayscores(self, irc, msg, args, channel):
|
||||||
"""
|
"""
|
||||||
[<channel>]
|
[<channel>]
|
||||||
|
|
||||||
Shows the score list of the day for <channel>.
|
Shows the score list of the day for <channel>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -624,7 +600,8 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
msgstring += "(x{0}x: {1}) ".format(item[0], str(item[1]))
|
msgstring += "(x{0}x: {1}) ".format(item[0], str(item[1]))
|
||||||
|
|
||||||
if msgstring != "":
|
if msgstring != "":
|
||||||
irc.reply("Scores for today: " + msgstring)
|
irc.reply("Scores for today:")
|
||||||
|
irc.reply(msgstring)
|
||||||
else:
|
else:
|
||||||
irc.reply("There aren't any day scores for today yet.")
|
irc.reply("There aren't any day scores for today yet.")
|
||||||
else:
|
else:
|
||||||
@ -638,11 +615,9 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
dayscores = wrap(dayscores, ['channel'])
|
dayscores = wrap(dayscores, ['channel'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def weekscores(self, irc, msg, args, week, nick, channel):
|
def weekscores(self, irc, msg, args, week, nick, channel):
|
||||||
"""
|
"""
|
||||||
[<week>] [<nick>] [<channel>]
|
[<week>] [<nick>] [<channel>]
|
||||||
|
|
||||||
Shows the score list of the week for <channel>. If <nick> is provided, it will only show <nick>'s scores.
|
Shows the score list of the week for <channel>. If <nick> is provided, it will only show <nick>'s scores.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -673,7 +648,8 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
weekscores[player] += value
|
weekscores[player] += value
|
||||||
|
|
||||||
if msgstring != "":
|
if msgstring != "":
|
||||||
irc.reply("Scores for week " + str(week) + ": " + msgstring)
|
irc.reply("Scores for week " + str(week) + ":")
|
||||||
|
irc.reply(msgstring)
|
||||||
# Who's the winner at this point?
|
# Who's the winner at this point?
|
||||||
winnernick, winnerscore = max(iter(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))
|
irc.reply("Leader: x%sx with %i points." % (winnernick, winnerscore))
|
||||||
@ -691,7 +667,8 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
total += self.channelweek[channel][week][i].get(nick)
|
total += self.channelweek[channel][week][i].get(nick)
|
||||||
|
|
||||||
if msgstring != "":
|
if msgstring != "":
|
||||||
irc.reply(nick + " scores for week " + str(self.woy) + ": " + msgstring)
|
irc.reply(nick + " scores for week " + str(self.woy) + ":")
|
||||||
|
irc.reply(msgstring)
|
||||||
irc.reply("Total: " + str(total) + " points.")
|
irc.reply("Total: " + str(total) + " points.")
|
||||||
else:
|
else:
|
||||||
irc.reply("There aren't any week scores for this nick.")
|
irc.reply("There aren't any week scores for this nick.")
|
||||||
@ -706,11 +683,9 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
weekscores = wrap(weekscores, [optional('int'), optional('nick'), 'channel'])
|
weekscores = wrap(weekscores, [optional('int'), optional('nick'), 'channel'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def listscores(self, irc, msg, args, size, channel):
|
def listscores(self, irc, msg, args, size, channel):
|
||||||
"""
|
"""
|
||||||
[<size>] [<channel>]
|
[<size>] [<channel>]
|
||||||
|
|
||||||
Shows the <size>-sized score list for <channel> (or for the current channel if no channel is given)
|
Shows the <size>-sized score list for <channel> (or for the current channel if no channel is given)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -771,7 +746,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
def listtimes(self, irc, msg, args, size, channel):
|
def listtimes(self, irc, msg, args, size, channel):
|
||||||
"""
|
"""
|
||||||
[<size>] [<channel>]
|
[<size>] [<channel>]
|
||||||
|
|
||||||
Shows the <size>-sized time list for <channel> (or for the current channel if no channel is given)
|
Shows the <size>-sized time list for <channel> (or for the current channel if no channel is given)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -804,7 +778,7 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
#msgstring += "x" + item[0] + "x: "+ str(round(item[1],2)) + " | "
|
#msgstring += "x" + item[0] + "x: "+ str(round(item[1],2)) + " | "
|
||||||
msgstring += "(x{0}x: {1}) ".format(item[0], str(round(item[1],2)))
|
msgstring += "(x{0}x: {1}) ".format(item[0], str(round(item[1],2)))
|
||||||
if msgstring != "":
|
if msgstring != "":
|
||||||
irc.reply("\_o< ~ DuckHunt top-" + str(listsize) + " times for " + channel + " ~ >o_/")
|
irc.reply("\_o< ~ DuckHunt top-" + str(listsize) + " fastest times for " + channel + " ~ >o_/")
|
||||||
irc.reply(msgstring)
|
irc.reply(msgstring)
|
||||||
else:
|
else:
|
||||||
irc.reply("There aren't any best times for this channel yet.")
|
irc.reply("There aren't any best times for this channel yet.")
|
||||||
@ -832,7 +806,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
listtimes = wrap(listtimes, [optional('int'), 'channel'])
|
listtimes = wrap(listtimes, [optional('int'), 'channel'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def dbg(self, irc, msg, args):
|
def dbg(self, irc, msg, args):
|
||||||
"""
|
"""
|
||||||
This is a debug command. If debug mode is not enabled, it won't do anything
|
This is a debug command. If debug mode is not enabled, it won't do anything
|
||||||
@ -844,7 +817,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
dbg = wrap(dbg)
|
dbg = wrap(dbg)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def bang(self, irc, msg, args):
|
def bang(self, irc, msg, args):
|
||||||
"""
|
"""
|
||||||
Shoots the duck!
|
Shoots the duck!
|
||||||
@ -866,7 +838,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
irc.reply("You are reloading... (Reloading takes %i seconds)" % (self.reloadtime[currentChannel]))
|
irc.reply("You are reloading... (Reloading takes %i seconds)" % (self.reloadtime[currentChannel]))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
# This player is now reloading
|
# This player is now reloading
|
||||||
self.reloading[currentChannel][msg.nick] = time.time();
|
self.reloading[currentChannel][msg.nick] = time.time();
|
||||||
|
|
||||||
@ -994,8 +965,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
irc.reply(message)
|
irc.reply(message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _end(self, irc, msg, args):
|
def _end(self, irc, msg, args):
|
||||||
"""
|
"""
|
||||||
End of the hunt (is called when the hunts stop "naturally" or when someone uses the !stop command)
|
End of the hunt (is called when the hunts stop "naturally" or when someone uses the !stop command)
|
||||||
@ -1033,11 +1002,10 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
# Showing scores
|
# Showing scores
|
||||||
#irc.reply("Winner: %s with %i points" % (winnernick, winnerscore))
|
#irc.reply("Winner: %s with %i points" % (winnernick, winnerscore))
|
||||||
#irc.reply(self.scores.get(currentChannel))
|
#irc.reply(self.scores.get(currentChannel))
|
||||||
#TODO: Better display
|
|
||||||
reply = []
|
reply = []
|
||||||
for nick, score in sorted(iter(self.scores.get(currentChannel).items()), key=itemgetter(1), reverse=True):
|
for nick, score in sorted(iter(self.scores.get(currentChannel).items()), key=itemgetter(1), reverse=True):
|
||||||
reply.append("({0}: {1})".format(nick, score))
|
reply.append("({0}: {1})".format(nick, score))
|
||||||
irc.reply(str(reply).replace("[", "").replace("]", "").replace(",", "").replace("'", ""), prefixNick=False)
|
irc.reply("Scores: " + str(reply).replace("[", "").replace("]", "").replace(",", "").replace("'", ""), prefixNick=False)
|
||||||
|
|
||||||
# Getting channel best time (to see if the best time of this hunt is better)
|
# Getting channel best time (to see if the best time of this hunt is better)
|
||||||
channelbestnick = None
|
channelbestnick = None
|
||||||
@ -1066,7 +1034,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
if self.channelworsttimes.get(currentChannel):
|
if self.channelworsttimes.get(currentChannel):
|
||||||
channelworstnick, channelworsttime = max(iter(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
|
# Showing worst time
|
||||||
recordmsg = ''
|
recordmsg = ''
|
||||||
if (self.worsttimes.get(currentChannel)):
|
if (self.worsttimes.get(currentChannel)):
|
||||||
@ -1111,9 +1078,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
irc.reply("%s has the lead for the week with %i points." % (winnernick, winnerscore), prefixNick=False)
|
irc.reply("%s has the lead for the week with %i points." % (winnernick, winnerscore), prefixNick=False)
|
||||||
self.leader[currentChannel] = winnernick
|
self.leader[currentChannel] = winnernick
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
irc.reply("Not a single duck was shot during this hunt!", prefixNick=False)
|
irc.reply("Not a single duck was shot during this hunt!", prefixNick=False)
|
||||||
|
|
||||||
@ -1134,7 +1098,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
self.shoots[currentChannel] = 0
|
self.shoots[currentChannel] = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _launch(self, irc, msg, args):
|
def _launch(self, irc, msg, args):
|
||||||
"""
|
"""
|
||||||
Launch a duck
|
Launch a duck
|
||||||
@ -1168,7 +1131,6 @@ class DuckHunt(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
irc.error('You have to be on a channel')
|
irc.error('You have to be on a channel')
|
||||||
|
|
||||||
|
|
||||||
Class = DuckHunt
|
Class = DuckHunt
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user