From eb692020f74cda4d9b7e239f1de9efe46f70aaa6 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Sat, 4 Mar 2023 19:19:38 +0000 Subject: [PATCH] check if a user was registered in the database if no argument for lastfm command is provided --- cmd/bot/commands.go | 8 +++----- cmd/bot/lastfm.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 cmd/bot/lastfm.go diff --git a/cmd/bot/commands.go b/cmd/bot/commands.go index fbe8da4..d1291c2 100644 --- a/cmd/bot/commands.go +++ b/cmd/bot/commands.go @@ -152,10 +152,9 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) { commands.FirstLine(target, cmdParams[1], cmdParams[2], app.TwitchClient) return } - case "lastfm": if msgLen == 1 { - common.Send(target, "Usage: ()firstline ", app.TwitchClient) + app.CheckLastFM(message) return } else if cmdParams[1] == "artist" && cmdParams[2] == "top" { commands.LastFmArtistTop(target, message, app.TwitchClient) @@ -508,12 +507,11 @@ func (app *Application) commandHelp(target, name, username string) { return } - reply := fmt.Sprintf(c) + reply := fmt.Sprint(c) common.Send(target, reply, app.TwitchClient) return } - reply := fmt.Sprintf("%s", i) + reply := fmt.Sprint(i) common.Send(target, reply, app.TwitchClient) - return } diff --git a/cmd/bot/lastfm.go b/cmd/bot/lastfm.go new file mode 100644 index 0000000..20c1374 --- /dev/null +++ b/cmd/bot/lastfm.go @@ -0,0 +1,36 @@ +package main + +import ( + "github.com/gempir/go-twitch-irc/v3" + "github.com/lyx0/nourybot/internal/commands" + "github.com/lyx0/nourybot/internal/common" + "go.uber.org/zap" +) + +func (app *Application) CheckLastFM(message twitch.PrivateMessage) { + sugar := zap.NewExample().Sugar() + defer sugar.Sync() + + twitchLogin := message.User.Name + sugar.Infow("Twitchlogin: ", + "twitchLogin:", twitchLogin, + ) + u, err := app.Models.LastFMUsers.Get(twitchLogin) + if err != nil { + sugar.Errorw("No LastFM account registered for: ", + "twitchLogin:", twitchLogin, + ) + reply := "No lastfm account registered in my database. Use ()register lastfm to register. (Not yet implemented) Otherwise use ()lastfm without registering." + common.Send(message.Channel, reply, app.TwitchClient) + return + } + + target := message.Channel + user := u.LastFMUser + sugar.Infow("Twitchlogin: ", + "twitchLogin:", twitchLogin, + "user:", user, + ) + + commands.LastFmUserRecent(target, user, app.TwitchClient) +}