Skip to content

Commit cccbfcc

Browse files
committed
fix: remove decorators as its not working with async open-telemetry/opentelemetry-python#3270
Signed-off-by: QuentinN42 <[email protected]>
1 parent c0c52d2 commit cccbfcc

File tree

1 file changed

+158
-142
lines changed

1 file changed

+158
-142
lines changed

bot/discord/main.py

+158-142
Original file line numberDiff line numberDiff line change
@@ -523,136 +523,152 @@ async def on_raw_reaction_add(payload):
523523
log("end on_raw_reaction_add")
524524

525525

526-
@TRACER.start_as_current_span("appelInscription")
527526
async def appelInscription(user, emote, jour):
528527
"""Inscrit le joueur en fonction de ca reaction
529528
530529
User = ID du joueur
531530
emote = ID de l'emote
532531
jour = numéro du jour
533532
"""
534-
if str(user.id) == secrets.CLIENT_ID:
535-
# c le bot :(
536-
return
537-
538-
logchannel = bot.get_channel(secrets.LOG_CHANNEL_ID)
539-
540-
if emote == secrets.DIS_EMOTE_ID:
541-
statut = inscription.add(user.id, jour, ["GV"]) # essaye d'inscrire la personne
542-
elif emote == secrets.CDS_EMOTE_ID:
543-
statut = inscription.add(
544-
user.id, jour, ["CDS"]
545-
) # essaye d'inscrire la personne
546-
elif emote == secrets.CDG_EMOTE_ID:
547-
statut = inscription.add(
548-
user.id, jour, ["CDG"]
549-
) # essaye d'inscrire la personne
550-
elif emote == secrets.CDE_EMOTE_ID:
551-
statut = inscription.add(
552-
user.id, jour, ["CDE"]
553-
) # essaye d'inscrire la personne
554-
elif emote == secrets.MED_EMOTE_ID:
555-
statut = inscription.add(
556-
user.id, jour, ["Médecin"]
557-
) # essaye d'inscrire la personne
558-
elif emote == secrets.MINI_EMOTE_ID:
559-
statut = inscription.add(
560-
user.id, jour, ["Minimi"]
561-
) # essaye d'inscrire la personne
562-
else:
563-
statut = inscription.add(user.id, jour) # essaye d'inscrire la personne
564-
565-
log(f" statut {statut}")
566-
if statut == 0:
567-
# deja inscrit
568-
return
569-
elif statut == 1:
570-
# succes
571-
return
572-
elif statut == 2: # Utilisateur pas dans la liste
573-
err = (
574-
user.display_name
575-
+ " (Id = `"
576-
+ str(user.id)
577-
+ "`) n'a pas pu être inscrit."
578-
)
579-
print("Ajout de l'utilisateur : ", user.display_name)
580-
inscription.addUser(user.display_name, str(user.id))
581-
print("utilisateur ajouté")
582-
err += (
583-
'\n:white_check_mark: Ajout de "'
584-
+ user.display_name
585-
+ "\" avec l'id ``"
586-
+ str(user.id)
587-
+ "``"
588-
)
589-
trace.get_current_span().set_status(StatusCode.ERROR)
590-
print(err)
591-
# reinscrit
592-
await logchannel.send(err)
593-
await appelInscription(user, emote, jour)
594-
return
595-
else:
596-
err = "ERREUR Inscription :" + user.display_name + " id `" + str(user.id) + "`"
597-
return
533+
with TRACER.start_as_current_span("appelInscription"):
534+
if str(user.id) == secrets.CLIENT_ID:
535+
# c le bot :(
536+
return
537+
538+
logchannel = bot.get_channel(secrets.LOG_CHANNEL_ID)
539+
540+
if emote == secrets.DIS_EMOTE_ID:
541+
statut = inscription.add(
542+
user.id, jour, ["GV"]
543+
) # essaye d'inscrire la personne
544+
elif emote == secrets.CDS_EMOTE_ID:
545+
statut = inscription.add(
546+
user.id, jour, ["CDS"]
547+
) # essaye d'inscrire la personne
548+
elif emote == secrets.CDG_EMOTE_ID:
549+
statut = inscription.add(
550+
user.id, jour, ["CDG"]
551+
) # essaye d'inscrire la personne
552+
elif emote == secrets.CDE_EMOTE_ID:
553+
statut = inscription.add(
554+
user.id, jour, ["CDE"]
555+
) # essaye d'inscrire la personne
556+
elif emote == secrets.MED_EMOTE_ID:
557+
statut = inscription.add(
558+
user.id, jour, ["Médecin"]
559+
) # essaye d'inscrire la personne
560+
elif emote == secrets.MINI_EMOTE_ID:
561+
statut = inscription.add(
562+
user.id, jour, ["Minimi"]
563+
) # essaye d'inscrire la personne
564+
else:
565+
statut = inscription.add(user.id, jour) # essaye d'inscrire la personne
566+
567+
log(f" statut {statut}")
568+
if statut == 0:
569+
# deja inscrit
570+
return
571+
elif statut == 1:
572+
# succes
573+
return
574+
elif statut == 2: # Utilisateur pas dans la liste
575+
err = (
576+
user.display_name
577+
+ " (Id = `"
578+
+ str(user.id)
579+
+ "`) n'a pas pu être inscrit."
580+
)
581+
print("Ajout de l'utilisateur : ", user.display_name)
582+
inscription.addUser(user.display_name, str(user.id))
583+
print("utilisateur ajouté")
584+
err += (
585+
'\n:white_check_mark: Ajout de "'
586+
+ user.display_name
587+
+ "\" avec l'id ``"
588+
+ str(user.id)
589+
+ "``"
590+
)
591+
trace.get_current_span().set_status(StatusCode.ERROR)
592+
print(err)
593+
# reinscrit
594+
await logchannel.send(err)
595+
await appelInscription(user, emote, jour)
596+
return
597+
else:
598+
err = (
599+
"ERREUR Inscription :"
600+
+ user.display_name
601+
+ " id `"
602+
+ str(user.id)
603+
+ "`"
604+
)
605+
return
598606

