From 4744a54079f85d4e694242bbfbdb27d172404256 Mon Sep 17 00:00:00 2001 From: Dusty Pianalto Date: Sun, 19 Apr 2020 17:11:52 -0800 Subject: [PATCH] Update util commands to use error channel --- djpianalto.com/goff/exts/utils.go | 58 ++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/djpianalto.com/goff/exts/utils.go b/djpianalto.com/goff/exts/utils.go index aa75c2e..b0983e2 100644 --- a/djpianalto.com/goff/exts/utils.go +++ b/djpianalto.com/goff/exts/utils.go @@ -11,15 +11,21 @@ import ( "time" ) -func pingCommand(ctx disgoman.Context, _ []string) error { +func pingCommand(ctx disgoman.Context, _ []string) { timeBefore := time.Now() msg, _ := ctx.Send("Pong!") took := time.Now().Sub(timeBefore) _, err := ctx.Session.ChannelMessageEdit(ctx.Message.ChannelID, msg.ID, fmt.Sprintf("Pong!\nPing Took **%s**", took.String())) - return err + if err != nil { + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "Ping Failed", + Error: err, + } + } } -func inviteCommand(ctx disgoman.Context, args []string) error { +func inviteCommand(ctx disgoman.Context, args []string) { var ids []string if len(args) == 0 { ids = []string{ctx.Session.State.User.ID} @@ -30,30 +36,48 @@ func inviteCommand(ctx disgoman.Context, args []string) error { } for _, id := range ids { url := fmt.Sprintf("", id) - ctx.Send(url) + _, err := ctx.Send(url) + if err != nil { + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "Couldn't send the invite link.", + Error: err, + } + } } - return nil } -func gitCommand(ctx disgoman.Context, _ []string) error { +func gitCommand(ctx disgoman.Context, _ []string) { embed := &discordgo.MessageEmbed{ Title: "Hi there, My code is on Github", Color: 0, URL: "https://github.com/dustinpianalto/Goff", } _, err := ctx.Session.ChannelMessageSendEmbed(ctx.Channel.ID, embed) - return err + if err != nil { + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "Git failed", + Error: err, + } + } } -func sayCommand(ctx disgoman.Context, args []string) error { +func sayCommand(ctx disgoman.Context, args []string) { resp := strings.Join(args, " ") resp = strings.ReplaceAll(resp, "@everyone", "@\ufff0everyone") resp = strings.ReplaceAll(resp, "@here", "@\ufff0here") _, err := ctx.Session.ChannelMessageSend(ctx.Message.ChannelID, resp) - return err + if err != nil { + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "Say Failed", + Error: err, + } + } } -func userCommand(ctx disgoman.Context, args []string) error { +func userCommand(ctx disgoman.Context, args []string) { var member *discordgo.Member if len(args) == 0 { member, _ = ctx.Session.GuildMember(ctx.Guild.ID, ctx.Message.Author.ID) @@ -65,7 +89,11 @@ func userCommand(ctx disgoman.Context, args []string) error { member, err = ctx.Session.GuildMember(ctx.Guild.ID, args[0]) } if err != nil { - return err + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "Couldn't get that member", + Error: err, + } } } thumb := &discordgo.MessageEmbedThumbnail{ @@ -124,5 +152,11 @@ func userCommand(ctx disgoman.Context, args []string) error { }, } _, err := ctx.Session.ChannelMessageSendEmbed(ctx.Channel.ID, embed) - return err + if err != nil { + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "Couldn't send the user embed", + Error: err, + } + } }