mirror of https://github.com/velour/catbase.git
Compare commits
No commits in common. "b1cec209fe151292bf69e0833e6fbee12979c223" and "32978784212d45d96926fec70b75c5bb6c2f3bd7" have entirely different histories.
b1cec209fe
...
3297878421
|
@ -43,8 +43,10 @@ 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
|
||||||
|
@ -84,7 +86,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/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.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,
|
||||||
|
@ -146,7 +148,6 @@ 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 == "" {
|
||||||
|
@ -182,9 +183,7 @@ func (p *Cowboy) mkOverlayCB(overlay string) func(s *discordgo.Session, i *disco
|
||||||
|
|
||||||
p.c.Set("cowboy.lastEmojy", name)
|
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, pardner!", lastEmojy, name)
|
||||||
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{
|
||||||
|
|
|
@ -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),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/velour/catbase/connectors/discord"
|
|
||||||
"image"
|
"image"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
"math"
|
"math"
|
||||||
|
@ -68,17 +67,6 @@ 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(`.*`),
|
||||||
|
@ -133,7 +121,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)
|
||||||
|
@ -155,7 +143,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")
|
||||||
}
|
}
|
||||||
|
@ -199,7 +187,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
|
||||||
|
@ -209,7 +197,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="name in fileKeys" key="name">
|
<div class="card text-center" v-for="(path, name) in fileList" key="name">
|
||||||
<img :src="fileList[name]" class="card-img-top mx-auto d-block" :alt="name" style="max-width: 100px">
|
<img :src="path" 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,7 +62,6 @@
|
||||||
view: '',
|
view: '',
|
||||||
nav: [],
|
nav: [],
|
||||||
results: [],
|
results: [],
|
||||||
fileKeys: [],
|
|
||||||
fileList: {},
|
fileList: {},
|
||||||
image: null,
|
image: null,
|
||||||
password: ''
|
password: ''
|
||||||
|
@ -91,8 +90,6 @@
|
||||||
.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,10 +54,8 @@
|
||||||
<span v-else>❎</span>
|
<span v-else>❎</span>
|
||||||
-
|
-
|
||||||
</span>
|
</span>
|
||||||
<span v-if="emojy.url">
|
<img v-if="emojy.url" :src="emojy.url" :alt="emojy.name" class="img-thumbnail"
|
||||||
<img :src="emojy.url" :alt="emojy.name" class="img-thumbnail"
|
style="max-width: 64px; max-height: 64px"/> {{emojy.name}}
|
||||||
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