599607

600-
# Ajoute le DLC au joueur en fonction de ca reaction
601-
# User = ID du joueur
602-
# emote = ID de l'emote
603-
@TRACER.start_as_current_span("appelDLC")
604608
async def appelDLC(user, emote, state):
605-
logchannel = bot.get_channel(secrets.LOG_CHANNEL_ID)
609+
"""Ajoute le DLC au joueur en fonction de ca reaction
606610
607-
if emote == secrets.KART_DLC_EMOTE_ID:
608-
statut = inscription.stateDLC(user.id, 0, state)
609-
elif emote == secrets.HELI_DLC_EMOTE_ID:
610-
statut = inscription.stateDLC(user.id, 1, state)
611-
elif emote == secrets.MARK_DLC_EMOTE_ID:
612-
statut = inscription.stateDLC(user.id, 2, state)
613-
elif emote == secrets.APEX_DLC_EMOTE_ID:
614-
statut = inscription.stateDLC(user.id, 3, state)
615-
elif emote == secrets.JETS_DLC_EMOTE_ID:
616-
statut = inscription.stateDLC(user.id, 4, state)
617-
elif emote == secrets.TANKS_DLC_EMOTE_ID:
618-
statut = inscription.stateDLC(user.id, 5, state)
619-
elif emote == secrets.LOW_DLC_EMOTE_ID:
620-
statut = inscription.stateDLC(user.id, 6, state)
621-
elif emote == secrets.GBMOB_DLC_EMOTE_ID:
622-
statut = inscription.stateDLC(user.id, 7, state)
623-
elif emote == secrets.CONTACT_DLC_EMOTE_ID:
624-
statut = inscription.stateDLC(user.id, 8, state)
625-
elif emote == secrets.PRAIRIEFIRE_DLC_EMOTE_ID:
626-
statut = inscription.stateDLC(user.id, 9, state)
627-
elif emote == secrets.WESTERNSAHARA_DLC_EMOTE_ID:
628-
statut = inscription.stateDLC(user.id, 10, state)
629-
630-
if statut == 1: # succes
631-
err = ""
632-
await SetActivity("Compter les DLCs de " + user.display_name)
633-
elif statut == 2: # Utilisateur pas dans la liste
634-
err = (
635-
user.display_name
636-
+ " (Id = `"
637-
+ str(user.id)
638-
+ "`) n'es pas dans la fiche Technique."
639-
)
640-
inscription.addUser(user.display_name, str(user.id))
641-
err += (
642-
'\n:white_check_mark: Ajout de "'
643-
+ user.display_name
644-
+ "\" avec l'id ``"
645-
+ str(user.id)
646-
+ "``"
647-
)
648-
else:
649-
err = "ERREUR Reaction DLC :" + user.display_name + " id `" + str(user.id) + "`"
611+
User = ID du joueur
612+
emote = ID de l'emote
613+
"""
614+
with TRACER.start_as_current_span("appelDLC"):
615+
logchannel = bot.get_channel(secrets.LOG_CHANNEL_ID)
616+
617+
if emote == secrets.KART_DLC_EMOTE_ID:
618+
statut = inscription.stateDLC(user.id, 0, state)
619+
elif emote == secrets.HELI_DLC_EMOTE_ID:
620+
statut = inscription.stateDLC(user.id, 1, state)
621+
elif emote == secrets.MARK_DLC_EMOTE_ID:
622+
statut = inscription.stateDLC(user.id, 2, state)
623+
elif emote == secrets.APEX_DLC_EMOTE_ID:
624+
statut = inscription.stateDLC(user.id, 3, state)
625+
elif emote == secrets.JETS_DLC_EMOTE_ID:
626+
statut = inscription.stateDLC(user.id, 4, state)
627+
elif emote == secrets.TANKS_DLC_EMOTE_ID:
628+
statut = inscription.stateDLC(user.id, 5, state)
629+
elif emote == secrets.LOW_DLC_EMOTE_ID:
630+
statut = inscription.stateDLC(user.id, 6, state)
631+
elif emote == secrets.GBMOB_DLC_EMOTE_ID:
632+
statut = inscription.stateDLC(user.id, 7, state)
633+
elif emote == secrets.CONTACT_DLC_EMOTE_ID:
634+
statut = inscription.stateDLC(user.id, 8, state)
635+
elif emote == secrets.PRAIRIEFIRE_DLC_EMOTE_ID:
636+
statut = inscription.stateDLC(user.id, 9, state)
637+
elif emote == secrets.WESTERNSAHARA_DLC_EMOTE_ID:
638+
statut = inscription.stateDLC(user.id, 10, state)
639+
640+
if statut == 1: # succes
641+
err = ""
642+
await SetActivity("Compter les DLCs de " + user.display_name)
643+
elif statut == 2: # Utilisateur pas dans la liste
644+
err = (
645+
user.display_name
646+
+ " (Id = `"
647+
+ str(user.id)
648+
+ "`) n'es pas dans la fiche Technique."
649+
)
650+
inscription.addUser(user.display_name, str(user.id))
651+
err += (
652+
'\n:white_check_mark: Ajout de "'
653+
+ user.display_name
654+
+ "\" avec l'id ``"
655+
+ str(user.id)
656+
+ "``"
657+
)
658+
else:
659+
err = (
660+
"ERREUR Reaction DLC :"
661+
+ user.display_name
662+
+ " id `"
663+
+ str(user.id)
664+
+ "`"
665+
)
650666

