Skip to content

Commit

Permalink
validate keycommands exists in MB_ROLES variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Schröter, Daniel Christian (BnotK) committed Feb 22, 2023
1 parent 25f5cba commit 1b38245
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,24 @@ func handlePost(post *model.Post) {
return
}
keycommand := strings.Trim(words[0], "!")
if command, ok := commands[keycommand]; ok {
confighandler.App.Logger.Debug().Str("function", "handlePost").Str("type", "request").Interface("received_keycommand", keycommand)
sendMsgToChannel("Executing command...", post.Id, false)
cmdout, err := command.executeFn(words, post.Message)
if err != nil {
confighandler.App.Logger.Error().Stack().Err(err).Str("function", "handlePost").Msg("Executing command failed for some reason")
// Check if command role is listed in MB_ROLES
if strings.Contains(confighandler.App.Config.MB_ROLES, keycommand) {
if command, ok := commands[keycommand]; ok {
confighandler.App.Logger.Debug().Str("function", "handlePost").Str("type", "request").Interface("received_keycommand", keycommand)
sendMsgToChannel("Executing command...", post.Id, false)
cmdout, err := command.executeFn(words, post.Message)
if err != nil {
confighandler.App.Logger.Error().Stack().Err(err).Str("function", "handlePost").Msg("Executing command failed for some reason")
}
sendMsgToChannel(cmdout, post.Id, true)
}
sendMsgToChannel(cmdout, post.Id, true)
} else if keycommand == "help" {
confighandler.App.Logger.Debug().Str("function", "handlePost").Str("type", "request").Interface("received_keycommand", keycommand)
help := "The following commands are available to use:\n"
for _, command := range commands {
help += command.help
if strings.Contains(confighandler.App.Config.MB_ROLES, command.name) {
help += command.help
}
}
sendMsgToChannel(help, post.Id, false)
return
Expand Down

0 comments on commit 1b38245

Please sign in to comment.