2024-03-15 18:51:00 +00:00
|
|
|
// Package spotify contains an actor to query the current playing
|
|
|
|
// track for a channel with authorized spotify account
|
|
|
|
package spotify
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/Luzifer/twitch-bot/v3/pkg/database"
|
|
|
|
"github.com/Luzifer/twitch-bot/v3/plugins"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
actorName = "spotify"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
baseURL *url.URL
|
|
|
|
db database.Connector
|
|
|
|
getModuleConfig plugins.ModuleConfigGetterFunc
|
|
|
|
)
|
|
|
|
|
|
|
|
// Register provides the plugins.RegisterFunc
|
|
|
|
func Register(args plugins.RegistrationArguments) (err error) {
|
|
|
|
if baseURL, err = url.Parse(args.GetBaseURL()); err != nil {
|
|
|
|
return fmt.Errorf("parsing base-url: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
db = args.GetDatabaseConnector()
|
|
|
|
getModuleConfig = args.GetModuleConfigForChannel
|
|
|
|
|
|
|
|
args.RegisterTemplateFunction(
|
|
|
|
"spotifyCurrentPlaying",
|
2024-03-28 17:29:39 +00:00
|
|
|
plugins.GenericTemplateFunctionGetter(getCurrentArtistTitleForChannel),
|
2024-03-15 18:51:00 +00:00
|
|
|
plugins.TemplateFuncDocumentation{
|
|
|
|
Name: "spotifyCurrentPlaying",
|
2024-05-13 16:26:38 +00:00
|
|
|
Description: "Retrieves the current playing track for the given channel (returns an empty string when nothing is playing)",
|
2024-03-15 18:51:00 +00:00
|
|
|
Syntax: "spotifyCurrentPlaying <channel>",
|
|
|
|
Example: &plugins.TemplateFuncDocumentationExample{
|
|
|
|
MatchMessage: "^!spotify",
|
|
|
|
MessageContent: "!spotify",
|
|
|
|
Template: "{{ spotifyCurrentPlaying .channel }}",
|
|
|
|
FakedOutput: "Beast in Black - Die By The Blade",
|
|
|
|
},
|
2024-03-28 17:29:39 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
args.RegisterTemplateFunction(
|
|
|
|
"spotifyLink",
|
|
|
|
plugins.GenericTemplateFunctionGetter(getCurrentLinkForChannel),
|
|
|
|
plugins.TemplateFuncDocumentation{
|
|
|
|
Name: "spotifyLink",
|
2024-05-13 16:26:38 +00:00
|
|
|
Description: "Retrieves the link for the playing track for the given channel (returns an empty string when nothing is playing)",
|
2024-03-28 17:29:39 +00:00
|
|
|
Syntax: "spotifyLink <channel>",
|
|
|
|
Example: &plugins.TemplateFuncDocumentationExample{
|
|
|
|
MatchMessage: "^!spotifylink",
|
|
|
|
MessageContent: "!spotifylink",
|
|
|
|
Template: "{{ spotifyLink .channel }}",
|
|
|
|
FakedOutput: "https://open.spotify.com/track/3HCzXf0lNpekSqsGBcGrCd",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2024-03-15 18:51:00 +00:00
|
|
|
|
|
|
|
if err = args.RegisterAPIRoute(plugins.HTTPRouteRegistrationArgs{
|
|
|
|
Description: "Starts authorization of an Spotify Account for a {channel}",
|
|
|
|
HandlerFunc: handleStartAuth,
|
|
|
|
Method: http.MethodGet,
|
|
|
|
Module: actorName,
|
|
|
|
Name: "Authorize Spotify Account",
|
|
|
|
Path: "/{channel}",
|
|
|
|
RequiresWriteAuth: false,
|
|
|
|
ResponseType: plugins.HTTPRouteResponseTypeTextPlain,
|
|
|
|
RouteParams: []plugins.HTTPRouteParamDocumentation{
|
|
|
|
{
|
|
|
|
Description: "Channel to authorize the Account for",
|
|
|
|
Name: "channel",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}); err != nil {
|
|
|
|
return fmt.Errorf("registering API route: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|