mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 19:28:25 +02:00
fixed updating embed and score counting
This commit is contained in:
parent
1766f65c2f
commit
5f14d0493a
1 changed files with 26 additions and 27 deletions
|
@ -49,7 +49,6 @@ async def on_ready():
|
||||||
|
|
||||||
message_from_sha1 = {}
|
message_from_sha1 = {}
|
||||||
old_message_from_sha1 = {}
|
old_message_from_sha1 = {}
|
||||||
old_sha1 = set()
|
|
||||||
|
|
||||||
message: discord.Message
|
message: discord.Message
|
||||||
async for message in track_channel.history(limit=5000):
|
async for message in track_channel.history(limit=5000):
|
||||||
|
@ -57,7 +56,6 @@ async def on_ready():
|
||||||
for field in message.embeds[0].fields:
|
for field in message.embeds[0].fields:
|
||||||
if "sha1" in field.name:
|
if "sha1" in field.name:
|
||||||
message_from_sha1[field.value] = message
|
message_from_sha1[field.value] = message
|
||||||
old_sha1.add(field.value)
|
|
||||||
|
|
||||||
async for message in old_track_channel.history(limit=5000):
|
async for message in old_track_channel.history(limit=5000):
|
||||||
if message.author.id == bot.user.id:
|
if message.author.id == bot.user.id:
|
||||||
|
@ -71,8 +69,12 @@ async def on_ready():
|
||||||
try:
|
try:
|
||||||
if track.name == "_": continue
|
if track.name == "_": continue
|
||||||
|
|
||||||
|
if track.sha1 in message_from_sha1:
|
||||||
|
embed = message_from_sha1[track.sha1].embeds[0]
|
||||||
|
else:
|
||||||
embed = discord.Embed(title=f"**{track.get_track_name()}**",
|
embed = discord.Embed(title=f"**{track.get_track_name()}**",
|
||||||
description="", url=f"https://ct.wiimm.de/i/{track.sha1}")
|
description="", url=f"https://ct.wiimm.de/i/{track.sha1}")
|
||||||
|
for _ in range(6): embed.add_field(name="empty", value="empty")
|
||||||
|
|
||||||
author_link = ""
|
author_link = ""
|
||||||
if "," not in track.author: author_link = "http://wiki.tockdom.com/wiki/" + track.author
|
if "," not in track.author: author_link = "http://wiki.tockdom.com/wiki/" + track.author
|
||||||
|
@ -82,38 +84,34 @@ async def on_ready():
|
||||||
|
|
||||||
if hasattr(track, "score"):
|
if hasattr(track, "score"):
|
||||||
scores = [track.score]
|
scores = [track.score]
|
||||||
if hasattr(track, "sha1"):
|
|
||||||
if track.sha1 in old_message_from_sha1:
|
if track.sha1 in old_message_from_sha1:
|
||||||
for reaction in old_message_from_sha1[track.sha1].reactions:
|
for reaction in old_message_from_sha1[track.sha1].reactions:
|
||||||
if hasattr(reaction, "id"):
|
if str(EMOTE_1STAR) in str(reaction.emoji): scores.extend([1] * (reaction.count - 1))
|
||||||
if reaction.emoji.id == EMOTE_1STAR: scores.extend([1] * (reaction.count - 1))
|
elif str(EMOTE_2STAR) in str(reaction.emoji): scores.extend([2] * (reaction.count - 1))
|
||||||
elif reaction.emoji.id == EMOTE_2STAR: scores.extend([2] * (reaction.count - 1))
|
elif str(EMOTE_3STAR) in str(reaction.emoji): scores.extend([3] * (reaction.count - 1))
|
||||||
elif reaction.emoji.id == EMOTE_3STAR: scores.extend([3] * (reaction.count - 1))
|
|
||||||
|
|
||||||
if track.sha1 in message_from_sha1:
|
if track.sha1 in message_from_sha1:
|
||||||
for reaction in message_from_sha1[track.sha1].reactions:
|
for reaction in message_from_sha1[track.sha1].reactions:
|
||||||
if hasattr(reaction, "id"):
|
if str(EMOTE_1STAR) in str(reaction.emoji): scores.extend([1] * (reaction.count - 1))
|
||||||
if reaction.emoji.id == EMOTE_1STAR: scores.extend([1] * (reaction.count - 1))
|
elif str(EMOTE_2STAR) in str(reaction.emoji): scores.extend([2] * (reaction.count - 1))
|
||||||
elif reaction.emoji.id == EMOTE_2STAR: scores.extend([2] * (reaction.count - 1))
|
elif str(EMOTE_3STAR) in str(reaction.emoji): scores.extend([3] * (reaction.count - 1))
|
||||||
elif reaction.emoji.id == EMOTE_3STAR: scores.extend([3] * (reaction.count - 1))
|
|
||||||
|
|
||||||
moy_score = round(sum(scores) / len(scores), 2)
|
moy_score = round(sum(scores) / len(scores), 2)
|
||||||
|
|
||||||
embed.add_field(name="Track Score", value=f"{moy_score} (vote : {len(scores)})")
|
embed.set_field_at(index=0, name="Track Score", value=f"{moy_score} (vote : {len(scores)})")
|
||||||
if hasattr(track, "warning"):
|
if hasattr(track, "warning"):
|
||||||
embed.add_field(name="Warning level", value=warning_level_message[track.warning])
|
embed.set_field_at(index=1, name="Warning level", value=warning_level_message[track.warning])
|
||||||
if hasattr(track, "since_version"):
|
if hasattr(track, "since_version"):
|
||||||
embed.add_field(name="Here since version", value=track.since_version)
|
embed.set_field_at(index=2, name="Here since version", value=track.since_version)
|
||||||
|
|
||||||
embed.add_field(name="Lap count", value=track_technical_data["lap_count"])
|
embed.set_field_at(index=3, name="Lap count", value=track_technical_data["lap_count"])
|
||||||
embed.add_field(name="Speed multiplier", value=track_technical_data["speed_factor"])
|
embed.set_field_at(index=4, name="Speed multiplier", value=track_technical_data["speed_factor"])
|
||||||
|
|
||||||
embed.set_image(url=placeholder_image_url) # TODO
|
embed.set_image(url=placeholder_image_url) # TODO
|
||||||
|
|
||||||
if hasattr(track, "sha1"):
|
embed.set_field_at(index=5, name="sha1", value=track.sha1)
|
||||||
embed.add_field(name="sha1", value=track.sha1)
|
|
||||||
|
|
||||||
if track.sha1 not in old_sha1:
|
if track.sha1 not in message_from_sha1:
|
||||||
|
|
||||||
with io.BytesIO() as image_binary:
|
with io.BytesIO() as image_binary:
|
||||||
image = get_track_minimap(track)
|
image = get_track_minimap(track)
|
||||||
|
@ -132,7 +130,8 @@ async def on_ready():
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if hasattr(track, "sha1"):
|
if hasattr(track, "sha1"):
|
||||||
await message_from_sha1[track.sha1].edit(embed=embed)
|
message = message_from_sha1[track.sha1]
|
||||||
|
await message.edit(embed=embed)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"error for track {track.name} : {str(e)}")
|
print(f"error for track {track.name} : {str(e)}")
|
||||||
|
|
Loading…
Reference in a new issue