From 6b9fd384ec528dca518f18d14073e0bd26187c8a Mon Sep 17 00:00:00 2001 From: Mike Edmister Date: Tue, 23 Apr 2019 13:31:02 -0400 Subject: [PATCH 1/8] .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 From 6404adb7733ffa979d2f3b69a3aaf512825af877 Mon Sep 17 00:00:00 2001 From: Mike Edmister Date: Tue, 23 Apr 2019 13:33:13 -0400 Subject: [PATCH 2/8] limit 10 --- pyircbot/modules/StockPlay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyircbot/modules/StockPlay.py b/pyircbot/modules/StockPlay.py index 5d5856e..40ff8c6 100644 --- a/pyircbot/modules/StockPlay.py +++ b/pyircbot/modules/StockPlay.py @@ -159,7 +159,7 @@ class StockPlay(ModuleBase): 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): + ORDER BY total DESC LIMIT 10""").fetchall(), start=1): self.bot.act_PRIVMSG(replyto, "{}: {} with total: ~{}".format(num, row.nick, row.total)) From 2533c5872a3212bd6ecf390149e0ddb6ed2e02cb Mon Sep 17 00:00:00 2001 From: Mike Edmister Date: Thu, 25 Apr 2019 10:27:55 -0400 Subject: [PATCH 3/8] lowered priority of .top, fixed query, removed @protected --- pyircbot/irccore.py | 4 ++-- pyircbot/modules/StockPlay.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pyircbot/irccore.py b/pyircbot/irccore.py index 3c8797d..7d80165 100644 --- a/pyircbot/irccore.py +++ b/pyircbot/irccore.py @@ -346,14 +346,14 @@ class IRCCore(object): :type channel: str""" self.sendRaw("JOIN %s" % channel, priority=3) - def act_PRIVMSG(self, towho, message): + def act_PRIVMSG(self, towho, message, priority=None): """Use the `/msg` command :param towho: the target #channel or user's name :type towho: str :param message: the message to send :type message: str""" - self.sendRaw("PRIVMSG %s :%s" % (towho, message)) + self.sendRaw("PRIVMSG %s :%s" % (towho, message), priority=priority) def act_MODE(self, channel, mode, extra=None): """Use the `/mode` command diff --git a/pyircbot/modules/StockPlay.py b/pyircbot/modules/StockPlay.py index 40ff8c6..a1fa274 100644 --- a/pyircbot/modules/StockPlay.py +++ b/pyircbot/modules/StockPlay.py @@ -156,12 +156,13 @@ class StockPlay(ModuleBase): 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 + for num, row in enumerate(c.execute("""SELECT h1.nick as nick, CAST(h1.cents as INTEGER) 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 total DESC LIMIT 10""").fetchall(), start=1): - - self.bot.act_PRIVMSG(replyto, "{}: {} with total: ~{}".format(num, row.nick, row.total)) + 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): """ @@ -470,7 +471,6 @@ class StockPlay(ModuleBase): @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 From ca3b4f903fd5ea3edd679f71970cffeef686c084 Mon Sep 17 00:00:00 2001 From: Mike Edmister Date: Thu, 25 Apr 2019 10:32:14 -0400 Subject: [PATCH 4/8] revert irccore --- pyircbot/irccore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyircbot/irccore.py b/pyircbot/irccore.py index 7d80165..3c8797d 100644 --- a/pyircbot/irccore.py +++ b/pyircbot/irccore.py @@ -346,14 +346,14 @@ class IRCCore(object): :type channel: str""" self.sendRaw("JOIN %s" % channel, priority=3) - def act_PRIVMSG(self, towho, message, priority=None): + def act_PRIVMSG(self, towho, message): """Use the `/msg` command :param towho: the target #channel or user's name :type towho: str :param message: the message to send :type message: str""" - self.sendRaw("PRIVMSG %s :%s" % (towho, message), priority=priority) + self.sendRaw("PRIVMSG %s :%s" % (towho, message)) def act_MODE(self, channel, mode, extra=None): """Use the `/mode` command From bdfadb0c11fc7112fef71d23594d300988145540 Mon Sep 17 00:00:00 2001 From: Mike Edmister Date: Thu, 25 Apr 2019 11:47:04 -0400 Subject: [PATCH 5/8] shortened lines for linter --- pyircbot/modules/StockPlay.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyircbot/modules/StockPlay.py b/pyircbot/modules/StockPlay.py index a1fa274..370ea00 100644 --- a/pyircbot/modules/StockPlay.py +++ b/pyircbot/modules/StockPlay.py @@ -156,8 +156,10 @@ class StockPlay(ModuleBase): 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, CAST(h1.cents as INTEGER) 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 + for num, row in enumerate(c.execute("""SELECT h1.nick as nick, CAST(h1.cents as INTEGER) 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 From f6b6c13c1272925111c4a9b074e9296f670da802 Mon Sep 17 00:00:00 2001 From: Mike Edmister Date: Thu, 25 Apr 2019 11:49:04 -0400 Subject: [PATCH 6/8] removed cast needed because of wrong column type --- pyircbot/modules/StockPlay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyircbot/modules/StockPlay.py b/pyircbot/modules/StockPlay.py index 370ea00..43f1ec0 100644 --- a/pyircbot/modules/StockPlay.py +++ b/pyircbot/modules/StockPlay.py @@ -156,7 +156,7 @@ class StockPlay(ModuleBase): 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, CAST(h1.cents as INTEGER) as cents + 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 From f9927e9acbd54ed2cf717550ad33be423b542312 Mon Sep 17 00:00:00 2001 From: Mike Edmister Date: Thu, 25 Apr 2019 11:55:26 -0400 Subject: [PATCH 7/8] added $ and changed from .thing to ['thing'] --- pyircbot/modules/StockPlay.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyircbot/modules/StockPlay.py b/pyircbot/modules/StockPlay.py index 43f1ec0..7d2a6b5 100644 --- a/pyircbot/modules/StockPlay.py +++ b/pyircbot/modules/StockPlay.py @@ -162,9 +162,9 @@ class StockPlay(ModuleBase): 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 + total = Decimal(row['cents']) / 100 self.bot.act_PRIVMSG(replyto, - "{}: {} with total: ~{}".format(num, row.nick, total), priority=5) + "{}: {} with total: ~${}".format(num, row['nick'], total), priority=5) def do_trade(self, trade): """ From b4b6d72607c7174532676f9f9f5671228ee992a8 Mon Sep 17 00:00:00 2001 From: Mike Edmister Date: Thu, 25 Apr 2019 11:57:12 -0400 Subject: [PATCH 8/8] doublequotes over single --- pyircbot/modules/StockPlay.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyircbot/modules/StockPlay.py b/pyircbot/modules/StockPlay.py index 7d2a6b5..1a73cda 100644 --- a/pyircbot/modules/StockPlay.py +++ b/pyircbot/modules/StockPlay.py @@ -162,9 +162,9 @@ class StockPlay(ModuleBase): 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 + total = Decimal(row["cents"]) / 100 self.bot.act_PRIVMSG(replyto, - "{}: {} with total: ~${}".format(num, row['nick'], total), priority=5) + "{}: {} with total: ~${}".format(num, row["nick"], total), priority=5) def do_trade(self, trade): """