diff --git a/.gitignore b/.gitignore index dffcaf7..f03a51b 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,4 @@ run.sh .idea logs util/files +impact.ttf diff --git a/go.mod b/go.mod index 970f7ee..1961ca4 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,6 @@ require ( github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82 // indirect github.com/gonum/internal v0.0.0-20181124074243-f884aa714029 // indirect github.com/google/uuid v1.1.1 - github.com/gorilla/mux v1.7.4 github.com/gorilla/websocket v1.4.1 // indirect github.com/james-bowman/nlp v0.0.0-20191016091239-d9dbfaff30c6 github.com/james-bowman/sparse v0.0.0-20190423065201-80c6877364c7 // indirect diff --git a/go.sum b/go.sum index 521b1ac..9d6236d 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,6 @@ github.com/gonum/internal v0.0.0-20181124074243-f884aa714029 h1:8jtTdc+Nfj9AR+0s github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhSyOzRwuXkOgAvijx4o+4YMUJJo9OvPYMkks= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= -github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ= github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= diff --git a/plugins/meme/meme.go b/plugins/meme/meme.go index 3648aa3..a81ee85 100644 --- a/plugins/meme/meme.go +++ b/plugins/meme/meme.go @@ -9,6 +9,7 @@ import ( "net/url" "path" "strings" + "time" "github.com/fogleman/gg" "github.com/google/uuid" @@ -16,6 +17,7 @@ import ( "github.com/velour/catbase/bot" "github.com/velour/catbase/bot/msg" + "github.com/velour/catbase/bot/user" "github.com/velour/catbase/config" ) @@ -59,14 +61,17 @@ func (p *MemePlugin) registerWeb(c bot.Connector) { r.ParseForm() log.Debug().Msgf("Meme:\n%+v", r.PostForm.Get("text")) channel := r.PostForm.Get("channel_id") - user := r.PostForm.Get("user_name") + channelName := r.PostForm.Get("channel_name") + from := r.PostForm.Get("user_name") log.Debug().Msgf("channel: %s", channel) parts := strings.SplitN(r.PostForm.Get("text"), " ", 2) + isCmd, message := bot.IsCmd(p.c, parts[1]) + log.Debug().Strs("parts", parts).Msgf("Meme:\n%+v", r.PostForm.Get("text")) w.WriteHeader(200) - id := p.genMeme(parts[0], parts[1]) + id := p.genMeme(parts[0], message) baseURL := p.c.Get("BaseURL", `https://catbase.velour.ninja`) u, _ := url.Parse(baseURL) u.Path = path.Join(u.Path, "meme", "img", id) @@ -74,9 +79,23 @@ func (p *MemePlugin) registerWeb(c bot.Connector) { 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", user, parts[1]), + 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(), + } + + p.bot.Receive(c, bot.Message, m) }) http.HandleFunc("/meme/img/", func(w http.ResponseWriter, r *http.Request) { diff --git a/plugins/talker/talker.go b/plugins/talker/talker.go index 7dc6fa2..4f35a06 100644 --- a/plugins/talker/talker.go +++ b/plugins/talker/talker.go @@ -70,7 +70,7 @@ func (p *TalkerPlugin) message(c bot.Connector, kind bot.Kind, message msg.Messa if message.Command && strings.HasPrefix(lowermessage, "cowsay") { msg, err := p.cowSay(strings.TrimPrefix(message.Body, "cowsay ")) if err != nil { - p.bot.Send(c, bot.Message, channel, "Error running cowsay: %s", err) + p.bot.Send(c, bot.Message, channel, fmt.Sprintf("Error running cowsay: %s", err)) return true } p.bot.Send(c, bot.Message, channel, msg)