diff --git a/bot/models/redis/__init__.py b/bot/models/redis/__init__.py index ba3c552..7e98446 100644 --- a/bot/models/redis/__init__.py +++ b/bot/models/redis/__init__.py @@ -4,7 +4,9 @@ # ------------------------------------------------------------------------ -def add_to_queue(group_id: str, from_user: str,position:int, date: str, file:str, type:str) -> bool: +def add_to_queue( + group_id: str, from_user: str, position: int, date: str, file: str, type: str +) -> bool: """Add or create queue from group_id""" values = { "from_user": from_user, @@ -12,7 +14,6 @@ def add_to_queue(group_id: str, from_user: str,position:int, date: str, file:str "date": date, "file": file, "type": type, - } hset = r.hset("queues", group_id, values) return hset @@ -23,14 +24,23 @@ def next_in_queue(group_id: str) -> Union[Tuple, None]: value = queue[group_id] if not value: return None - values = (value["from_user"], value["position"], value["date"], value["file"], value["type"]) + values = ( + value["from_user"], + value["position"], + value["date"], + value["file"], + value["type"], + ) return values -def remove_queue(group_id: str): +def remove_queue(group_id: str) -> bool: queue = r.hgetall("queues") hdel = r.hdel("queues", group_id) - return hdel + if hdel <= 0: + return False + return True + def get_queue_position(group_id: str) -> Union[int, None]: queue = r.hgetall("queues") @@ -39,4 +49,5 @@ def get_queue_position(group_id: str) -> Union[int, None]: value = list(queue.values())[-1] return value["position"] -# ------------------------------------------------------------------------ \ No newline at end of file + +# ------------------------------------------------------------------------