add channel and user database functionality onto application

This commit is contained in:
lyx0 2022-08-09 22:49:48 +02:00
parent 1728fb54f9
commit 364ea24ca0
4 changed files with 11 additions and 11 deletions

View file

@ -9,7 +9,7 @@ import (
"github.com/lyx0/nourybot/pkg/common"
)
func AddChannel(login string, message twitch.PrivateMessage, app *Application) {
func (app *Application) AddChannel(login string, message twitch.PrivateMessage) {
userId, err := decapi.GetIdByLogin(login)
if err != nil {
app.Logger.Error(err)
@ -34,7 +34,7 @@ func AddChannel(login string, message twitch.PrivateMessage, app *Application) {
}
}
func DeleteChannel(login string, message twitch.PrivateMessage, app *Application) {
func (app *Application) DeleteChannel(login string, message twitch.PrivateMessage) {
err := app.Models.Channels.Delete(login)
if err != nil {
common.Send(message.Channel, "Something went wrong FeelsBadMan", app.TwitchClient)

View file

@ -9,7 +9,7 @@ import (
"go.uber.org/zap"
)
func handleCommand(message twitch.PrivateMessage, app *Application) {
func (app *Application) handleCommand(message twitch.PrivateMessage) {
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
@ -61,7 +61,7 @@ func handleCommand(message twitch.PrivateMessage, app *Application) {
return
} else {
// ()addchannel noemience
AddChannel(cmdParams[1], message, app)
app.AddChannel(cmdParams[1], message)
return
}
case "adduser":
@ -72,18 +72,18 @@ func handleCommand(message twitch.PrivateMessage, app *Application) {
return
} else {
// ()adduser nourylul 1000
AddUser(cmdParams[1], cmdParams[2], message, app)
app.AddUser(cmdParams[1], cmdParams[2], message)
return
}
case "deletechannel":
if message.User.ID != "31437432" { // Limit to myself for now.
return
} else if msgLen < 3 {
} else if msgLen < 2 {
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
return
} else {
// ()addchannel noemience
DeleteChannel(cmdParams[1], message, app)
app.DeleteChannel(cmdParams[1], message)
return
}
case "deleteuser":
@ -94,7 +94,7 @@ func handleCommand(message twitch.PrivateMessage, app *Application) {
return
} else {
// ()addchannel noemience
DeleteUser(cmdParams[1], message, app)
app.DeleteUser(cmdParams[1], message)
return
}
case "bttv":

View file

@ -24,7 +24,7 @@ func (app *Application) handlePrivateMessage(message twitch.PrivateMessage) {
if len(message.Message) >= 2 {
// Strip the `()` prefix
if message.Message[:2] == "()" {
handleCommand(message, app)
app.handleCommand(message)
return
}
}

View file

@ -10,7 +10,7 @@ import (
"github.com/lyx0/nourybot/pkg/common"
)
func AddUser(login, lvl string, message twitch.PrivateMessage, app *Application) {
func (app *Application) AddUser(login, lvl string, message twitch.PrivateMessage) {
userId, err := decapi.GetIdByLogin(login)
if err != nil {
app.Logger.Error(err)
@ -43,7 +43,7 @@ func AddUser(login, lvl string, message twitch.PrivateMessage, app *Application)
}
}
func DeleteUser(login string, message twitch.PrivateMessage, app *Application) {
func (app *Application) DeleteUser(login string, message twitch.PrivateMessage) {
err := app.Models.Users.Delete(login)
if err != nil {
common.Send(message.Channel, "Something went wrong FeelsBadMan", app.TwitchClient)