Skip to content

Commit

Permalink
distinguish loved songs in /fm
Browse files Browse the repository at this point in the history
  • Loading branch information
averen committed Sep 9, 2024
1 parent 9221b0b commit 0c90592
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.sandrabot.sandra.commands.lastfm

import com.sandrabot.sandra.constants.Emotes
import com.sandrabot.sandra.constants.Unicode
import com.sandrabot.sandra.constants.asEmoji
import com.sandrabot.sandra.entities.Command
import com.sandrabot.sandra.entities.lastfm.ImageSize
Expand Down Expand Up @@ -71,6 +72,7 @@ class NowPlaying : Command(arguments = "[user]") {
val trackInfo = event.sandra.lastfm.getTrackInfo(track.name, track.artist.name, username)
// only display the footer if we received a valid response from the api
if (trackInfo != null) footer(buildString {
if (trackInfo.userLoved) append(Unicode.MEDIUM_STAR, " ")
append(event.get("plays", trackInfo.userPlayCount))
if (trackInfo.duration > 0) append("", trackInfo.duration.milliseconds)
if (trackInfo.tags.isNotEmpty()) {
Expand Down
17 changes: 9 additions & 8 deletions src/main/kotlin/com/sandrabot/sandra/constants/Unicode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ package com.sandrabot.sandra.constants
*/
object Unicode {

const val BUG = "🐛"
const val BULLET = ""
const val CROSS_MARK = ""
const val FORTUNE_COOKIE = "🥠"
const val GAME_DIE = "🎲"
const val HEAVY_BLACK_HEART = ""
const val LINK = "🔗"
const val MAGIC_8_BALL = "🎱"
const val BUG = """🐛"""
const val BULLET = """"""
const val CROSS_MARK = """"""
const val FORTUNE_COOKIE = """🥠"""
const val GAME_DIE = """🎲"""
const val HEAVY_BLACK_HEART = """"""
const val LINK = """🔗"""
const val MAGIC_8_BALL = """🎱"""
const val MEDIUM_STAR = """"""

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ data class Track(
val artist: Artist,
val duration: Int = -1,
val playCount: Int = -1,
val userLoved: Int = -1,
val userPlayCount: Int = -1,
val playedWhen: Long = -1,
val userLoved: Boolean = false,
val isNowPlaying: Boolean = false,
val tags: List<Tag> = emptyList(),
val album: Album? = null,
Expand Down Expand Up @@ -86,7 +86,8 @@ data class Wiki(

@Serializable
abstract class ImageHolder {
@JsonNames("image", "images") val images: List<CoverImage> = emptyList()
@JsonNames("image", "images")
val images: List<CoverImage> = emptyList()

fun getImageUrl(size: ImageSize) = images.firstOrNull { it.size == size }?.url
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object TrackSerializer : JsonTransformingSerializer<Track>(Track.serializer()) {
"duration" -> put("duration", value)
"playcount" -> put("playCount", value)
"userplaycount" -> put("userPlayCount", value)
"userloved" -> put("userLoved", value)
"userloved" -> put("userLoved", value.jsonPrimitive.int > 0)
"date" -> put("playedWhen", value.jsonObject["uts"]!!)
"toptags" -> put("tags", value.jsonObject["tag"]!!)
"@attr" -> put("isNowPlaying", value.jsonObject["nowplaying"]!!)
Expand Down

0 comments on commit 0c90592

Please sign in to comment.