aboutsummaryrefslogtreecommitdiff
path: root/bot.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot.py')
-rw-r--r--bot.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/bot.py b/bot.py
index 17bed8a..b6aa67c 100644
--- a/bot.py
+++ b/bot.py
@@ -183,7 +183,27 @@ class SpotifyAPI:
"album_art": None,
"url": None,
}
+ @staticmethod
+ def get_last_liked_track(sp: spotipy.Spotify) -> dict | None:
+ res = sp.current_user_saved_tracks(limit=1)
+ items = res.get("items", [])
+
+ if not items:
+ return None
+ track = items[0].get("track")
+ if not track:
+ return None
+
+ return {
+ "title": track["name"],
+ "artist": track["artists"][0]["name"],
+ # Renamed key to 'album_art' to match payload builder expectations
+ "album_art": track["album"]["images"][0]["url"]
+ if track["album"].get("images")
+ else None,
+ "url": track["external_urls"]["spotify"],
+ }
# ==============================================================================
# 4. DISCORD PAYLOAD BUILDER & DISCORD IDENTITY API UPDATER
@@ -257,15 +277,14 @@ def build_discord_profile_payload(
"type": 3,
"name": "current_song_picture",
"value": {
- "url": current_track.get("album_art") or DEFAULT_IMAGE
- },
+ "url": (current_track.get("album_art") if current_track else None) or DEFAULT_IMAGE },
},
{
"type": 1,
"name": "current_song_name",
"value": current_track.get("title", "None"),
},
- {"type": 1, "name": "status", "value": status_label},
+ {"type": 1, "name": "status", "value": "recently liked"},
{"type": 1, "name": "range", "value": time_range_label},
]
}
@@ -303,7 +322,7 @@ async def process_user_widget_update(discord_user_id: str) -> bool:
top_song = SpotifyAPI.get_top_track(sp, time_range="short_term")
top_album = SpotifyAPI.get_top_album(sp, time_range="short_term")
top_artist = SpotifyAPI.get_top_artist(sp, time_range="short_term")
- current_track = SpotifyAPI.get_currently_playing(sp)
+ last_liked = SpotifyAPI.get_last_liked_track(sp)
payload = build_discord_profile_payload(
spotify_username=spotify_username,
@@ -311,7 +330,7 @@ async def process_user_widget_update(discord_user_id: str) -> bool:
top_song=top_song,
top_album=top_album,
top_artist=top_artist,
- current_track=current_track,
+ current_track=last_liked,
time_range_label="4 weeks",
)