Should have handled username updating code in the command, didn't need to create new functions for the command.
This commit is contained in:
+8
-28
@@ -153,15 +153,19 @@ class Category:
|
||||
return self._scores_map[user]
|
||||
return None
|
||||
|
||||
def remove_score(self, score: str) -> None:
|
||||
def remove_score(self, user: str) -> Score:
|
||||
"""
|
||||
Removes a user's score from dictionary storage.
|
||||
|
||||
Args:
|
||||
score (str): user whose score to remove
|
||||
user (str): user whose score to remove
|
||||
|
||||
Returns:
|
||||
Score: User's Score or None
|
||||
"""
|
||||
score = self._scores_map.pop(score)
|
||||
del score
|
||||
if user in self._scores_map:
|
||||
return self._scores_map.pop(user)
|
||||
return None
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""
|
||||
@@ -188,27 +192,3 @@ class Category:
|
||||
str: string of json representation of Category
|
||||
"""
|
||||
return json.dumps(self.to_dict(), indent=4)
|
||||
|
||||
def update_username(self, old_username: str, new_username: str) -> bool:
|
||||
"""
|
||||
Checks score map for old username. Pops old username to remove from map.
|
||||
Updates score's username and calls self.add_score with new score to add back
|
||||
to map and sort.
|
||||
|
||||
Args:
|
||||
old_username (str): Username to replace
|
||||
new_username (str): Username to replace with
|
||||
|
||||
Returns:
|
||||
bool: True indicating a score was updated, False otherwise
|
||||
"""
|
||||
|
||||
ret_val: bool = False
|
||||
|
||||
if old_username in self._scores_map:
|
||||
ret_val = True
|
||||
score: Score = self._scores_map.pop(old_username)
|
||||
score.user = new_username
|
||||
self.add_score(score)
|
||||
|
||||
return ret_val
|
||||
|
||||
Reference in New Issue
Block a user