mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
get user level from database for command permissions
This commit is contained in:
parent
94f21a2a66
commit
a0e724d009
5 changed files with 30 additions and 28 deletions
|
@ -22,16 +22,17 @@ func (app *Application) AddChannel(login string, message twitch.PrivateMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = app.Models.Channels.Insert(channel)
|
err = app.Models.Channels.Insert(channel)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
reply := fmt.Sprintf("Something went wrong FeelsBadMan %s", err)
|
reply := fmt.Sprintf("Something went wrong FeelsBadMan %s", err)
|
||||||
common.Send(message.Channel, reply, app.TwitchClient)
|
common.Send(message.Channel, reply, app.TwitchClient)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
app.TwitchClient.Join(login)
|
||||||
reply := fmt.Sprintf("Added channel %s", login)
|
reply := fmt.Sprintf("Added channel %s", login)
|
||||||
common.Send(message.Channel, reply, app.TwitchClient)
|
common.Send(message.Channel, reply, app.TwitchClient)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *Application) GetAllChannels() {
|
func (app *Application) GetAllChannels() {
|
||||||
|
@ -52,6 +53,8 @@ func (app *Application) DeleteChannel(login string, message twitch.PrivateMessag
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.TwitchClient.Depart(login)
|
||||||
|
|
||||||
reply := fmt.Sprintf("Deleted channel %s", login)
|
reply := fmt.Sprintf("Deleted channel %s", login)
|
||||||
common.Send(message.Channel, reply, app.TwitchClient)
|
common.Send(message.Channel, reply, app.TwitchClient)
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,18 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
// where we are responding.
|
// where we are responding.
|
||||||
target := message.Channel
|
target := message.Channel
|
||||||
|
|
||||||
|
// Userlevel is the level set for a user in the database.
|
||||||
|
// It is NOT same as twitch user/mod.
|
||||||
|
// 1000 = admin
|
||||||
|
// 500 = mod
|
||||||
|
// 100 = normal
|
||||||
|
// If the level returned is 0 then the user was not found in the database.
|
||||||
|
userLevel := app.GetUserLevel(message.User.Name)
|
||||||
|
|
||||||
sugar.Infow("Command received",
|
sugar.Infow("Command received",
|
||||||
// "message", message,
|
// "message", message,
|
||||||
"message.Channel", target,
|
"message.Channel", target,
|
||||||
|
"user level", userLevel,
|
||||||
"message.Message", message.Message,
|
"message.Message", message.Message,
|
||||||
"commandName", commandName,
|
"commandName", commandName,
|
||||||
"cmdParams", cmdParams,
|
"cmdParams", cmdParams,
|
||||||
|
@ -54,7 +63,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "addchannel":
|
case "addchannel":
|
||||||
if message.User.ID != "31437432" { // Limit to myself for now.
|
if userLevel < 1000 { // Limit to myself for now.
|
||||||
return
|
return
|
||||||
} else if msgLen < 2 {
|
} else if msgLen < 2 {
|
||||||
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
||||||
|
@ -65,7 +74,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "adduser":
|
case "adduser":
|
||||||
if message.User.ID != "31437432" { // Limit to myself for now.
|
if userLevel < 1000 { // Limit to myself for now.
|
||||||
return
|
return
|
||||||
} else if msgLen < 3 {
|
} else if msgLen < 3 {
|
||||||
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
||||||
|
@ -76,7 +85,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "edituser": // ()edituser level nourylul 1000
|
case "edituser": // ()edituser level nourylul 1000
|
||||||
if message.User.ID != "31437432" { // Limit to myself for now.
|
if userLevel < 1000 { // Limit to myself for now.
|
||||||
return
|
return
|
||||||
} else if msgLen < 4 {
|
} else if msgLen < 4 {
|
||||||
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
||||||
|
@ -88,7 +97,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "debug": // ()edituser level nourylul 1000
|
case "debug": // ()edituser level nourylul 1000
|
||||||
if message.User.ID != "31437432" { // Limit to myself for now.
|
if userLevel < 1000 { // Limit to myself for now.
|
||||||
return
|
return
|
||||||
} else if msgLen < 3 {
|
} else if msgLen < 3 {
|
||||||
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
||||||
|
@ -100,7 +109,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "deletechannel":
|
case "deletechannel":
|
||||||
if message.User.ID != "31437432" { // Limit to myself for now.
|
if userLevel < 1000 { // Limit to myself for now.
|
||||||
return
|
return
|
||||||
} else if msgLen < 2 {
|
} else if msgLen < 2 {
|
||||||
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
||||||
|
@ -111,7 +120,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "deleteuser":
|
case "deleteuser":
|
||||||
if message.User.ID != "31437432" { // Limit to myself for now.
|
if userLevel < 1000 { // Limit to myself for now.
|
||||||
return
|
return
|
||||||
} else if msgLen < 2 {
|
} else if msgLen < 2 {
|
||||||
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
||||||
|
@ -153,7 +162,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
commands.Currency(target, cmdParams[1], cmdParams[2], cmdParams[4], app.TwitchClient)
|
commands.Currency(target, cmdParams[1], cmdParams[2], cmdParams[4], app.TwitchClient)
|
||||||
return
|
return
|
||||||
case "echo":
|
case "echo":
|
||||||
if message.User.ID != "31437432" { // Limit to myself for now.
|
if userLevel < 1000 { // Limit to myself for now.
|
||||||
return
|
return
|
||||||
} else if msgLen < 2 {
|
} else if msgLen < 2 {
|
||||||
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
||||||
|
|
|
@ -15,25 +15,6 @@ import (
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type config struct {
|
|
||||||
twitchUsername string
|
|
||||||
twitchOauth string
|
|
||||||
environment string
|
|
||||||
db struct {
|
|
||||||
dsn string
|
|
||||||
maxOpenConns int
|
|
||||||
maxIdleConns int
|
|
||||||
maxIdleTime string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Application struct {
|
|
||||||
TwitchClient *twitch.Client
|
|
||||||
Logger *zap.SugaredLogger
|
|
||||||
Db *sql.DB
|
|
||||||
Models data.Models
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var cfg config
|
var cfg config
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ func (app *Application) handlePrivateMessage(message twitch.PrivateMessage) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message was no command so we just print it.
|
|
||||||
// app.Logger.Infow("Private Message received",
|
// app.Logger.Infow("Private Message received",
|
||||||
// // "message", message,
|
// // "message", message,
|
||||||
// "message.Channel", message.Channel,
|
// "message.Channel", message.Channel,
|
||||||
|
|
|
@ -92,3 +92,13 @@ func (app *Application) EditUserLevel(user, lvl string, message twitch.PrivateMe
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *Application) GetUserLevel(login string) int {
|
||||||
|
user, err := app.Models.Users.Get(login)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
} else {
|
||||||
|
return user.Level
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue