diff --git a/discordbot/titanembeds/redisqueue.py b/discordbot/titanembeds/redisqueue.py index 10daae7..e6a7139 100644 --- a/discordbot/titanembeds/redisqueue.py +++ b/discordbot/titanembeds/redisqueue.py @@ -207,4 +207,18 @@ class RedisQueue: if exists: await self.delete_guild(guild) await self.on_get_guild(key, {"guild_id": guild.id}) - await self.enforce_expiring_key(key) \ No newline at end of file + await self.enforce_expiring_key(key) + + async def on_get_user(self, key, params): + user = self.bot.get_user(int(params["user_id"])) + if not user: + await self.connection.set(key, "") + return + user_formatted = { + "id": user.id, + "username": user.name, + "discriminator": user.discriminator, + "avatar": user.avatar, + "bot": user.bot + } + await self.connection.set(key, json.dumps(user_formatted, separators=(',', ':'))) \ No newline at end of file diff --git a/webapp/titanembeds/blueprints/admin/admin.py b/webapp/titanembeds/blueprints/admin/admin.py index fad8d66..81009a8 100644 --- a/webapp/titanembeds/blueprints/admin/admin.py +++ b/webapp/titanembeds/blueprints/admin/admin.py @@ -435,19 +435,9 @@ def voting_get(): users = db.session.query(DiscordBotsOrgTransactions).filter(DiscordBotsOrgTransactions.timestamp >= start, DiscordBotsOrgTransactions.timestamp <= end).order_by(DiscordBotsOrgTransactions.timestamp) all_users = [] for u in users: - uid = u.user_id # Let's fix this OBO error - gmember = db.session.query(GuildMembers).filter(GuildMembers.user_id == uid).first() - count = 0 - if not gmember: - uid = uid - 10 - while uid < u.user_id + 10: - gmember = db.session.query(GuildMembers).filter(GuildMembers.user_id == uid).first() - if gmember: - break - uid = uid + 1 all_users.append({ "id": u.id, - "user_id": uid, + "user_id": u.user_id, "timestamp": u.timestamp, "action": u.action, "referrer": u.referrer @@ -458,8 +448,6 @@ def voting_get(): action = u["action"] if uid not in overall_votes: overall_votes[uid] = 0 - if action == "none": - overall_votes[uid] = overall_votes[uid] - 1 if action == "upvote": overall_votes[uid] = overall_votes[uid] + 1 sorted_overall_votes = [] @@ -467,13 +455,13 @@ def voting_get(): sorted_overall_votes.append(uid) overall = [] for uid in sorted_overall_votes: - gmember = db.session.query(GuildMembers).filter(GuildMembers.user_id == uid).first() + gmember = redisqueue.get_user(uid) u = { "user_id": uid, "votes": overall_votes[uid] } if gmember: - u["discord"] = gmember.username + "#" + str(gmember.discriminator) + u["discord"] = gmember["username"] + "#" + str(gmember["discriminator"]) overall.append(u) referrer = {} for u in all_users: @@ -488,12 +476,12 @@ def voting_get(): sorted_referrers.append(uid) referrals = [] for uid in sorted_referrers: - gmember = db.session.query(GuildMembers).filter(GuildMembers.user_id == uid).first() + gmember = redisqueue.get_user(uid) u = { "user_id": uid, "votes": referrer[uid] } if gmember: - u["discord"] = gmember.username + "#" + str(gmember.discriminator) + u["discord"] = gmember["username"] + "#" + str(gmember["discriminator"]) referrals.append(u) return render_template("admin_voting.html.j2", overall=overall, referrals=referrals, datestart=datestart, timestart=timestart, dateend=dateend, timeend=timeend) \ No newline at end of file diff --git a/webapp/titanembeds/blueprints/api/api.py b/webapp/titanembeds/blueprints/api/api.py index e1db860..56fe4e5 100644 --- a/webapp/titanembeds/blueprints/api/api.py +++ b/webapp/titanembeds/blueprints/api/api.py @@ -540,8 +540,6 @@ def webhook_discordbotsorg_vote(): params = dict(parse_qsl(urlsplit(incoming.get("query", "")).query)) if vote_type == "upvote": redis_store.set("DiscordBotsOrgVoted/" + user_id, "voted", 86400) - else: - redis_store.delete("DiscordBotsOrgVoted/" + user_id) referrer = None if "referrer" in params: try: diff --git a/webapp/titanembeds/redisqueue.py b/webapp/titanembeds/redisqueue.py index 1936ea4..52556d7 100644 --- a/webapp/titanembeds/redisqueue.py +++ b/webapp/titanembeds/redisqueue.py @@ -113,4 +113,9 @@ class RedisQueue: def get_guild(self, guild_id): key = "/guilds/{}".format(guild_id) q = self.get(key, "get_guild", {"guild_id": guild_id}) + return q + + def get_user(self, user_id): + key = "/users/{}".format(user_id) + q = self.get(key, "get_user", {"user_id": user_id}) return q \ No newline at end of file