mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
pass in a command to the insert method instead of name, text
This commit is contained in:
parent
0099236bc8
commit
650e7f450f
3 changed files with 11 additions and 6 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gempir/go-twitch-irc/v3"
|
"github.com/gempir/go-twitch-irc/v3"
|
||||||
|
"github.com/lyx0/nourybot/internal/data"
|
||||||
"github.com/lyx0/nourybot/pkg/common"
|
"github.com/lyx0/nourybot/pkg/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,7 +23,13 @@ func (app *Application) AddCommand(name string, message twitch.PrivateMessage) {
|
||||||
// e.g. ()addcommand dank FeelsDankMan
|
// e.g. ()addcommand dank FeelsDankMan
|
||||||
// | part1 snip ^ part2 |
|
// | part1 snip ^ part2 |
|
||||||
text := message.Message[prefixLength+len(name) : len(message.Message)]
|
text := message.Message[prefixLength+len(name) : len(message.Message)]
|
||||||
err := app.Models.Commands.Insert(name, text)
|
command := &data.Command{
|
||||||
|
Name: name,
|
||||||
|
Text: text,
|
||||||
|
Category: "uncategorized",
|
||||||
|
Level: 0,
|
||||||
|
}
|
||||||
|
err := app.Models.Commands.Insert(command)
|
||||||
|
|
||||||
// app.Logger.Infow("Message splits",
|
// app.Logger.Infow("Message splits",
|
||||||
// "Command Name:", name,
|
// "Command Name:", name,
|
||||||
|
|
|
@ -97,9 +97,7 @@ func (c CommandModel) SetLevel(name string, level int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert adds a command into the database.
|
// Insert adds a command into the database.
|
||||||
func (c CommandModel) Insert(name, text string) error {
|
func (c CommandModel) Insert(command *Command) error {
|
||||||
perms := 0
|
|
||||||
category := "uncategorized"
|
|
||||||
query := `
|
query := `
|
||||||
INSERT into commands(name, text, category, level)
|
INSERT into commands(name, text, category, level)
|
||||||
VALUES ($1, $2, $3, $4)
|
VALUES ($1, $2, $3, $4)
|
||||||
|
@ -108,7 +106,7 @@ func (c CommandModel) Insert(name, text string) error {
|
||||||
RETURNING id;
|
RETURNING id;
|
||||||
`
|
`
|
||||||
|
|
||||||
args := []interface{}{name, text, category, perms}
|
args := []interface{}{command.Name, command.Text, command.Category, command.Level}
|
||||||
|
|
||||||
result, err := c.DB.Exec(query, args...)
|
result, err := c.DB.Exec(query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -30,7 +30,7 @@ type Models struct {
|
||||||
}
|
}
|
||||||
Commands interface {
|
Commands interface {
|
||||||
Get(name string) (*Command, error)
|
Get(name string) (*Command, error)
|
||||||
Insert(name, text string) error
|
Insert(command *Command) error
|
||||||
SetLevel(name string, level int) error
|
SetLevel(name string, level int) error
|
||||||
SetCategory(name, category string) error
|
SetCategory(name, category string) error
|
||||||
Delete(name string) error
|
Delete(name string) error
|
||||||
|
|
Loading…
Reference in a new issue