99
1010# Custom modules
1111from utils .json_hooks import dateconverter , dateparser , int_keys
12- from utils .command_checks import tournament_is_pending , tournament_is_underway , tournament_is_underway_or_pending , in_channel , is_streaming , is_owner_or_to
12+ from utils .command_checks import tournament_is_pending , tournament_is_underway , tournament_is_underway_or_pending , in_channel , is_streaming , is_owner_or_to , inscriptions_still_open
1313from utils .stream import is_on_stream , is_queued_for_stream
1414from utils .rounds import is_top8 , nom_round
1515from utils .game_specs import get_access_stream
@@ -125,7 +125,6 @@ async def init_tournament(url_or_id):
125125
126126 with open (tournoi_path , 'w' ) as f : json .dump (tournoi , f , indent = 4 , default = dateconverter )
127127 with open (participants_path , 'w' ) as f : json .dump ({}, f , indent = 4 )
128- with open (waiting_list_path , 'w' ) as f : json .dump ({}, f , indent = 4 )
129128 with open (stream_path , 'w' ) as f : json .dump ({}, f , indent = 4 )
130129
131130 await annonce_inscription ()
@@ -306,7 +305,6 @@ async def end_tournament(ctx):
306305
307306 # Reset JSON storage
308307 with open (participants_path , 'w' ) as f : json .dump ({}, f , indent = 4 )
309- with open (waiting_list_path , 'w' ) as f : json .dump ({}, f , indent = 4 )
310308 with open (tournoi_path , 'w' ) as f : json .dump ({}, f , indent = 4 )
311309 with open (stream_path , 'w' ) as f : json .dump ({}, f , indent = 4 )
312310
@@ -419,7 +417,6 @@ async def annonce_inscription():
419417async def inscrire (member ):
420418
421419 with open (participants_path , 'r+' ) as f : participants = json .load (f , object_pairs_hook = int_keys )
422- with open (waiting_list_path , 'r+' ) as f : waiting_list = json .load (f , object_pairs_hook = int_keys )
423420 with open (tournoi_path , 'r+' ) as f : tournoi = json .load (f , object_hook = dateparser )
424421
425422 if (member .id not in participants ) and (len (participants ) < tournoi ['limite' ]):
@@ -450,52 +447,25 @@ async def inscrire(member):
450447 except discord .Forbidden :
451448 pass
452449
453- elif ( member . id not in waiting_list ) and ( len (participants ) >= tournoi ['limite' ]) :
450+ elif tournoi [ "reaction_mode" ] and len (participants ) >= tournoi ['limite' ]:
454451
455452 try :
456- tournoi ['waiting_list_id' ]
457- except KeyError :
458- inscriptions_channel = bot .get_channel (inscriptions_channel_id )
459- waiting_list_msg = await inscriptions_channel .send (":hourglass: __Liste d'attente__ :\n " )
460- tournoi ['waiting_list_id' ] = waiting_list_msg .id
461- with open (tournoi_path , 'w' ) as f : json .dump (tournoi , f , indent = 4 , default = dateconverter )
462- await waiting_list_msg .pin ()
463-
464- waiting_list [member .id ] = { "display_name" : member .display_name if tournoi ['use_guild_name' ] else str (member ) }
465-
466- with open (waiting_list_path , 'w' ) as f : json .dump (waiting_list , f , indent = 4 )
467- await update_waiting_list ()
468-
469- try :
470- await member .send (f"Dû au manque de place, tu es ajouté(e) à la **liste d'attente** pour le tournoi **{ tournoi ['name' ]} **. "
471- f"Maintiens ton inscription seulement si tu es sûr(e) de vouloir participer. Tu seras prévenu(e) si une place se libère !" )
453+ await member .send (f"Il n'y a malheureusement plus de place pour le tournoi **{ tournoi ['name' ]} **. "
454+ f"Retente ta chance plus tard, par exemple à la fin du check-in pour remplacer les absents !" )
472455 except discord .Forbidden :
473456 pass
474457
475-
476- ### Mettre à jour la liste d'attente
477- async def update_waiting_list ():
478-
479- with open (waiting_list_path , 'r+' ) as f : waiting_list = json .load (f , object_pairs_hook = int_keys )
480- with open (tournoi_path , 'r+' ) as f : tournoi = json .load (f , object_hook = dateparser )
481-
482- old_waiting_list = await bot .get_channel (inscriptions_channel_id ).fetch_message (tournoi ["waiting_list_id" ])
483-
484- new_waiting_list = ":hourglass: __Liste d'attente__ *(seuls les 20 premiers sont affichés)* :\n "
485-
486- for joueur in list (waiting_list )[:20 ]:
487- new_waiting_list += f":white_small_square: { waiting_list [joueur ]['display_name' ]} \n "
488-
489- new_waiting_list += f"\n **{ len (waiting_list )} personne(s)** au total sur la liste d'attente."
490-
491- await old_waiting_list .edit (content = new_waiting_list )
458+ try :
459+ inscription = await bot .get_channel (inscriptions_channel_id ).fetch_message (tournoi ["annonce_id" ])
460+ await inscription .remove_reaction ("✅" , member )
461+ except (discord .HTTPException , discord .NotFound ):
462+ pass
492463
493464
494465### Désinscription
495466async def desinscrire (member ):
496467
497468 with open (participants_path , 'r+' ) as f : participants = json .load (f , object_pairs_hook = int_keys )
498- with open (waiting_list_path , 'r+' ) as f : waiting_list = json .load (f , object_pairs_hook = int_keys )
499469 with open (tournoi_path , 'r+' ) as f : tournoi = json .load (f , object_hook = dateparser )
500470
501471 if member .id in participants :
@@ -528,30 +498,6 @@ async def desinscrire(member):
528498 except discord .Forbidden :
529499 pass
530500
531- # If there's a waiting list, add the next waiting player
532- try :
533- next_waiting_player = next (iter (waiting_list ))
534- except StopIteration :
535- pass
536- else :
537- await inscrire (member .guild .get_member (next_waiting_player ))
538- del waiting_list [next_waiting_player ]
539- with open (waiting_list_path , 'w' ) as f : json .dump (waiting_list , f , indent = 4 )
540-
541- await update_waiting_list ()
542-
543- elif member .id in waiting_list :
544-
545- del waiting_list [member .id ]
546- with open (waiting_list_path , 'w' ) as f : json .dump (waiting_list , f , indent = 4 )
547-
548- await update_waiting_list ()
549-
550- try :
551- await member .send (f"Tu as été retiré(e) de la liste d'attente pour le tournoi **{ tournoi ['name' ]} **." )
552- except discord .Forbidden :
553- pass
554-
555501
556502### Mettre à jour l'annonce d'inscription
557503async def update_annonce ():
@@ -604,7 +550,7 @@ async def rappel_check_in():
604550
605551 if tournoi ["fin_check-in" ] - datetime .datetime .now () < datetime .timedelta (minutes = 10 ):
606552 try :
607- await guild .get_member (inscrit ).send (f"**Attention !** Il ne te reste plus qu 'une dizaine de minutes pour check-in au tournoi **{ tournoi ['name' ]} **." )
553+ await guild .get_member (inscrit ).send (f"**Attention !** Il te reste moins d 'une dizaine de minutes pour check-in au tournoi **{ tournoi ['name' ]} **." )
608554 except discord .Forbidden :
609555 pass
610556
@@ -640,10 +586,8 @@ async def end_check_in():
640586 if participants [inscrit ]["checked_in" ] == False :
641587 await desinscrire (guild .get_member (inscrit ))
642588
643- await bot .get_channel (inscriptions_channel_id ).send (
644- ":information_source: **Les absents du check-in ont été retirés** : des places sont peut-être libérées pour des inscriptions de dernière minute.\n "
645- "*Notez que la liste d'attente est prioritaire pour remplacer les absents du check-in.*"
646- )
589+ await bot .get_channel (inscriptions_channel_id ).send (":information_source: **Les absents du check-in ont été retirés** : "
590+ "des places sont peut-être libérées pour des inscriptions de dernière minute.\n " )
647591
648592
649593### Fin des inscriptions
@@ -669,7 +613,7 @@ async def check_in(member):
669613
670614### Prise en charge des inscriptions, désinscriptions, check-in et check-out
671615@bot .command (aliases = ['in' , 'out' ])
672- @commands .check (tournament_is_pending )
616+ @commands .check (inscriptions_still_open )
673617@commands .max_concurrency (1 , wait = True )
674618async def participants_management (ctx ):
675619
@@ -687,13 +631,11 @@ async def participants_management(ctx):
687631
688632 elif ctx .invoked_with == 'in' :
689633
690- now = datetime .datetime .now ()
691-
692- if ctx .channel .id == check_in_channel_id and ctx .author .id in participants and tournoi ["fin_check-in" ] > now > tournoi ["début_check-in" ]:
634+ if ctx .channel .id == check_in_channel_id and ctx .author .id in participants and tournoi ["fin_check-in" ] > datetime .datetime .now () > tournoi ["début_check-in" ]:
693635 await check_in (ctx .author )
694636 await ctx .message .add_reaction ("✅" )
695-
696- elif ctx .channel .id == inscriptions_channel_id and ctx .author .id not in participants and now < tournoi ["fin_inscription" ]:
637+
638+ elif ctx .channel .id == inscriptions_channel_id and ctx .author .id not in participants and len ( participants ) < tournoi ['limite' ]:
697639 await inscrire (ctx .author )
698640 await ctx .message .add_reaction ("✅" )
699641
0 commit comments