mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 03:08:29 +02:00
implemented score calculus
This commit is contained in:
parent
3d5372acc6
commit
1766f65c2f
1 changed files with 28 additions and 3 deletions
|
@ -12,6 +12,7 @@ from scripts.minimap import obj_to_png
|
|||
bot = discord.Client()
|
||||
SERVER_ID = 842865613918699590
|
||||
TRACK_CHANNEL_ID = 871100630251499530
|
||||
OLD_TRACK_CHANNEL_ID = 842867283428507699 # previous channel used by the program to get score
|
||||
DATA_CHANNEL_ID = 871469647617216652
|
||||
|
||||
warning_level_message = [
|
||||
|
@ -43,9 +44,11 @@ def get_track_minimap(track: Track):
|
|||
async def on_ready():
|
||||
guild: discord.Guild = bot.get_guild(id=SERVER_ID)
|
||||
track_channel: discord.TextChannel = guild.get_channel(channel_id=TRACK_CHANNEL_ID)
|
||||
old_track_channel: discord.TextChannel = guild.get_channel(channel_id=OLD_TRACK_CHANNEL_ID)
|
||||
data_channel: discord.TextChannel = guild.get_channel(channel_id=DATA_CHANNEL_ID)
|
||||
|
||||
message_from_sha1 = {}
|
||||
old_message_from_sha1 = {}
|
||||
old_sha1 = set()
|
||||
|
||||
message: discord.Message
|
||||
|
@ -56,6 +59,11 @@ async def on_ready():
|
|||
message_from_sha1[field.value] = message
|
||||
old_sha1.add(field.value)
|
||||
|
||||
async for message in old_track_channel.history(limit=5000):
|
||||
if message.author.id == bot.user.id:
|
||||
sha1 = message.content.split("ct.wiimm.de/i/")[-1].replace("|", "").strip()
|
||||
old_message_from_sha1[sha1] = message
|
||||
|
||||
ct_config = CT_Config()
|
||||
ct_config.load_ctconfig_file("./ct_config.json")
|
||||
|
||||
|
@ -73,7 +81,25 @@ async def on_ready():
|
|||
track_technical_data = szs.analyze(track.file_szs)
|
||||
|
||||
if hasattr(track, "score"):
|
||||
embed.add_field(name="Track Score", value=track.score) # TODO
|
||||
scores = [track.score]
|
||||
if hasattr(track, "sha1"):
|
||||
if track.sha1 in old_message_from_sha1:
|
||||
for reaction in old_message_from_sha1[track.sha1].reactions:
|
||||
if hasattr(reaction, "id"):
|
||||
if reaction.emoji.id == EMOTE_1STAR: scores.extend([1] * (reaction.count - 1))
|
||||
elif reaction.emoji.id == EMOTE_2STAR: scores.extend([2] * (reaction.count - 1))
|
||||
elif reaction.emoji.id == EMOTE_3STAR: scores.extend([3] * (reaction.count - 1))
|
||||
|
||||
if track.sha1 in message_from_sha1:
|
||||
for reaction in message_from_sha1[track.sha1].reactions:
|
||||
if hasattr(reaction, "id"):
|
||||
if reaction.emoji.id == EMOTE_1STAR: scores.extend([1] * (reaction.count - 1))
|
||||
elif reaction.emoji.id == EMOTE_2STAR: scores.extend([2] * (reaction.count - 1))
|
||||
elif reaction.emoji.id == EMOTE_3STAR: scores.extend([3] * (reaction.count - 1))
|
||||
|
||||
moy_score = round(sum(scores) / len(scores), 2)
|
||||
|
||||
embed.add_field(name="Track Score", value=f"{moy_score} (vote : {len(scores)})")
|
||||
if hasattr(track, "warning"):
|
||||
embed.add_field(name="Warning level", value=warning_level_message[track.warning])
|
||||
if hasattr(track, "since_version"):
|
||||
|
@ -104,12 +130,11 @@ async def on_ready():
|
|||
await message.add_reaction(bot.get_emoji(EMOTE_3STAR))
|
||||
await message.add_reaction("❌")
|
||||
|
||||
|
||||
else:
|
||||
if hasattr(track, "sha1"):
|
||||
await message_from_sha1[track.sha1].edit(embed=embed)
|
||||
|
||||
except Exception as e:
|
||||
print(f'error in track {track.name} : {str(e)}')
|
||||
print(f"error for track {track.name} : {str(e)}")
|
||||
|
||||
bot.run(os.environ['DISCORD_GR_TOKEN'])
|
||||
|
|
Loading…
Reference in a new issue