@@ -70,10 +70,10 @@ def __init__(
70
70
def add_user_statistics (self , user : str , values : Dict [str , int ]) -> None :
71
71
self .get_user_cache ()
72
72
current_values : Dict [str , int ] = {}
73
- if "stats" in self .get_user_by_email (user ). keys () :
73
+ if "stats" in self .get_user_by_email (user ):
74
74
current_values = self .user_cache [user ]["stats" ]
75
75
for key , value in values .items ():
76
- if key not in current_values . keys () :
76
+ if key not in current_values :
77
77
current_values .update ({key : 0 })
78
78
current_values [key ] += value
79
79
self .user_cache [user ].update ({"stats" : current_values })
@@ -216,15 +216,15 @@ def handle_message(self, message: Dict[str, Any], bot_handler: BotHandler) -> No
216
216
sender = message ["sender_email" ].lower ()
217
217
message ["sender_email" ] = message ["sender_email" ].lower ()
218
218
219
- if self .email not in self .user_cache . keys () and self .supports_computer :
219
+ if self .email not in self .user_cache and self .supports_computer :
220
220
self .add_user_to_cache (
221
221
{"sender_email" : self .email , "sender_full_name" : self .full_name }
222
222
)
223
223
224
224
if sender == self .email :
225
225
return
226
226
227
- if sender not in self .user_cache . keys () :
227
+ if sender not in self .user_cache :
228
228
self .add_user_to_cache (message )
229
229
logging .info ("Added %s to user cache" , sender )
230
230
@@ -489,7 +489,7 @@ def command_leaderboard(self, message: Dict[str, Any], sender: str, content: str
489
489
def get_sorted_player_statistics (self ) -> List [Tuple [str , Dict [str , int ]]]:
490
490
players = []
491
491
for user_name , u in self .user_cache .items ():
492
- if "stats" in u . keys () :
492
+ if "stats" in u :
493
493
players .append ((user_name , u ["stats" ]))
494
494
return sorted (
495
495
players ,
@@ -508,11 +508,11 @@ def send_invite(self, game_id: str, user_email: str, message: Dict[str, Any] = {
508
508
self .send_reply (message , self .confirm_new_invitation (user_email ))
509
509
510
510
def cancel_game (self , game_id : str , reason : str = "" ) -> None :
511
- if game_id in self .invites . keys () :
511
+ if game_id in self .invites :
512
512
self .broadcast (game_id , "Game cancelled.\n " + reason )
513
513
del self .invites [game_id ]
514
514
return
515
- if game_id in self .instances . keys () :
515
+ if game_id in self .instances :
516
516
self .instances [game_id ].broadcast ("Game ended.\n " + reason )
517
517
del self .instances [game_id ]
518
518
return
@@ -541,7 +541,7 @@ def get_formatted_game_object(self, game_id: str) -> str:
541
541
object = f"""> **Game `{ game_id } `**
542
542
> { self .game_name }
543
543
> { self .get_number_of_players (game_id )} /{ self .max_players } players"""
544
- if game_id in self .instances . keys () :
544
+ if game_id in self .instances :
545
545
instance = self .instances [game_id ]
546
546
if not self .is_single_player :
547
547
object += "\n > **[Join Game](/#narrow/stream/{}/topic/{})**" .format (
@@ -561,7 +561,7 @@ def join_game(self, game_id: str, user_email: str, message: Dict[str, Any] = {})
561
561
self .start_game_if_ready (game_id )
562
562
563
563
def get_players (self , game_id : str , parameter : str = "a" ) -> List [str ]:
564
- if game_id in self .invites . keys () :
564
+ if game_id in self .invites :
565
565
players : List [str ] = []
566
566
if (
567
567
self .invites [game_id ]["subject" ] == "###private###" and "p" in parameter
@@ -573,14 +573,14 @@ def get_players(self, game_id: str, parameter: str = "a") -> List[str]:
573
573
if parameter in accepted :
574
574
players .append (player )
575
575
return players
576
- if game_id in self .instances . keys () and "p" not in parameter :
576
+ if game_id in self .instances and "p" not in parameter :
577
577
players = self .instances [game_id ].players
578
578
return players
579
579
return []
580
580
581
581
def get_game_info (self , game_id : str ) -> Dict [str , Any ]:
582
582
game_info : Dict [str , Any ] = {}
583
- if game_id in self .instances . keys () :
583
+ if game_id in self .instances :
584
584
instance = self .instances [game_id ]
585
585
game_info = {
586
586
"game_id" : game_id ,
@@ -589,7 +589,7 @@ def get_game_info(self, game_id: str) -> Dict[str, Any]:
589
589
"subject" : instance .subject ,
590
590
"players" : self .get_players (game_id ),
591
591
}
592
- if game_id in self .invites . keys () :
592
+ if game_id in self .invites :
593
593
invite = self .invites [game_id ]
594
594
game_info = {
595
595
"game_id" : game_id ,
@@ -603,7 +603,7 @@ def get_game_info(self, game_id: str) -> Dict[str, Any]:
603
603
def get_user_by_name (self , name : str ) -> Dict [str , Any ]:
604
604
name = name .strip ()
605
605
for user in self .user_cache .values ():
606
- if "full_name" in user . keys () and user ["full_name" ].lower () == name .lower ():
606
+ if "full_name" in user and user ["full_name" ].lower () == name .lower ():
607
607
return user
608
608
return {}
609
609
@@ -646,9 +646,9 @@ def change_game_subject(
646
646
if message != {}:
647
647
self .send_reply (message , "There is already a game in this subject." )
648
648
return
649
- if game_id in self .instances . keys () :
649
+ if game_id in self .instances :
650
650
self .instances [game_id ].change_subject (stream_name , subject_name )
651
- if game_id in self .invites . keys () :
651
+ if game_id in self .invites :
652
652
invite = self .invites [game_id ]
653
653
invite ["stream" ] = stream_name
654
654
invite ["subject" ] = stream_name
@@ -658,7 +658,7 @@ def set_invite_by_user(
658
658
) -> str :
659
659
user_email = user_email .lower ()
660
660
for game , users in self .invites .items ():
661
- if user_email in users . keys () :
661
+ if user_email in users :
662
662
if is_accepted :
663
663
if message ["type" ] == "private" :
664
664
users [user_email ] = "pa"
@@ -754,7 +754,7 @@ def is_user_not_player(self, user_email: str, message: Dict[str, Any] = {}) -> b
754
754
if user_email in instance .players :
755
755
return False
756
756
for invite in self .invites .values ():
757
- for u in invite . keys () :
757
+ for u in invite :
758
758
if u == "host" and user_email == invite ["host" ]:
759
759
return False
760
760
if u == user_email and "a" in invite [u ]:
@@ -774,15 +774,15 @@ def broadcast(self, game_id: str, content: str, include_private: bool = True) ->
774
774
if private_recipients is not None :
775
775
for user in private_recipients :
776
776
self .send_message (user , content , True )
777
- if game_id in self .invites . keys () and self .invites [game_id ]["subject" ] != "###private###" :
777
+ if game_id in self .invites and self .invites [game_id ]["subject" ] != "###private###" :
778
778
self .send_message (
779
779
self .invites [game_id ]["stream" ],
780
780
content ,
781
781
False ,
782
782
self .invites [game_id ]["subject" ],
783
783
)
784
784
return True
785
- if game_id in self .instances . keys () :
785
+ if game_id in self .instances :
786
786
self .send_message (
787
787
self .instances [game_id ].stream , content , False , self .instances [game_id ].subject
788
788
)
@@ -801,7 +801,7 @@ def get_game_id_by_email(self, user_email: str) -> str:
801
801
for instance in self .instances .values ():
802
802
if user_email in instance .players :
803
803
return instance .game_id
804
- for game_id in self .invites . keys () :
804
+ for game_id in self .invites :
805
805
players = self .get_players (game_id )
806
806
if user_email in players :
807
807
return game_id
@@ -879,7 +879,7 @@ def handle_message(self, content: str, player_email: str) -> None:
879
879
self .end_game ("except:" + player_email )
880
880
return
881
881
if content == "draw" :
882
- if player_email in self .current_draw . keys () :
882
+ if player_email in self .current_draw :
883
883
self .current_draw [player_email ] = True
884
884
else :
885
885
self .current_draw = {p : False for p in self .players }
0 commit comments