Compare commits

..

No commits in common. "cee267dbb81afdb260d1a5da18c51a8307c726c3" and "dcb6c3740d17f471291055a9a8f9a59912e66d81" have entirely different histories.

9 changed files with 32 additions and 100 deletions

View File

@ -50,8 +50,6 @@ type bot struct {
password string
passwordCreated time.Time
quiet bool
}
type EndPoint struct {
@ -261,7 +259,3 @@ func (b *bot) GetPassword() string {
}
return b.password
}
func (b *bot) SetQuiet(status bool) {
b.quiet = status
}

View File

@ -54,9 +54,6 @@ func (b *bot) runCallback(conn Connector, plugin Plugin, evt Kind, message msg.M
// Send a message to the connection
func (b *bot) Send(conn Connector, kind Kind, args ...interface{}) (string, error) {
if b.quiet {
return "", nil
}
return conn.Send(kind, args...)
}

View File

@ -68,7 +68,6 @@ type Bot interface {
DefaultConnector() Connector
GetWebNavigation() []EndPoint
GetPassword() string
SetQuiet(bool)
}
// Connector represents a server connection to a chat service

View File

@ -33,7 +33,6 @@ func (mb *MockBot) Who(string) []user.User { return []user.User{} }
func (mb *MockBot) WhoAmI() string { return "tester" }
func (mb *MockBot) DefaultConnector() Connector { return nil }
func (mb *MockBot) GetPassword() string { return "12345" }
func (mb *MockBot) SetQuiet(bool) {}
func (mb *MockBot) Send(c Connector, kind Kind, args ...interface{}) (string, error) {
switch kind {
case Message:

View File

@ -160,14 +160,6 @@ func (c *Config) Set(key, value string) error {
return nil
}
func (c *Config) SetMap(key string, values map[string]string) error {
b, err := json.Marshal(values)
if err != nil {
return err
}
return c.Set(key, string(b))
}
func (c *Config) SetArray(key string, values []string) error {
vals := strings.Join(values, ";;")
return c.Set(key, vals)

1
go.mod
View File

@ -35,7 +35,6 @@ require (
github.com/mattn/go-sqlite3 v1.11.0
github.com/mmcdole/gofeed v1.0.0-beta2
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/nlopes/slack v0.6.0
github.com/olebedev/when v0.0.0-20190311101825-c3b538a97254
github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d // indirect

2
go.sum
View File

@ -88,8 +88,6 @@ github.com/mmcdole/gofeed v1.0.0-beta2 h1:CjQ0ADhAwNSb08zknAkGOEYqr8zfZKfrzgk9Bx
github.com/mmcdole/gofeed v1.0.0-beta2/go.mod h1:/BF9JneEL2/flujm8XHoxUcghdTV6vvb3xx/vKyChFU=
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf h1:sWGE2v+hO0Nd4yFU/S/mDBM5plIU8v/Qhfz41hkDIAI=
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf/go.mod h1:pasqhqstspkosTneA62Nc+2p9SOBBYAPbnmRRWPQ0V8=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA=
github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk=
github.com/olebedev/when v0.0.0-20190311101825-c3b538a97254 h1:JYoQR67E1vv1WGoeW8DkdFs7vrIEe/5wP+qJItd5tUE=

View File

@ -55,7 +55,7 @@ var forbiddenKeys = map[string]bool{
func (p *AdminPlugin) message(conn bot.Connector, k bot.Kind, message msg.Message, args ...interface{}) bool {
body := message.Body
if p.quiet && message.Body != "come back" {
if p.quiet {
return true
}
@ -67,16 +67,7 @@ func (p *AdminPlugin) message(conn bot.Connector, k bot.Kind, message msg.Messag
return false
}
if p.quiet && message.Body == "come back" {
p.quiet = false
p.bot.SetQuiet(false)
backMsg := p.bot.Config().Get("admin.comeback", "Okay, I'm back.")
p.bot.Send(conn, bot.Message, message.Channel, backMsg)
return true
}
if strings.ToLower(body) == "reboot" {
p.bot.Send(conn, bot.Message, message.Channel, "brb")
log.Info().Msgf("Got reboot command")
os.Exit(0)
}
@ -84,18 +75,13 @@ func (p *AdminPlugin) message(conn bot.Connector, k bot.Kind, message msg.Messag
if strings.ToLower(body) == "shut up" {
dur := time.Duration(p.cfg.GetInt("quietDuration", 5)) * time.Minute
log.Info().Msgf("Going to sleep for %v, %v", dur, time.Now().Add(dur))
leaveMsg := p.bot.Config().Get("admin.shutup", "Okay. I'll be back later.")
p.bot.Send(conn, bot.Message, message.Channel, leaveMsg)
p.bot.Send(conn, bot.Message, message.Channel, "Okay. I'll be back later.")
p.quiet = true
p.bot.SetQuiet(true)
go func() {
select {
case <-time.After(dur):
p.quiet = false
p.bot.SetQuiet(false)
log.Info().Msg("Waking up from nap.")
backMsg := p.bot.Config().Get("admin.backmsg", "I'm back, bitches.")
p.bot.Send(conn, bot.Message, message.Channel, backMsg)
}
}()
return true
@ -133,15 +119,6 @@ func (p *AdminPlugin) message(conn bot.Connector, k bot.Kind, message msg.Messag
}
p.bot.Send(conn, bot.Message, message.Channel, fmt.Sprintf("Set %s", parts[1]))
return true
} else if parts[0] == "setkey" && len(parts) > 3 {
items := p.cfg.GetMap(parts[1], map[string]string{})
items[parts[2]] = strings.Join(parts[3:], " ")
if err := p.cfg.SetMap(parts[1], items); err != nil {
p.bot.Send(conn, bot.Message, message.Channel, fmt.Sprintf("Set error: %s", err))
return true
}
p.bot.Send(conn, bot.Message, message.Channel, fmt.Sprintf("Set %s", parts[1]))
return true
}
if parts[0] == "get" && len(parts) == 2 && forbiddenKeys[parts[1]] {

View File

@ -13,7 +13,6 @@ import (
"github.com/fogleman/gg"
"github.com/google/uuid"
"github.com/nfnt/resize"
"github.com/rs/zerolog/log"
"github.com/velour/catbase/bot"
@ -91,40 +90,38 @@ func (p *MemePlugin) registerWeb(c bot.Connector) {
log.Debug().Strs("parts", parts).Msgf("Meme:\n%+v", r.PostForm.Get("text"))
w.WriteHeader(200)
top, bottom := "", message
parts = strings.Split(message, "\n")
if len(parts) > 1 {
top, bottom = parts[0], parts[1]
}
id := p.genMeme(format, top, bottom)
baseURL := p.c.Get("BaseURL", `https://catbase.velour.ninja`)
u, _ := url.Parse(baseURL)
u.Path = path.Join(u.Path, "meme", "img", id)
log.Debug().Msgf("image is at %s", u.String())
p.bot.Send(c, bot.Message, channel, "", bot.ImageAttachment{
URL: u.String(),
AltTxt: fmt.Sprintf("%s: %s", from, message),
})
w.Write(nil)
m := msg.Message{
User: &user.User{
ID: from,
Name: from,
Admin: false,
},
Channel: channel,
ChannelName: channelName,
Body: message,
Command: isCmd,
Time: time.Now(),
}
go func() {
top, bottom := "", message
parts = strings.Split(message, "\n")
if len(parts) > 1 {
top, bottom = parts[0], parts[1]
}
id := p.genMeme(format, top, bottom)
baseURL := p.c.Get("BaseURL", `https://catbase.velour.ninja`)
u, _ := url.Parse(baseURL)
u.Path = path.Join(u.Path, "meme", "img", id)
log.Debug().Msgf("image is at %s", u.String())
p.bot.Send(c, bot.Message, channel, "", bot.ImageAttachment{
URL: u.String(),
AltTxt: fmt.Sprintf("%s: %s", from, message),
})
m := msg.Message{
User: &user.User{
ID: from,
Name: from,
Admin: false,
},
Channel: channel,
ChannelName: channelName,
Body: message,
Command: isCmd,
Time: time.Now(),
}
p.bot.Receive(c, bot.Message, m)
}()
p.bot.Receive(c, bot.Message, m)
})
http.HandleFunc("/meme/img/", func(w http.ResponseWriter, r *http.Request) {
@ -185,30 +182,10 @@ func (p *MemePlugin) genMeme(meme, top, bottom string) string {
log.Debug().Msgf("Attempting to download url: %s", u.String())
img := DownloadTemplate(u)
r := img.Bounds()
w := r.Dx()
h := r.Dy()
maxSz := 750.0
if w > h {
scale := maxSz / float64(w)
w = int(float64(w) * scale)
h = int(float64(h) * scale)
} else {
scale := maxSz / float64(h)
w = int(float64(w) * scale)
h = int(float64(h) * scale)
}
log.Debug().Msgf("trynig to resize to %v, %v", w, h)
img = resize.Resize(uint(w), uint(h), img, resize.Lanczos3)
r = img.Bounds()
w = r.Dx()
h = r.Dy()
log.Debug().Msgf("resized to %v, %v", w, h)
m := gg.NewContext(w, h)
m.DrawImage(img, 0, 0)
fontLocation := p.c.Get("meme.font", "impact.ttf")