diff --git a/djpianalto.com/goff/exts/tags.go b/djpianalto.com/goff/exts/tags.go index 81a5e0c..293222d 100644 --- a/djpianalto.com/goff/exts/tags.go +++ b/djpianalto.com/goff/exts/tags.go @@ -2,6 +2,7 @@ package exts import ( "djpianalto.com/goff/djpianalto.com/goff/utils" + "errors" "fmt" "github.com/dustinpianalto/disgoman" "github.com/kballard/go-shellquote" @@ -9,12 +10,16 @@ import ( "strings" ) -func addTagCommand(ctx disgoman.Context, args []string) error { +func addTagCommand(ctx disgoman.Context, args []string) { if len(args) >= 1 { args, err := shellquote.Split(strings.Join(args, " ")) if err != nil { - ctx.Send(err.Error()) - return err + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "", + Error: err, + } + return } queryString := `SELECT tags.id, tags.tag, tags.content from tags WHERE tags.guild_id = $1 @@ -24,45 +29,75 @@ func addTagCommand(ctx disgoman.Context, args []string) error { if err := row.Scan(&dest); err != nil { tag := args[0] if tag == "" { - ctx.Send("That is not a valid tag name") - return nil + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "That is not a valid tag name", + Error: err, + } + return } if len(args) <= 1 { - ctx.Send("I got a name but no value.") - return nil + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "I got a name but no value", + Error: err, + } + return } value := args[1] if value == "" { - ctx.Send("You have to include a content for the tag") - return nil + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "You have to include a content for the tag", + Error: err, + } + return } queryString = `INSERT INTO tags (tag, content, creator, guild_id) VALUES ($1, $2, $3, $4);` _, err := utils.Database.Exec(queryString, tag, value, ctx.Message.Author.ID, ctx.Guild.ID) if err != nil { ctx.Send(err.Error()) - return err + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "", + Error: err, + } + return } ctx.Send(fmt.Sprintf("Tag %v added successfully.", tag)) - return nil + return } else { - ctx.Send("That tag already exists.") - return nil + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "That tag already exists", + Error: err, + } + return } } else { ctx.Send("You need to tell me what tag you want to add...") - return nil + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "You need to tell me what tag you want to add...", + Error: errors.New("nothing to do"), + } + return } } -func tagCommand(ctx disgoman.Context, args []string) error { +func tagCommand(ctx disgoman.Context, args []string) { if len(args) >= 1 { tagString := strings.Join(args, " ") queryString := `SELECT tags.id, tags.tag, tags.content from tags WHERE tags.guild_id = $1;` rows, err := utils.Database.Query(queryString, ctx.Guild.ID) if err != nil { - ctx.Send(err.Error()) - return err + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "", + Error: err, + } + return } else { for rows.Next() { var ( @@ -75,14 +110,23 @@ func tagCommand(ctx disgoman.Context, args []string) error { } if tagString == tag { ctx.Send(content) - return nil + return } } - ctx.Send(fmt.Sprintf("Tag %v not found", args[0])) - return nil + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: fmt.Sprintf("Tag %v not found", args[0]), + Error: err, + } + return } } else { - ctx.Send("I need a tag to check fetch...") - return nil + ctx.Send("I need a tag to fetch...") + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "I need a tag to fetch...", + Error: errors.New("nothing to do"), + } + return } }