Skip to content

Commit

Permalink
Finding bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Oct 10, 2023
1 parent 53cb6a1 commit e4b39f6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
18 changes: 9 additions & 9 deletions bot/helpers/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def add_or_create_queue(
]
values: bytes = pickle.dumps(kw)
queue: dict = r.hgetall("queues")
if group_id in queue:
if group_id in str(queue):
giq: list = pickle.loads(queue[group_id])
giq.append(values)
hset = r.hset("queues", group_id, pickle.dumps(giq))
Expand All @@ -42,7 +42,7 @@ def next_in_queue(group_id: str) -> Union[Tuple, None]:
"""Get next media in queue"""
queue: dict = r.hgetall("queues")
values: list = pickle.loads(queue[group_id])
if group_id not in queue:
if group_id not in str(queue):
return None
for i in range(len(values)):
if values[i].get("is_playing"):
Expand All @@ -63,7 +63,7 @@ def previous_in_queue(group_id: str) -> Union[Tuple, None]:
"""Get previous media in queue"""
queue: dict = r.hgetall("queues")
values: list = pickle.loads(queue[group_id])
if group_id not in queue:
if group_id not in str(queue):
return None
for i in range(len(values)):
if values[i].get("is_playing"):
Expand Down Expand Up @@ -93,7 +93,7 @@ def get_queues() -> Union[Dict, None]:
def get_current_position_in_queue(group_id: str) -> Union[int, None]:
"""Get the current position of the media that is playing"""
queue: dict = r.hgetall("queues")
if group_id not in queue:
if group_id not in str(queue):
return None
values: dict = pickle.loads(queue[group_id])
for i in range(len(values)):
Expand All @@ -105,18 +105,18 @@ def get_current_position_in_queue(group_id: str) -> Union[int, None]:
def get_last_position_in_queue(group_id: str) -> Union[int, None]:
"""Get the last position of the media that will be played in the queue"""
queue: dict = r.hgetall("queues")
if group_id not in queue:
if group_id not in str(queue):
return None
value: dict = pickle.loads(queue[group_id])[-1]
return value["position"]


def update_is_played_in_queue(group_id: str, action: str) -> None:
def update_is_played_in_queue(group_id: str, action: str) -> Union[bool, None]:
"""Update `is_playing` status in queue"""
queue: dict = r.hgetall("queues")
values: list = pickle.loads(queue[group_id])
if group_id not in queue:
if group_id not in str(queue):
return None
values: list = pickle.loads(queue[group_id])
for i in range(len(values)):
if values[i].get("is_playing"):
if action == "previous":
Expand All @@ -127,4 +127,4 @@ def update_is_played_in_queue(group_id: str, action: str) -> None:
values[i]["is_playing"] = False
values[i + 1]["is_playing"] = True
return r.hset("queues", group_id, pickle.dumps(values))
return None
return True
8 changes: 5 additions & 3 deletions bot/plugins/commands/play_song.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,19 @@ async def _(client: Client, message: Message):
"**__Can't find song.\n\nTry searching with more specific title.__**",
)
if str(message.chat.id) in str(QUEUES):
position = get_last_position_in_queue(str(message.chat.id)) + 1
position = get_last_position_in_queue(str(message.chat.id))
if position is None:
return
add_or_create_queue(
str(message.chat.id),
from_user=str(message.from_user.id),
date=str(datetime.now()),
file=url,
type_of="song_yt",
position=position,
position=position + 1,
)
return await msg.edit(
f"__Added to queue at {position}\n\nTitle: [{name}]({url})\nDuration: {duration} Minutes\n Requested by:__ [{data['first_name']}]({data['mention']})",
f"**__Added to queue at {position + 1}\n\nTitle: [{name}]({url})\nDuration: {duration} Minutes\n Requested by:__** [{data['first_name']}]({data['mention']})",
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("cʟᴏꜱᴇ", callback_data="close")]]
),
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ services:
- ./.env
ports:
- "$POSTGRES_PORT:$POSTGRES_PORT"
expose:
- $POSTGRES_PORT
networks:
- kreacher
cache:
Expand All @@ -22,6 +24,8 @@ services:
command: redis-server --save 20 1 --loglevel warning --requirepass $REDIS_PASSWORD
ports:
- "$REDIS_PORT:$REDIS_PORT"
expose:
- $REDIS_PORT
pgadmin:
image: dpage/pgadmin4
restart: always
Expand Down

0 comments on commit e4b39f6

Please sign in to comment.