mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 16:50:01 +00:00
[core] Fix: Allow start when no tokens are available
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
3213f4ac37
commit
e8d39c19a4
2 changed files with 9 additions and 1 deletions
|
@ -38,6 +38,8 @@ type (
|
|||
Service struct{ db database.Connector }
|
||||
)
|
||||
|
||||
var ErrChannelNotAuthorized = errors.New("channel is not authorized")
|
||||
|
||||
func New(db database.Connector) (*Service, error) {
|
||||
return &Service{db}, errors.Wrap(
|
||||
db.DB().AutoMigrate(&extendedPermission{}),
|
||||
|
@ -144,6 +146,9 @@ func (s Service) GetTwitchClientForChannel(channel string, cfg ClientConfig) (*t
|
|||
)
|
||||
|
||||
if err = s.db.DB().First(&perm, "channel = ?", strings.TrimLeft(channel, "#")).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, ErrChannelNotAuthorized
|
||||
}
|
||||
return nil, errors.Wrap(err, "getting twitch credential from database")
|
||||
}
|
||||
|
||||
|
|
3
main.go
3
main.go
|
@ -272,8 +272,11 @@ func main() {
|
|||
frontendReloadHooks.Ping()
|
||||
},
|
||||
}); err != nil {
|
||||
if !errors.Is(err, access.ErrChannelNotAuthorized) {
|
||||
log.WithError(err).Fatal("Unable to initialize Twitch client")
|
||||
}
|
||||
twitchClient = twitch.New(cfg.TwitchClient, cfg.TwitchClientSecret, cfg.TwitchToken, "")
|
||||
}
|
||||
|
||||
twitchWatch := newTwitchWatcher()
|
||||
// Query may run that often as the twitchClient has an internal
|
||||
|
|
Loading…
Reference in a new issue