diff --git a/config/config.go b/config/config.go index eeecd06..7a6f9a4 100644 --- a/config/config.go +++ b/config/config.go @@ -73,6 +73,13 @@ func (c *Config) GetInt(key string, fallback int) int { return i } +// GetBool returns true or false for config key +// It will assume false for any string except "true" +func (c *Config) GetBool(key string, fallback bool) bool { + val := c.GetString(key, strconv.FormatBool(fallback)) + return val == "true" +} + // Get is a shortcut for GetString func (c *Config) Get(key, fallback string) string { return c.GetString(key, fallback) diff --git a/plugins/tappd/tappd.go b/plugins/tappd/tappd.go index 0596fce..c1114ac 100644 --- a/plugins/tappd/tappd.go +++ b/plugins/tappd/tappd.go @@ -1,8 +1,10 @@ package tappd import ( + "bytes" "fmt" "github.com/bwmarrin/discordgo" + "github.com/gabriel-vasile/mimetype" "github.com/rs/zerolog/log" "github.com/velour/catbase/bot" "github.com/velour/catbase/config" @@ -134,18 +136,35 @@ func (p *Tappd) tap(s *discordgo.Session, i *discordgo.InteractionCreate) { } return } - embed := &discordgo.MessageEmbed{ + embeds := []*discordgo.MessageEmbed{{ Description: longMsg, Image: &discordgo.MessageEmbedImage{ URL: info.BotURL, Width: info.W, Height: info.H, }, + }} + mime := mimetype.Detect(info.Repr) + files := []*discordgo.File{{ + Name: info.ID + mime.Extension(), + ContentType: mime.String(), + Reader: bytes.NewBuffer(info.Repr), + }} + content := info.BotURL + // Yes, the configs are all stringly typed. Get over it. + useEmbed := p.c.GetBool("tappd.embed", false) + if useEmbed { + files = nil + } else { + embeds = nil + content = "" } err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Embeds: []*discordgo.MessageEmbed{embed}, + Embeds: embeds, + Files: files, + Content: content, }, }) if err != nil {