diff --git a/plugins/cowboy/cowboy.go b/plugins/cowboy/cowboy.go index 05e1c43..4fcddc4 100644 --- a/plugins/cowboy/cowboy.go +++ b/plugins/cowboy/cowboy.go @@ -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 diff --git a/plugins/emojy/discordslash.go b/plugins/emojy/discordslash.go new file mode 100644 index 0000000..505b7b8 --- /dev/null +++ b/plugins/emojy/discordslash.go @@ -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), + }, + }) +} diff --git a/plugins/emojy/emojy.go b/plugins/emojy/emojy.go index 7ee2e76..d4ae3e5 100644 --- a/plugins/emojy/emojy.go +++ b/plugins/emojy/emojy.go @@ -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(`.*`),