diff --git a/bot/helpers/queues.py b/bot/helpers/queues.py index b82442f..b5e471b 100644 --- a/bot/helpers/queues.py +++ b/bot/helpers/queues.py @@ -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)) @@ -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"): @@ -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"): @@ -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)): @@ -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": @@ -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 diff --git a/bot/plugins/commands/play_song.py b/bot/plugins/commands/play_song.py index afc9bbb..640d517 100755 --- a/bot/plugins/commands/play_song.py +++ b/bot/plugins/commands/play_song.py @@ -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")]] ), diff --git a/docker-compose.yml b/docker-compose.yml index 633b409..4820fed 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,8 @@ services: - ./.env ports: - "$POSTGRES_PORT:$POSTGRES_PORT" + expose: + - $POSTGRES_PORT networks: - kreacher cache: @@ -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