From 6b9fd384ec528dca518f18d14073e0bd26187c8a Mon Sep 17 00:00:00 2001 From: Mike Edmister Date: Tue, 23 Apr 2019 13:31:02 -0400 Subject: [PATCH] .top function --- pyircbot/modules/StockPlay.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pyircbot/modules/StockPlay.py b/pyircbot/modules/StockPlay.py index 1f78175..5d5856e 100644 --- a/pyircbot/modules/StockPlay.py +++ b/pyircbot/modules/StockPlay.py @@ -143,10 +143,26 @@ class StockPlay(ModuleBase): self.do_trade(data) elif action == "portreport": self.do_report(*data) + elif action == "topten": + self.do_topten(*data) except Exception: traceback.print_exc() continue + def do_topten(self, nick, replyto): + """ + Do lookup of highest valued portfolios + """ + self.log.warning("{} wants top 10 sent to {}".format(nick, replyto)) + + with closing(self.sql.getCursor()) as c: + for num, row in enumerate(c.execute("""SELECT h1.nick as nick, h1.total as total FROM stockplay_balance_history h1 + INNER JOIN (SELECT nick, max(day) as MaxDate FROM stockplay_balance_history GROUP BY nick) h2 + ON h1.nick = h2.nick AND h1.day = h2.MaxDate + ORDER BY total DESC""").fetchall(), start=1): + + self.bot.act_PRIVMSG(replyto, "{}: {} with total: ~{}".format(num, row.nick, row.total)) + def do_trade(self, trade): """ Perform a queued trade @@ -452,6 +468,17 @@ class StockPlay(ModuleBase): else message.args[0], full))) + @info("top", "show top portfolios", cmds=["top", "top10"]) + @command("top", "top10", allow_private=True) + @protected() + def cmd_top(self, message, command): + """ + Top 10 report command + """ + self.asyncq.put(("topten", (message.prefix.nick, + message.prefix.nick if not message.args[0].startswith("#") + else message.args[0]))) + def check_nick(self, nick): """ Set up a user's account by setting the initial balance