2024-02-29 20:18:59 +00:00
|
|
|
package main
|
|
|
|
|
2024-03-10 16:38:18 +00:00
|
|
|
import (
|
2024-03-14 12:33:52 +00:00
|
|
|
"log/slog"
|
|
|
|
|
2024-03-10 16:38:18 +00:00
|
|
|
"git.sr.ht/~ashkeel/strimertul/twitch"
|
|
|
|
)
|
2024-02-29 20:18:59 +00:00
|
|
|
|
|
|
|
type ProblemID string
|
|
|
|
|
|
|
|
const (
|
|
|
|
ProblemIDTwitchNoApp = "twitch:app_missing"
|
|
|
|
ProblemIDEventSubNoAuth = "twitch:eventsub_no_auth"
|
|
|
|
ProblemIDEventSubScope = "twitch:eventsub_scope"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Problem struct {
|
|
|
|
ID ProblemID `json:"id"`
|
|
|
|
Details any `json:"details"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) GetProblems() (problems []Problem) {
|
|
|
|
problems = []Problem{}
|
|
|
|
if a.twitchManager != nil {
|
|
|
|
client := a.twitchManager.Client()
|
|
|
|
if client != nil {
|
|
|
|
// Check if the app needs to be authorized again
|
2024-03-10 16:38:18 +00:00
|
|
|
scopesMatch, err := twitch.CheckScopes(client.DB)
|
2024-02-29 20:18:59 +00:00
|
|
|
if err != nil {
|
2024-03-14 12:33:52 +00:00
|
|
|
slog.Warn("Could not check scopes for problems", "error", err)
|
2024-02-29 20:18:59 +00:00
|
|
|
} else {
|
|
|
|
if !scopesMatch {
|
|
|
|
problems = append(problems, Problem{
|
|
|
|
ID: ProblemIDEventSubScope,
|
|
|
|
Details: nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|