rafacovez / notify

Telegram bot written in Python to interact with the Spotify API.
https://t.me/playlistNotificationBot
MIT License
2 stars 0 forks source link

/shownotifylist doesn't tell the user they don't have any playlists in their Notify list yet. #7

Closed rafacovez closed 1 year ago

rafacovez commented 1 year ago

Issue Description

Problem Statement

Currently, the /shownotifylist command does not inform the user if they don't have any playlists in their Notify list on the first try of a fresh start of the bot. Even if no playlists have been added, the code does not display any message indicating an empty list.

Expected Behavior

When a user does not have any playlists in their Notify list, the code should inform them with an appropriate message.

Actual Behavior

The code does not notify the user if they have an empty Notify list on the first try.

Steps to Reproduce

  1. Run the bot for the first time without adding any playlists to the Notify list.
  2. Observe that no message is displayed indicating an empty Notify list.

Code Snippet


class ShowNotifyListCommandHandler(BaseCommandHandler):
    def specific_code(self, message, user_sp, chat_id, user_id):
        conn = sqlite3.connect(database)
        cursor = conn.cursor()

        user_id_in_db = cursor.execute(
            "SELECT user_id FROM notify_list WHERE user_id = ?", (user_id,)
        ).fetchone()

        if user_id_in_db is None:
            bot.send_message(
                chat_id, "You don't have any playlists in your Notify list yet."
            )

        else:
            user_playlists_name = cursor.execute(
                "SELECT playlist_name FROM notify_list WHERE user_id = ?", (user_id,)
            ).fetchall()
            user_playlists_name_arr = [result[0] for result in user_playlists_name]
            notify_list = "\n- ".join(user_playlists_name_arr)

            bot.send_message(
                chat_id, f"This is your Notify list right now: \n\n- {notify_list}"
            )

        cursor.close()
        conn.close()
rafacovez commented 1 year ago

Might stop happening after code refactorization. Yet to confirm.