implement setting a lastfm account

This commit is contained in:
lyx0 2023-03-04 20:26:02 +00:00
parent 2168991651
commit 2e7b115795
3 changed files with 48 additions and 6 deletions

View file

@ -190,13 +190,15 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
commands.Preview(target, cmdParams[1], app.TwitchClient)
return
}
// ()thumbnail <live channel>
case "thumbnail":
if msgLen < 2 {
common.Send(target, "Not enough arguments provided. Usage: ()thumbnail <username>", app.TwitchClient)
case "set":
if msgLen < 3 {
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
return
} else if cmdParams[1] == "lastfm" {
app.SetLastFMUser(cmdParams[2], message)
return
} else {
commands.Preview(target, cmdParams[1], app.TwitchClient)
return
}
@ -210,6 +212,16 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
commands.Seventv(target, cmdParams[1], app.TwitchClient)
return
}
// ()thumbnail <live channel>
case "thumbnail":
if msgLen < 2 {
common.Send(target, "Not enough arguments provided. Usage: ()thumbnail <username>", app.TwitchClient)
return
} else {
commands.Preview(target, cmdParams[1], app.TwitchClient)
return
}
// ()7tv <emote name>
case "7tv":
if msgLen < 2 {

View file

@ -1,9 +1,12 @@
package main
import (
"fmt"
"github.com/gempir/go-twitch-irc/v3"
"github.com/lyx0/nourybot/internal/commands"
"github.com/lyx0/nourybot/internal/common"
"github.com/lyx0/nourybot/internal/data"
"go.uber.org/zap"
)
@ -34,3 +37,30 @@ func (app *Application) CheckLastFM(message twitch.PrivateMessage) {
commands.LastFmUserRecent(target, user, app.TwitchClient)
}
func (app *Application) SetLastFMUser(lastfmUser string, message twitch.PrivateMessage) {
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
user := &data.LastFMUser{
TwitchLogin: message.User.Name,
TwitchID: message.User.ID,
LastFMUser: lastfmUser,
}
sugar.Infow("User:: ",
"user:", user,
)
err := app.Models.LastFMUsers.Insert(user)
if err != nil {
if err != nil {
reply := fmt.Sprintf("Something went wrong FeelsBadMan %s", err)
common.Send(message.Channel, reply, app.TwitchClient)
return
}
} else {
reply := fmt.Sprintf("Successfully set your lastfm account as %v", lastfmUser)
common.Send(message.Channel, reply, app.TwitchClient)
return
}
}

View file

@ -65,7 +65,7 @@ func (l LastFMUserModel) Insert(lastfm *LastFMUser) error {
}
if rowsAffected == 0 {
return ErrCommandRecordAlreadyExists
return ErrLastFMUserRecordAlreadyExists
}
return nil