Add !lotterywinner in modules/coins.py, to show who last won the lottery

This commit is contained in:
jesopo 2018-10-14 13:51:32 +01:00
parent 104e1ab185
commit a43d1cbb91

View file

@ -519,6 +519,17 @@ class Module(ModuleManager.BaseModule):
event["stdout"].write("Next lottery is in: %s" % event["stdout"].write("Next lottery is in: %s" %
utils.to_pretty_time(until)) utils.to_pretty_time(until))
@utils.hook("received.command.lotterywinner")
def lottery_winner(self, event):
"""
:help: Show who last won the lottery
"""
winner = event["server"].get_setting("lottery-winner", None)
if winner:
event["stdout"].write("Last lottery winner: %s" % winner)
else:
event["stderr"].write("There have been no lottery winners!")
@utils.hook("timer.coin-lottery") @utils.hook("timer.coin-lottery")
def lottery(self, event): def lottery(self, event):
for server in self.bot.servers.values(): for server in self.bot.servers.values():
@ -539,5 +550,6 @@ class Module(ModuleManager.BaseModule):
self._take_from_pool(server, winnings) self._take_from_pool(server, winnings)
new_coins = coins+winnings new_coins = coins+winnings
user.set_setting("coins", str(new_coins)) user.set_setting("coins", str(new_coins))
event["server"].set_setting("lottery-winner", user.nickname)
user.send_notice("You won %s in the lottery! you now have %s coins" user.send_notice("You won %s in the lottery! you now have %s coins"
% ("{0:.2f}".format(winnings), "{0:.2f}".format(new_coins))) % ("{0:.2f}".format(winnings), "{0:.2f}".format(new_coins)))