mirror of https://github.com/velour/catbase.git
tappd: optionally use files instead of embeds
This commit is contained in:
parent
435f45fa7c
commit
df9db4e6fd
|
@ -73,6 +73,13 @@ func (c *Config) GetInt(key string, fallback int) int {
|
||||||
return i
|
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
|
// Get is a shortcut for GetString
|
||||||
func (c *Config) Get(key, fallback string) string {
|
func (c *Config) Get(key, fallback string) string {
|
||||||
return c.GetString(key, fallback)
|
return c.GetString(key, fallback)
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package tappd
|
package tappd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
"github.com/gabriel-vasile/mimetype"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/velour/catbase/bot"
|
"github.com/velour/catbase/bot"
|
||||||
"github.com/velour/catbase/config"
|
"github.com/velour/catbase/config"
|
||||||
|
@ -134,18 +136,35 @@ func (p *Tappd) tap(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
embed := &discordgo.MessageEmbed{
|
embeds := []*discordgo.MessageEmbed{{
|
||||||
Description: longMsg,
|
Description: longMsg,
|
||||||
Image: &discordgo.MessageEmbedImage{
|
Image: &discordgo.MessageEmbedImage{
|
||||||
URL: info.BotURL,
|
URL: info.BotURL,
|
||||||
Width: info.W,
|
Width: info.W,
|
||||||
Height: info.H,
|
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{
|
err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
Data: &discordgo.InteractionResponseData{
|
Data: &discordgo.InteractionResponseData{
|
||||||
Embeds: []*discordgo.MessageEmbed{embed},
|
Embeds: embeds,
|
||||||
|
Files: files,
|
||||||
|
Content: content,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue