check if a user was registered in the database if no argument for lastfm command is provided

This commit is contained in:
lyx0 2023-03-04 19:19:38 +00:00
parent ea6fcbe416
commit eb692020f7
2 changed files with 39 additions and 5 deletions

View file

@ -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 <channel> <user>", 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
}

36
cmd/bot/lastfm.go Normal file
View file

@ -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 <username> to register. (Not yet implemented) Otherwise use ()lastfm <username> 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)
}