diff --git a/discord/embeds.go b/discord/embeds.go index 69834a9e..26dd8bcb 100644 --- a/discord/embeds.go +++ b/discord/embeds.go @@ -1,6 +1,10 @@ package discord -import "github.com/bwmarrin/discordgo" +import ( + "fmt" + + "github.com/bwmarrin/discordgo" +) func helpEmbed(s *discordgo.Session) *discordgo.MessageEmbed { return &discordgo.MessageEmbed{ @@ -56,3 +60,11 @@ func botWalletEmbed(s *discordgo.Session, i *discordgo.InteractionCreate, result Description: result, } } + +func errorEmbedMessage(reason string) *discordgo.MessageEmbed { + return &discordgo.MessageEmbed{ + Title: "Error", + Description: fmt.Sprintf("An error occurred, please try again! : %s", reason), + Color: 0xFF0000, // Red color + } +} diff --git a/discord/handlers.go b/discord/handlers.go index eaca56ae..6f544abf 100644 --- a/discord/handlers.go +++ b/discord/handlers.go @@ -2,6 +2,7 @@ package discord import ( "fmt" + "strings" "github.com/bwmarrin/discordgo" "github.com/kehiy/RoboPac/log" @@ -37,12 +38,23 @@ func claimCommandHandler(db *DiscordBot, s *discordgo.Session, i *discordgo.Inte log.Info("new claim request", "discordID", i.Member.User.ID, "mainNetAddr", mainnetAddr, "testNetAddr", testnetAddr) + testnetAddr = strings.TrimPrefix(testnetAddr, "testnet-addr:") + mainnetAddr = strings.TrimPrefix(mainnetAddr, "mainnet-addr:") + command := fmt.Sprintf("claim %s %s %s", i.Member.User.ID, testnetAddr, mainnetAddr) result, err := db.BotEngine.Run(command) if err != nil { - msg := fmt.Sprintf("an error occurred while claiming: %v", err) - _, _ = s.ChannelMessageSend(i.ChannelID, msg) + errorEmbed := errorEmbedMessage(err.Error()) + + response := &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Embeds: []*discordgo.MessageEmbed{errorEmbed}, + }, + } + + _ = s.InteractionRespond(i.Interaction, response) return } @@ -68,8 +80,16 @@ func claimerInfoCommandHandler(db *DiscordBot, s *discordgo.Session, i *discordg result, err := db.BotEngine.Run(command) if err != nil { - msg := fmt.Sprintf("an error occurred : %v", err) - _, _ = s.ChannelMessageSend(i.ChannelID, msg) + errorEmbed := errorEmbedMessage(err.Error()) + + response := &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Embeds: []*discordgo.MessageEmbed{errorEmbed}, + }, + } + + _ = s.InteractionRespond(i.Interaction, response) return } @@ -95,8 +115,16 @@ func nodeInfoCommandHandler(db *DiscordBot, s *discordgo.Session, i *discordgo.I result, err := db.BotEngine.Run(command) if err != nil { - msg := fmt.Sprintf("an error occurred : %v", err) - _, _ = s.ChannelMessageSend(i.ChannelID, msg) + errorEmbed := errorEmbedMessage(err.Error()) + + response := &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Embeds: []*discordgo.MessageEmbed{errorEmbed}, + }, + } + + _ = s.InteractionRespond(i.Interaction, response) return } @@ -121,8 +149,16 @@ func networkHealthCommandHandler(db *DiscordBot, s *discordgo.Session, i *discor result, err := db.BotEngine.Run(command) if err != nil { - msg := fmt.Sprintf("an error occurred : %v", err) - _, _ = s.ChannelMessageSend(i.ChannelID, msg) + errorEmbed := errorEmbedMessage(err.Error()) + + response := &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Embeds: []*discordgo.MessageEmbed{errorEmbed}, + }, + } + + _ = s.InteractionRespond(i.Interaction, response) return } @@ -145,8 +181,16 @@ func networkStatusCommandHandler(db *DiscordBot, s *discordgo.Session, i *discor result, err := db.BotEngine.Run("network") if err != nil { - msg := fmt.Sprintf("an error occurred : %v", err) - _, _ = s.ChannelMessageSend(i.ChannelID, msg) + errorEmbed := errorEmbedMessage(err.Error()) + + response := &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Embeds: []*discordgo.MessageEmbed{errorEmbed}, + }, + } + + _ = s.InteractionRespond(i.Interaction, response) return }