mirror of https://github.com/velour/catbase.git
emojy: swap in emojy command
This commit is contained in:
parent
0453c5ec24
commit
51da6187b0
|
@ -43,10 +43,8 @@ func (p *Cowboy) register() {
|
|||
Kind: bot.Startup, IsCmd: false,
|
||||
Regex: regexp.MustCompile(`.*`),
|
||||
Handler: func(r bot.Request) bool {
|
||||
log.Debug().Msgf("Got bot.Startup")
|
||||
switch conn := r.Conn.(type) {
|
||||
case *discord.Discord:
|
||||
log.Debug().Msg("Found a discord connection")
|
||||
p.registerCmds(conn)
|
||||
}
|
||||
return false
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package emojy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/velour/catbase/connectors/discord"
|
||||
)
|
||||
|
||||
func (p *EmojyPlugin) registerCmds(d *discord.Discord) {
|
||||
log.Debug().Msg("About to register some startup commands")
|
||||
cmd := discordgo.ApplicationCommand{
|
||||
Name: "emojy",
|
||||
Description: "swap in an emojy",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Name: "emojy",
|
||||
Description: "which emojy you want swapped in",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := d.RegisterSlashCmd(cmd, p.overlayCB); err != nil {
|
||||
log.Error().Err(err).Msg("could not register emojy command")
|
||||
}
|
||||
}
|
||||
|
||||
func (p *EmojyPlugin) overlayCB(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
lastEmojy := p.c.Get("emojy.lastEmojy", "rust")
|
||||
list := map[string]string{}
|
||||
var err error
|
||||
msg := "hello, user"
|
||||
|
||||
name := i.ApplicationCommandData().Options[0].StringValue()
|
||||
|
||||
if ok, _, _, err := p.isKnownEmojy(name); !ok || err != nil {
|
||||
msg = "I could not find your emojy"
|
||||
goto resp
|
||||
}
|
||||
|
||||
err = p.RmEmojy(p.b.DefaultConnector(), lastEmojy)
|
||||
if err != nil {
|
||||
msg = err.Error()
|
||||
goto resp
|
||||
}
|
||||
|
||||
err = p.UploadEmojyInCache(p.b.DefaultConnector(), name)
|
||||
if err != nil {
|
||||
msg = err.Error()
|
||||
goto resp
|
||||
}
|
||||
|
||||
p.c.Set("emojy.lastEmojy", name)
|
||||
|
||||
list = invertEmojyList(p.b.DefaultConnector().GetEmojiList(true))
|
||||
msg = fmt.Sprintf("You replaced %s with a new emojy %s <:%s:%s>, pardner!", lastEmojy, name, name, list[name])
|
||||
|
||||
resp:
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: msg,
|
||||
Flags: uint64(discordgo.MessageFlagsEphemeral),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/velour/catbase/connectors/discord"
|
||||
"image"
|
||||
"image/draw"
|
||||
"math"
|
||||
|
@ -67,6 +68,17 @@ func (p *EmojyPlugin) setupDB() {
|
|||
|
||||
func (p *EmojyPlugin) register() {
|
||||
ht := bot.HandlerTable{
|
||||
{
|
||||
Kind: bot.Startup, IsCmd: false,
|
||||
Regex: regexp.MustCompile(`.*`),
|
||||
Handler: func(r bot.Request) bool {
|
||||
switch conn := r.Conn.(type) {
|
||||
case *discord.Discord:
|
||||
p.registerCmds(conn)
|
||||
}
|
||||
return false
|
||||
},
|
||||
},
|
||||
{
|
||||
Kind: bot.Message, IsCmd: false,
|
||||
Regex: regexp.MustCompile(`.*`),
|
||||
|
|
Loading…
Reference in New Issue