prun-trade-bot-go/lib/helpers/pointers.go

29 lines
777 B
Go

package helpers
import (
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/rs/zerolog"
)
func Pointer[T any](v T) *T {
return &v
}
func EphemeralResponse(format string, any ...any) *discordgo.InteractionResponse {
return &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Content: fmt.Sprintf(format, any...),
},
}
}
func InteractionErrorResponse(session *discordgo.Session, command *discordgo.InteractionCreate, logger *zerolog.Logger, err error) {
err = session.InteractionRespond(command.Interaction, EphemeralResponse("%s", err))
if err != nil {
logger.Error().Err(err).Msg("Unable to respond to request from user")
}
}