mirror of https://github.com/velour/catbase.git
Compare commits
6 Commits
3297878421
...
b1cec209fe
Author | SHA1 | Date |
---|---|---|
Chris Sexton | b1cec209fe | |
Chris Sexton | 668b0dcb7b | |
Chris Sexton | 4c1a02e9fb | |
Chris Sexton | 274d8f6966 | |
Chris Sexton | 51da6187b0 | |
Chris Sexton | 0453c5ec24 |
|
@ -43,10 +43,8 @@ func (p *Cowboy) register() {
|
||||||
Kind: bot.Startup, IsCmd: false,
|
Kind: bot.Startup, IsCmd: false,
|
||||||
Regex: regexp.MustCompile(`.*`),
|
Regex: regexp.MustCompile(`.*`),
|
||||||
Handler: func(r bot.Request) bool {
|
Handler: func(r bot.Request) bool {
|
||||||
log.Debug().Msgf("Got bot.Startup")
|
|
||||||
switch conn := r.Conn.(type) {
|
switch conn := r.Conn.(type) {
|
||||||
case *discord.Discord:
|
case *discord.Discord:
|
||||||
log.Debug().Msg("Found a discord connection")
|
|
||||||
p.registerCmds(conn)
|
p.registerCmds(conn)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -86,7 +84,7 @@ func (p *Cowboy) makeCowboy(r bot.Request) {
|
||||||
}
|
}
|
||||||
log.Debug().Msgf("makeCowboy: %s", r.Values["what"])
|
log.Debug().Msgf("makeCowboy: %s", r.Values["what"])
|
||||||
base := p.c.Get("baseURL", "http://127.0.0.1:1337")
|
base := p.c.Get("baseURL", "http://127.0.0.1:1337")
|
||||||
u := base + "/cowboy/img/" + r.Values["what"]
|
u := base + "/cowboy/img/hat/" + r.Values["what"]
|
||||||
p.b.Send(r.Conn, bot.Delete, r.Msg.Channel, r.Msg.ID)
|
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{
|
p.b.Send(r.Conn, bot.Message, r.Msg.Channel, "", bot.ImageAttachment{
|
||||||
URL: u,
|
URL: u,
|
||||||
|
@ -148,6 +146,7 @@ func (p *Cowboy) mkOverlayCB(overlay string) func(s *discordgo.Session, i *disco
|
||||||
return func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
return func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
lastEmojy := p.c.Get("cowboy.lastEmojy", "rust")
|
lastEmojy := p.c.Get("cowboy.lastEmojy", "rust")
|
||||||
emojyPlugin := emojy.NewAPI(p.b)
|
emojyPlugin := emojy.NewAPI(p.b)
|
||||||
|
list := map[string]string{}
|
||||||
|
|
||||||
name := i.ApplicationCommandData().Options[0].StringValue()
|
name := i.ApplicationCommandData().Options[0].StringValue()
|
||||||
if overlay == "" {
|
if overlay == "" {
|
||||||
|
@ -183,7 +182,9 @@ func (p *Cowboy) mkOverlayCB(overlay string) func(s *discordgo.Session, i *disco
|
||||||
|
|
||||||
p.c.Set("cowboy.lastEmojy", name)
|
p.c.Set("cowboy.lastEmojy", name)
|
||||||
|
|
||||||
msg = fmt.Sprintf("You replaced %s with a new emojy %s, pardner!", 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])
|
||||||
|
|
||||||
resp:
|
resp:
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
|
|
@ -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"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/velour/catbase/connectors/discord"
|
||||||
"image"
|
"image"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
"math"
|
"math"
|
||||||
|
@ -67,6 +68,17 @@ func (p *EmojyPlugin) setupDB() {
|
||||||
|
|
||||||
func (p *EmojyPlugin) register() {
|
func (p *EmojyPlugin) register() {
|
||||||
ht := bot.HandlerTable{
|
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,
|
Kind: bot.Message, IsCmd: false,
|
||||||
Regex: regexp.MustCompile(`.*`),
|
Regex: regexp.MustCompile(`.*`),
|
||||||
|
@ -121,7 +133,7 @@ func (p *EmojyPlugin) register() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EmojyPlugin) RmEmojy(c bot.Connector, name string) error {
|
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
|
// Call a non-existent emojy a successful remove
|
||||||
if _, ok := onServerList[name]; !ok {
|
if _, ok := onServerList[name]; !ok {
|
||||||
return fmt.Errorf("could not find emojy %s", name)
|
return fmt.Errorf("could not find emojy %s", name)
|
||||||
|
@ -143,7 +155,7 @@ func (p *EmojyPlugin) rmEmojyHandler(r bot.Request, name string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EmojyPlugin) AddEmojy(c bot.Connector, name string) error {
|
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 {
|
if _, ok := onServerList[name]; ok {
|
||||||
return fmt.Errorf("emojy already exists")
|
return fmt.Errorf("emojy already exists")
|
||||||
}
|
}
|
||||||
|
@ -187,7 +199,7 @@ type EmojyCount struct {
|
||||||
OnServer bool `json:"onServer"`
|
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{}
|
out := map[string]string{}
|
||||||
for k, v := range emojy {
|
for k, v := range emojy {
|
||||||
out[v] = k
|
out[v] = k
|
||||||
|
@ -197,7 +209,7 @@ func invertEmojyList(emojy map[string]string) map[string]string {
|
||||||
|
|
||||||
func (p *EmojyPlugin) allCounts() (map[string][]EmojyCount, error) {
|
func (p *EmojyPlugin) allCounts() (map[string][]EmojyCount, error) {
|
||||||
out := map[string][]EmojyCount{}
|
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`
|
q := `select emojy, count(observed) as count from emojyLog group by emojy order by count desc`
|
||||||
result := []EmojyCount{}
|
result := []EmojyCount{}
|
||||||
err := p.db.Select(&result, q)
|
err := p.db.Select(&result, q)
|
||||||
|
|
|
@ -44,8 +44,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row row-cols-5">
|
<div class="row row-cols-5">
|
||||||
<div class="card text-center" v-for="(path, name) in fileList" key="name">
|
<div class="card text-center" v-for="name in fileKeys" key="name">
|
||||||
<img :src="path" class="card-img-top mx-auto d-block" :alt="name" style="max-width: 100px">
|
<img :src="fileList[name]" class="card-img-top mx-auto d-block" :alt="name" style="max-width: 100px">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">{{name}}</h5>
|
<h5 class="card-title">{{name}}</h5>
|
||||||
</div>
|
</div>
|
||||||
|
@ -62,6 +62,7 @@
|
||||||
view: '',
|
view: '',
|
||||||
nav: [],
|
nav: [],
|
||||||
results: [],
|
results: [],
|
||||||
|
fileKeys: [],
|
||||||
fileList: {},
|
fileList: {},
|
||||||
image: null,
|
image: null,
|
||||||
password: ''
|
password: ''
|
||||||
|
@ -90,6 +91,8 @@
|
||||||
.catch(err => (this.err = err))
|
.catch(err => (this.err = err))
|
||||||
axios.get('/emojy/allFiles')
|
axios.get('/emojy/allFiles')
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
|
// stole this somewhere or other as a quick hack
|
||||||
|
this.fileKeys = Object.keys(resp.data).sort()
|
||||||
this.fileList = resp.data
|
this.fileList = resp.data
|
||||||
this.err = ''
|
this.err = ''
|
||||||
})
|
})
|
||||||
|
|
|
@ -54,8 +54,10 @@
|
||||||
<span v-else>❎</span>
|
<span v-else>❎</span>
|
||||||
-
|
-
|
||||||
</span>
|
</span>
|
||||||
<img v-if="emojy.url" :src="emojy.url" :alt="emojy.name" class="img-thumbnail"
|
<span v-if="emojy.url">
|
||||||
style="max-width: 64px; max-height: 64px"/> {{emojy.name}}
|
<img :src="emojy.url" :alt="emojy.name" class="img-thumbnail"
|
||||||
|
style="max-width: 64px; max-height: 64px"/> {{emojy.emojy}}
|
||||||
|
</span>
|
||||||
<span v-else>{{emojy.emojy}}</span>
|
<span v-else>{{emojy.emojy}}</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in New Issue