diff --git a/pyircbot/modules/StockPlay.py b/pyircbot/modules/StockPlay.py index 11b79c9..5d32ba0 100644 --- a/pyircbot/modules/StockPlay.py +++ b/pyircbot/modules/StockPlay.py @@ -214,10 +214,29 @@ 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.cents as cents + FROM stockplay_balance_history h1 + INNER JOIN (SELECT nick, max(day) as MaxDate FROM stockplay_balance_history + WHERE nick != ? GROUP BY nick) h2 + ON h1.nick = h2.nick AND h1.day = h2.MaxDate + ORDER BY cents DESC LIMIT 10""", (DUSTACCT, )).fetchall(), start=1): + total = Decimal(row["cents"]) / 100 + self.bot.act_PRIVMSG(replyto, + "{}: {} with total: ~${}".format(num, row["nick"], total), priority=5) + def do_trade(self, trade): """ Perform a queued trade @@ -534,6 +553,16 @@ class StockPlay(ModuleBase): else message.args[0], full))) + @info("top", "show top portfolios", cmds=["top", "top10"]) + @command("top", "top10", allow_private=True) + 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