75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package cmds
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"fmt"
|
|
"os/exec"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
var GayCommand = &discordgo.ApplicationCommand{
|
|
Name: "gay",
|
|
Description: "Generates a call-out",
|
|
Options: []*discordgo.ApplicationCommandOption{
|
|
{
|
|
Type: discordgo.ApplicationCommandOptionAttachment,
|
|
Name: "image",
|
|
Description: "Image to call-out",
|
|
Required: false,
|
|
},
|
|
{
|
|
Type: discordgo.ApplicationCommandOptionUser,
|
|
Name: "user",
|
|
Description: "User to call-out",
|
|
Required: false,
|
|
},
|
|
},
|
|
}
|
|
|
|
func GayCommandHandler(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
|
return ArrowCommandHandlerHelper("assets/faggot-arrow.png", s, i)
|
|
}
|
|
|
|
func ArrowCommandHandlerHelper(backgroundImage string, s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
|
options := i.ApplicationCommandData().Options
|
|
|
|
optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options))
|
|
for _, opt := range options {
|
|
optionMap[opt.Name] = opt
|
|
}
|
|
|
|
imageReader, err := getImage(s, i)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer imageReader.Close()
|
|
|
|
magickCmd := exec.Command("magick", backgroundImage, "fd:0", "-geometry", "256x256+25+20!", "-background", "none", "-composite", "png:fd:1")
|
|
|
|
magickCmd.Stdin = imageReader
|
|
|
|
magickOutput, err := magickCmd.CombinedOutput()
|
|
if err != nil {
|
|
return errors.New(fmt.Sprintf("magick: %s\n%s", err.Error(), string(magickOutput)))
|
|
}
|
|
|
|
err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
Data: &discordgo.InteractionResponseData{
|
|
Files: []*discordgo.File{
|
|
{
|
|
Name: "callout.png",
|
|
Reader: bytes.NewReader(magickOutput),
|
|
ContentType: "image/png",
|
|
},
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|