Compare commits

..

No commits in common. "b1cec209fe151292bf69e0833e6fbee12979c223" and "32978784212d45d96926fec70b75c5bb6c2f3bd7" have entirely different histories.

5 changed files with 12 additions and 97 deletions

View File

@ -43,8 +43,10 @@ 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
@ -84,7 +86,7 @@ func (p *Cowboy) makeCowboy(r bot.Request) {
}
log.Debug().Msgf("makeCowboy: %s", r.Values["what"])
base := p.c.Get("baseURL", "http://127.0.0.1:1337")
u := base + "/cowboy/img/hat/" + r.Values["what"]
u := base + "/cowboy/img/" + r.Values["what"]
p.b.Send(r.Conn, bot.Delete, r.Msg.Channel, r.Msg.ID)
p.b.Send(r.Conn, bot.Message, r.Msg.Channel, "", bot.ImageAttachment{
URL: u,
@ -146,7 +148,6 @@ func (p *Cowboy) mkOverlayCB(overlay string) func(s *discordgo.Session, i *disco
return func(s *discordgo.Session, i *discordgo.InteractionCreate) {
lastEmojy := p.c.Get("cowboy.lastEmojy", "rust")
emojyPlugin := emojy.NewAPI(p.b)
list := map[string]string{}
name := i.ApplicationCommandData().Options[0].StringValue()
if overlay == "" {
@ -182,9 +183,7 @@ func (p *Cowboy) mkOverlayCB(overlay string) func(s *discordgo.Session, i *disco
p.c.Set("cowboy.lastEmojy", name)
list = emojy.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])
msg = fmt.Sprintf("You replaced %s with a new emojy %s, pardner!", lastEmojy, name)
resp:
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{

View File

@ -1,67 +0,0 @@
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),
},
})
}

View File

@ -4,7 +4,6 @@ import (
"bytes"
"encoding/base64"
"fmt"
"github.com/velour/catbase/connectors/discord"
"image"
"image/draw"
"math"
@ -68,17 +67,6 @@ 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(`.*`),
@ -133,7 +121,7 @@ func (p *EmojyPlugin) register() {
}
func (p *EmojyPlugin) RmEmojy(c bot.Connector, name string) error {
onServerList := InvertEmojyList(p.b.GetEmojiList(false))
onServerList := invertEmojyList(p.b.GetEmojiList(false))
// Call a non-existent emojy a successful remove
if _, ok := onServerList[name]; !ok {
return fmt.Errorf("could not find emojy %s", name)
@ -155,7 +143,7 @@ func (p *EmojyPlugin) rmEmojyHandler(r bot.Request, name string) bool {
}
func (p *EmojyPlugin) AddEmojy(c bot.Connector, name string) error {
onServerList := InvertEmojyList(p.b.GetEmojiList(false))
onServerList := invertEmojyList(p.b.GetEmojiList(false))
if _, ok := onServerList[name]; ok {
return fmt.Errorf("emojy already exists")
}
@ -199,7 +187,7 @@ type EmojyCount struct {
OnServer bool `json:"onServer"`
}
func InvertEmojyList(emojy map[string]string) map[string]string {
func invertEmojyList(emojy map[string]string) map[string]string {
out := map[string]string{}
for k, v := range emojy {
out[v] = k
@ -209,7 +197,7 @@ func InvertEmojyList(emojy map[string]string) map[string]string {
func (p *EmojyPlugin) allCounts() (map[string][]EmojyCount, error) {
out := map[string][]EmojyCount{}
onServerList := InvertEmojyList(p.b.GetEmojiList(true))
onServerList := invertEmojyList(p.b.GetEmojiList(true))
q := `select emojy, count(observed) as count from emojyLog group by emojy order by count desc`
result := []EmojyCount{}
err := p.db.Select(&result, q)

View File

@ -44,8 +44,8 @@
</div>
<div class="row row-cols-5">
<div class="card text-center" v-for="name in fileKeys" key="name">
<img :src="fileList[name]" class="card-img-top mx-auto d-block" :alt="name" style="max-width: 100px">
<div class="card text-center" v-for="(path, name) in fileList" key="name">
<img :src="path" class="card-img-top mx-auto d-block" :alt="name" style="max-width: 100px">
<div class="card-body">
<h5 class="card-title">{{name}}</h5>
</div>
@ -62,7 +62,6 @@
view: '',
nav: [],
results: [],
fileKeys: [],
fileList: {},
image: null,
password: ''
@ -91,8 +90,6 @@
.catch(err => (this.err = err))
axios.get('/emojy/allFiles')
.then(resp => {
// stole this somewhere or other as a quick hack
this.fileKeys = Object.keys(resp.data).sort()
this.fileList = resp.data
this.err = ''
})

View File

@ -54,10 +54,8 @@
<span v-else></span>
-
</span>
<span v-if="emojy.url">
<img :src="emojy.url" :alt="emojy.name" class="img-thumbnail"
style="max-width: 64px; max-height: 64px"/> {{emojy.emojy}}
</span>
<img v-if="emojy.url" :src="emojy.url" :alt="emojy.name" class="img-thumbnail"
style="max-width: 64px; max-height: 64px"/> {{emojy.name}}
<span v-else>{{emojy.emojy}}</span>
</li>
</ul>