feat: add config & logic to have dynamic rich presence activity name
This commit is contained in:
@@ -25,8 +25,17 @@ import (
|
|||||||
|
|
||||||
// Configuration keys
|
// Configuration keys
|
||||||
const (
|
const (
|
||||||
clientIDKey = "clientid"
|
clientIDKey = "clientid"
|
||||||
usersKey = "users"
|
usersKey = "users"
|
||||||
|
activityNameKey = "activityname"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Activity name display options
|
||||||
|
const (
|
||||||
|
activityNameDefault = "default"
|
||||||
|
activityNameTitle = "title"
|
||||||
|
activityNameArtist = "artist"
|
||||||
|
activityNameAlbum = "album"
|
||||||
)
|
)
|
||||||
|
|
||||||
// userToken represents a user-token mapping from the config
|
// userToken represents a user-token mapping from the config
|
||||||
@@ -136,10 +145,22 @@ func (p *discordPlugin) NowPlaying(input scrobbler.NowPlayingRequest) error {
|
|||||||
startTime := (now - int64(input.Position)) * 1000
|
startTime := (now - int64(input.Position)) * 1000
|
||||||
endTime := startTime + int64(input.Track.Duration)*1000
|
endTime := startTime + int64(input.Track.Duration)*1000
|
||||||
|
|
||||||
|
// Resolve the activity name based on configuration
|
||||||
|
activityName := "Navidrome"
|
||||||
|
activityNameOption, _ := pdk.GetConfig(activityNameKey)
|
||||||
|
switch activityNameOption {
|
||||||
|
case activityNameTitle:
|
||||||
|
activityName = input.Track.Title
|
||||||
|
case activityNameArtist:
|
||||||
|
activityName = input.Track.Artist
|
||||||
|
case activityNameAlbum:
|
||||||
|
activityName = input.Track.Album
|
||||||
|
}
|
||||||
|
|
||||||
// Send activity update
|
// Send activity update
|
||||||
if err := rpc.sendActivity(clientID, input.Username, userToken, activity{
|
if err := rpc.sendActivity(clientID, input.Username, userToken, activity{
|
||||||
Application: clientID,
|
Application: clientID,
|
||||||
Name: "Navidrome",
|
Name: activityName,
|
||||||
Type: 2, // Listening
|
Type: 2, // Listening
|
||||||
Details: input.Track.Title,
|
Details: input.Track.Title,
|
||||||
State: input.Track.Artist,
|
State: input.Track.Artist,
|
||||||
|
|||||||
Reference in New Issue
Block a user