651-
if (
652-
str(user.id) != secrets.CLIENT_ID and err != ""
653-
): # si l'utilisateur n'est pas le bot
654-
await logchannel.send(err)
655-
await appelDLC(user, emote, state)
667+
if (
668+
str(user.id) != secrets.CLIENT_ID and err != ""
669+
): # si l'utilisateur n'est pas le bot
670+
await logchannel.send(err)
671+
await appelDLC(user, emote, state)
656672

657673

658674
# quand une réaction est enlevée
@@ -731,35 +747,35 @@ async def on_raw_reaction_remove(payload):
731747
await appelDLC(user, payload.emoji.id, 0)
732748

733749

734-
@TRACER.start_as_current_span("updateMessage")
735750
async def updateMessage(msg):
736751
"""met a jour le message
737752
738753
est appellé par l'ajout ou la suppresion de reaction
739754
"""
740-
log(" updateMessage")
741-
jourNom = [
742-
"",
743-
"Lundi",
744-
"Mardi",
745-
"Mercredi",
746-
"Jeudi",
747-
"Vendredi",
748-
"Samedi",
749-
"Dimanche",
750-
]
751-
jour = utils.jour(msg.content) # récupère le jours du message
752-
753-
newmsg = inscription.message(jour) # crée le nouveau message
754-
# print("Message : ", newmsg)
755-
if newmsg != 0:
756-
if newmsg != msg: # si le nouveau message est different de l'ancien
757-
await msg.edit(content=newmsg) # modifie le message
758-
# print(jour)
759-
await SetActivity(
760-
str(inscription.missionName(jour) + " " + jourNom[jour] + " soir")
761-
)
762-
log(" end updateMessage")
755+
with TRACER.start_as_current_span("updateMessage"):
756+
log(" updateMessage")
757+
jourNom = [
758+
"",
759+
"Lundi",
760+
"Mardi",
761+
"Mercredi",
762+
"Jeudi",
763+
"Vendredi",
764+
"Samedi",
765+
"Dimanche",
766+
]
767+
jour = utils.jour(msg.content) # récupère le jours du message
768+
769+
newmsg = inscription.message(jour) # crée le nouveau message
770+
# print("Message : ", newmsg)
771+
if newmsg != 0:
772+
if newmsg != msg: # si le nouveau message est different de l'ancien
773+
await msg.edit(content=newmsg) # modifie le message
774+
# print(jour)
775+
await SetActivity(
776+
str(inscription.missionName(jour) + " " + jourNom[jour] + " soir")
777+
)
778+
log(" end updateMessage")
763779

764780

765781
# toutes les heures, execute :

0 commit comments

Comments
 (0)