Skip to content

Commit

Permalink
Update __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Oct 8, 2023
1 parent ad628bd commit 14cacbe
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions bot/models/redis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
# ------------------------------------------------------------------------


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,
"position": position,
"date": date,
"file": file,
"type": type,

}
hset = r.hset("queues", group_id, values)
return hset
Expand All @@ -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")
Expand All @@ -39,4 +49,5 @@ def get_queue_position(group_id: str) -> Union[int, None]:
value = list(queue.values())[-1]
return value["position"]

# ------------------------------------------------------------------------

# ------------------------------------------------------------------------

0 comments on commit 14cacbe

Please sign in to comment.