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
@ -207,4 +207,18 @@ class RedisQueue:
|
|||||||
if exists:
|
if exists:
|
||||||
await self.delete_guild(guild)
|
await self.delete_guild(guild)
|
||||||
await self.on_get_guild(key, {"guild_id": guild.id})
|
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=(',', ':')))
|
@ -435,19 +435,9 @@ def voting_get():
|
|||||||
users = db.session.query(DiscordBotsOrgTransactions).filter(DiscordBotsOrgTransactions.timestamp >= start, DiscordBotsOrgTransactions.timestamp <= end).order_by(DiscordBotsOrgTransactions.timestamp)
|
users = db.session.query(DiscordBotsOrgTransactions).filter(DiscordBotsOrgTransactions.timestamp >= start, DiscordBotsOrgTransactions.timestamp <= end).order_by(DiscordBotsOrgTransactions.timestamp)
|
||||||
all_users = []
|
all_users = []
|
||||||
for u in 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({
|
all_users.append({
|
||||||
"id": u.id,
|
"id": u.id,
|
||||||
"user_id": uid,
|
"user_id": u.user_id,
|
||||||
"timestamp": u.timestamp,
|
"timestamp": u.timestamp,
|
||||||
"action": u.action,
|
"action": u.action,
|
||||||
"referrer": u.referrer
|
"referrer": u.referrer
|
||||||
@ -458,8 +448,6 @@ def voting_get():
|
|||||||
action = u["action"]
|
action = u["action"]
|
||||||
if uid not in overall_votes:
|
if uid not in overall_votes:
|
||||||
overall_votes[uid] = 0
|
overall_votes[uid] = 0
|
||||||
if action == "none":
|
|
||||||
overall_votes[uid] = overall_votes[uid] - 1
|
|
||||||
if action == "upvote":
|
if action == "upvote":
|
||||||
overall_votes[uid] = overall_votes[uid] + 1
|
overall_votes[uid] = overall_votes[uid] + 1
|
||||||
sorted_overall_votes = []
|
sorted_overall_votes = []
|
||||||
@ -467,13 +455,13 @@ def voting_get():
|
|||||||
sorted_overall_votes.append(uid)
|
sorted_overall_votes.append(uid)
|
||||||
overall = []
|
overall = []
|
||||||
for uid in sorted_overall_votes:
|
for uid in sorted_overall_votes:
|
||||||
gmember = db.session.query(GuildMembers).filter(GuildMembers.user_id == uid).first()
|
gmember = redisqueue.get_user(uid)
|
||||||
u = {
|
u = {
|
||||||
"user_id": uid,
|
"user_id": uid,
|
||||||
"votes": overall_votes[uid]
|
"votes": overall_votes[uid]
|
||||||
}
|
}
|
||||||
if gmember:
|
if gmember:
|
||||||
u["discord"] = gmember.username + "#" + str(gmember.discriminator)
|
u["discord"] = gmember["username"] + "#" + str(gmember["discriminator"])
|
||||||
overall.append(u)
|
overall.append(u)
|
||||||
referrer = {}
|
referrer = {}
|
||||||
for u in all_users:
|
for u in all_users:
|
||||||
@ -488,12 +476,12 @@ def voting_get():
|
|||||||
sorted_referrers.append(uid)
|
sorted_referrers.append(uid)
|
||||||
referrals = []
|
referrals = []
|
||||||
for uid in sorted_referrers:
|
for uid in sorted_referrers:
|
||||||
gmember = db.session.query(GuildMembers).filter(GuildMembers.user_id == uid).first()
|
gmember = redisqueue.get_user(uid)
|
||||||
u = {
|
u = {
|
||||||
"user_id": uid,
|
"user_id": uid,
|
||||||
"votes": referrer[uid]
|
"votes": referrer[uid]
|
||||||
}
|
}
|
||||||
if gmember:
|
if gmember:
|
||||||
u["discord"] = gmember.username + "#" + str(gmember.discriminator)
|
u["discord"] = gmember["username"] + "#" + str(gmember["discriminator"])
|
||||||
referrals.append(u)
|
referrals.append(u)
|
||||||
return render_template("admin_voting.html.j2", overall=overall, referrals=referrals, datestart=datestart, timestart=timestart, dateend=dateend, timeend=timeend)
|
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))
|
params = dict(parse_qsl(urlsplit(incoming.get("query", "")).query))
|
||||||
if vote_type == "upvote":
|
if vote_type == "upvote":
|
||||||
redis_store.set("DiscordBotsOrgVoted/" + user_id, "voted", 86400)
|
redis_store.set("DiscordBotsOrgVoted/" + user_id, "voted", 86400)
|
||||||
else:
|
|
||||||
redis_store.delete("DiscordBotsOrgVoted/" + user_id)
|
|
||||||
referrer = None
|
referrer = None
|
||||||
if "referrer" in params:
|
if "referrer" in params:
|
||||||
try:
|
try:
|
||||||
|
@ -113,4 +113,9 @@ class RedisQueue:
|
|||||||
def get_guild(self, guild_id):
|
def get_guild(self, guild_id):
|
||||||
key = "/guilds/{}".format(guild_id)
|
key = "/guilds/{}".format(guild_id)
|
||||||
q = self.get(key, "get_guild", {"guild_id": 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
|
return q
|
Loading…
Reference in New Issue
Block a user