Fix admin voting page crash

This commit is contained in:
Jeremy Zhang 2018-07-23 05:02:26 +00:00
parent 1e80512ca7
commit 0203f24ce7
4 changed files with 25 additions and 20 deletions

View File

@ -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)
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=(',', ':')))

View File

@ -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)

View File

@ -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:

View File

@ -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