Skip to content

Commit

Permalink
Update __init__.py and requirements-dev.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Oct 8, 2023
1 parent 28bd472 commit e71ec34
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 26 deletions.
91 changes: 65 additions & 26 deletions bot/models/redis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,85 @@


def add_to_queue(
group_id: str, from_user: str, position: int, date: str, file: str, type: str
group_id: str,
from_user: str,
is_playing: bool,
date: str,
file: str,
type: str,
position=1,
) -> bool:
"""Add or create queue from group_id"""
values = {
"from_user": from_user,
"position": position,
"date": date,
"file": file,
"type": type,
}
"""Add or create queue in `group_id` field"""
values = [
{
"from_user": from_user,
"is_playing": is_playing,
"position": position,
"date": date,
"file": file,
"type": type,
}
]
queue = r.hgetall("queues")
if group_id in queue:
queue[group_id].append(values)
hset = r.hset("queues", group_id, queue[group_id])
if hset == 0:
return True
return False
hset = r.hset("queues", group_id, values)
return hset
if hset == 1:
return True
return False


def next_in_queue(group_id: str) -> Union[Tuple, None]:
queue = r.hgetall("queues")
value = queue[group_id]
if not value:
if group_id not in queue:
return None
values = (
value["from_user"],
value["position"],
value["date"],
value["file"],
value["type"],
)
return values
for i, v in range(len(value)):
if value[i].get("is_playing"):
next = value[i + 1]
values = (
next["from_user"],
next["is_playing"],
next["position"],
next["date"],
next["file"],
next["type"],
)
return values
return None


def remove_queue(group_id: str) -> bool:
def previous_in_queue(group_id: str) -> Union[Tuple, None]:
queue = r.hgetall("queues")
hdel = r.hdel("queues", group_id)
if hdel <= 0:
return False
return True
value = queue[group_id]
if group_id not in queue:
return None
for i, v in range(len(value)):
if value[i].get("is_playing"):
next = value[i - 1]
values = (
next["from_user"],
next["is_playing"],
next["position"],
next["date"],
next["file"],
next["type"],
)
return values
return None


def remove_queue(group_id: str) -> None:
r.hdel("queues", group_id)


def get_queue_position(group_id: str) -> Union[int, None]:
def get_last_queue_position(group_id: str) -> Union[int, None]:
queue = r.hgetall("queues")
if not queue:
if group_id not in queue:
return None
value = list(queue.values())[-1]
return value["position"]
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
black==23.7.0
black[jupyter]
pylint==2.17.5

0 comments on commit e71ec34

Please sign in to comment.