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 9c7f152 commit 6f96fcd
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions bot/models/redis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from bot import r
from typing import Tuple, Union


def add_to_queue(
group_id: str,
from_user: str,
Expand Down Expand Up @@ -61,14 +62,14 @@ def previous_in_queue(group_id: str) -> Union[Tuple, None]:
return None
for i in range(len(value)):
if value[i].get("is_playing"):
next = value[i - 1]
previous = value[i - 1]
values = (
next["from_user"],
next["is_playing"],
next["position"],
next["date"],
next["file"],
next["type"],
previous["from_user"],
previous["is_playing"],
previous["position"],
previous["date"],
previous["file"],
previous["type"],
)
return values
return None
Expand All @@ -77,14 +78,17 @@ def previous_in_queue(group_id: str) -> Union[Tuple, None]:
def remove_queue(group_id: str) -> None:
r.hdel("queues", group_id)


def get_current_position_in_queue(group_id: str) -> Union[int, None]:
queue = r.hgetall("queues")
if group_id not in queue:
return None
value = queue[group_id].values()[-1]
values = queue[group_id].values()[-1]
for i in range(len(values)):
if values[i].get("is_playing"):
return value["position"]
return values[i]["position"]
return None


def get_last_position_in_queue(group_id: str) -> Union[int, None]:
queue = r.hgetall("queues")
Expand All @@ -93,6 +97,7 @@ def get_last_position_in_queue(group_id: str) -> Union[int, None]:
value = queue[group_id].values()[-1]
return value["position"]


def update_is_played_in_queue(action: str) -> None:
queue = r.hgetall("queues")
values = queue[group_id]
Expand Down

0 comments on commit 6f96fcd

Please sign in to comment.