mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-12-24 14:07:03 +01:00
Fix admin voting page crash
This commit is contained in:
parent
1e80512ca7
commit
0203f24ce7
@ -208,3 +208,17 @@ class RedisQueue:
|
||||
await self.delete_guild(guild)
|
||||
await self.on_get_guild(key, {"guild_id": guild.id})
|
||||
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=(',', ':')))
|
@ -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)
|
@ -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:
|
||||
|
@ -114,3 +114,8 @@ class RedisQueue:
|
||||
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
|
Loading…
Reference in New Issue
Block a user