mirror of https://github.com/velour/catbase.git
Compare commits
No commits in common. "8817df15f0a24e741bc693f68505cef179e2d814" and "a30be0df8f6853995f23b3a0e8e4178fc816f21e" have entirely different histories.
8817df15f0
...
a30be0df8f
|
@ -102,7 +102,7 @@ func (p *MemePlugin) help(c bot.Connector, kind bot.Kind, message msg.Message, a
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MemePlugin) bully(c bot.Connector, format, id string) (image.Image, string) {
|
func (p *MemePlugin) bully(c bot.Connector, format, id string) image.Image {
|
||||||
bullyIcon := ""
|
bullyIcon := ""
|
||||||
|
|
||||||
for _, bully := range p.c.GetArray("meme.bully", []string{}) {
|
for _, bully := range p.c.GetArray("meme.bully", []string{}) {
|
||||||
|
@ -114,14 +114,13 @@ func (p *MemePlugin) bully(c bot.Connector, format, id string) (image.Image, str
|
||||||
}
|
}
|
||||||
formats := p.c.GetMap("meme.memes", defaultFormats)
|
formats := p.c.GetMap("meme.memes", defaultFormats)
|
||||||
format = randEntry(formats)
|
format = randEntry(formats)
|
||||||
log.Debug().Msgf("After bullying:\nFormat: %s", format)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if u, err := c.Profile(id); bullyIcon == "" && err == nil {
|
if u, err := c.Profile(id); bullyIcon == "" && err == nil {
|
||||||
if u.IconImg != nil {
|
if u.IconImg != nil {
|
||||||
return u.IconImg, format
|
return u.IconImg
|
||||||
}
|
}
|
||||||
bullyIcon = u.Icon
|
bullyIcon = u.Icon
|
||||||
}
|
}
|
||||||
|
@ -134,7 +133,7 @@ func (p *MemePlugin) bully(c bot.Connector, format, id string) (image.Image, str
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("error downloading bully icon")
|
log.Error().Err(err).Msg("error downloading bully icon")
|
||||||
}
|
}
|
||||||
return bullyImg, format
|
return bullyImg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MemePlugin) sendMeme(c bot.Connector, channel, channelName, msgID string, from *user.User, text string) {
|
func (p *MemePlugin) sendMeme(c bot.Connector, channel, channelName, msgID string, from *user.User, text string) {
|
||||||
|
@ -192,7 +191,7 @@ func (p *MemePlugin) sendMeme(c bot.Connector, channel, channelName, msgID strin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bullyImg, format := p.bully(c, format, from.ID)
|
bullyImg := p.bully(c, format, from.ID)
|
||||||
|
|
||||||
id, w, h, err := p.genMeme(format, bullyImg, config)
|
id, w, h, err := p.genMeme(format, bullyImg, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -21,18 +21,6 @@ const (
|
||||||
closingTagSuffix = "\" />"
|
closingTagSuffix = "\" />"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HTTPClient interface {
|
|
||||||
Do(req *http.Request) (*http.Response, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
client HTTPClient
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
client = &http.Client{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type NerdepediaPlugin struct {
|
type NerdepediaPlugin struct {
|
||||||
bot bot.Bot
|
bot bot.Bot
|
||||||
config *config.Config
|
config *config.Config
|
||||||
|
@ -49,50 +37,26 @@ func New(b bot.Bot) *NerdepediaPlugin {
|
||||||
return np
|
return np
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultSites() map[string]string {
|
|
||||||
starWars := "http://starwars.wikia.com/wiki/Special:Random"
|
|
||||||
starTrek := "http://memory-alpha.wikia.com/wiki/Special:Random"
|
|
||||||
dune := "http://dune.wikia.com/wiki/Special:Random"
|
|
||||||
lotr := "http://lotr.wikia.com/wiki/Special:Random"
|
|
||||||
pokemon := "http://pokemon.wikia.com/wiki/Special:Random"
|
|
||||||
|
|
||||||
return map[string]string{
|
|
||||||
"may the force be with you": starWars,
|
|
||||||
"help me obi-wan": starWars,
|
|
||||||
|
|
||||||
"beam me up scotty": starTrek,
|
|
||||||
"live long and prosper": starTrek,
|
|
||||||
|
|
||||||
"bless the maker": dune,
|
|
||||||
"i must not fear": dune,
|
|
||||||
"the spice must flow": dune,
|
|
||||||
|
|
||||||
"my precious": lotr,
|
|
||||||
"one ring to rule them all": lotr,
|
|
||||||
"one does not simply walk into mordor": lotr,
|
|
||||||
|
|
||||||
"pikachu i choose you": pokemon,
|
|
||||||
"gotta catch em all": pokemon,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Message responds to the bot hook on recieving messages.
|
// Message responds to the bot hook on recieving messages.
|
||||||
// This function returns true if the plugin responds in a meaningful way to the users message.
|
// This function returns true if the plugin responds in a meaningful way to the users message.
|
||||||
// Otherwise, the function returns false and the bot continues execution of other plugins.
|
// Otherwise, the function returns false and the bot continues execution of other plugins.
|
||||||
func (p *NerdepediaPlugin) message(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool {
|
func (p *NerdepediaPlugin) message(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool {
|
||||||
lowerCase := strings.ToLower(message.Body)
|
lowerCase := strings.ToLower(message.Body)
|
||||||
query := ""
|
query := ""
|
||||||
queries := p.config.GetMap("nerdepedia.sites", defaultSites())
|
if lowerCase == "may the force be with you" || lowerCase == "help me obi-wan" {
|
||||||
for k, v := range queries {
|
query = "http://starwars.wikia.com/wiki/Special:Random"
|
||||||
if lowerCase == k {
|
} else if lowerCase == "beam me up scotty" || lowerCase == "live long and prosper" {
|
||||||
query = v
|
query = "http://memory-alpha.wikia.com/wiki/Special:Random"
|
||||||
break
|
} else if lowerCase == "bless the maker" || lowerCase == "i must not fear" || lowerCase == "the spice must flow" {
|
||||||
}
|
query = "http://dune.wikia.com/wiki/Special:Random"
|
||||||
|
} else if lowerCase == "my precious" || lowerCase == "one ring to rule them all" || lowerCase == "one does not simply walk into mordor" {
|
||||||
|
query = "http://lotr.wikia.com/wiki/Special:Random"
|
||||||
|
} else if lowerCase == "pikachu i choose you" || lowerCase == "gotta catch em all" {
|
||||||
|
query = "http://pokemon.wikia.com/wiki/Special:Random"
|
||||||
}
|
}
|
||||||
|
|
||||||
if query != "" {
|
if query != "" {
|
||||||
req, _ := http.NewRequest(http.MethodGet, query, nil)
|
resp, err := http.Get(query)
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,42 +3,16 @@
|
||||||
package nerdepedia
|
package nerdepedia
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"github.com/velour/catbase/plugins/cli"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
|
|
||||||
"github.com/velour/catbase/plugins/cli"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/velour/catbase/bot"
|
"github.com/velour/catbase/bot"
|
||||||
"github.com/velour/catbase/bot/msg"
|
"github.com/velour/catbase/bot/msg"
|
||||||
"github.com/velour/catbase/bot/user"
|
"github.com/velour/catbase/bot/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
var body = []byte(`
|
|
||||||
<meta name="description" content="Refresher Reading was a recurring feature appearing in Star Wars Insider. 20 Things You Didn't Know About the Tantive IV 20 Things You Didn't Know About the Mos Eisley Cantina 20 Things You Didn't Know About the Massassi Temples"/>
|
|
||||||
<link rel="canonical" href="https://starwars.fandom.com/wiki/Refresher_Reading"/>`)
|
|
||||||
|
|
||||||
type MockClient struct {
|
|
||||||
Status int
|
|
||||||
Body io.ReadCloser
|
|
||||||
Err error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cl MockClient) Do(req *http.Request) (*http.Response, error) {
|
|
||||||
log.Debug().Msgf("Returning mock response")
|
|
||||||
return &http.Response{
|
|
||||||
StatusCode: cl.Status,
|
|
||||||
Body: cl.Body,
|
|
||||||
}, cl.Err
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeMessage(payload string) (bot.Connector, bot.Kind, msg.Message) {
|
func makeMessage(payload string) (bot.Connector, bot.Kind, msg.Message) {
|
||||||
isCmd := strings.HasPrefix(payload, "!")
|
isCmd := strings.HasPrefix(payload, "!")
|
||||||
if isCmd {
|
if isCmd {
|
||||||
|
@ -56,12 +30,34 @@ func TestWars(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
c := New(mb)
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, c)
|
||||||
client = MockClient{
|
|
||||||
Status: http.StatusOK,
|
|
||||||
Body: ioutil.NopCloser(bytes.NewReader(body)),
|
|
||||||
Err: nil,
|
|
||||||
}
|
|
||||||
res := c.message(makeMessage("help me obi-wan"))
|
res := c.message(makeMessage("help me obi-wan"))
|
||||||
assert.Len(t, mb.Messages, 1)
|
assert.Len(t, mb.Messages, 1)
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTrek(t *testing.T) {
|
||||||
|
mb := bot.NewMockBot()
|
||||||
|
c := New(mb)
|
||||||
|
assert.NotNil(t, c)
|
||||||
|
res := c.message(makeMessage("live long and prosper"))
|
||||||
|
assert.Len(t, mb.Messages, 1)
|
||||||
|
assert.True(t, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDune(t *testing.T) {
|
||||||
|
mb := bot.NewMockBot()
|
||||||
|
c := New(mb)
|
||||||
|
assert.NotNil(t, c)
|
||||||
|
res := c.message(makeMessage("bless the maker"))
|
||||||
|
assert.Len(t, mb.Messages, 1)
|
||||||
|
assert.True(t, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPoke(t *testing.T) {
|
||||||
|
mb := bot.NewMockBot()
|
||||||
|
c := New(mb)
|
||||||
|
assert.NotNil(t, c)
|
||||||
|
res := c.message(makeMessage("gotta catch em all"))
|
||||||
|
assert.Len(t, mb.Messages, 1)
|
||||||
|
assert.True(t, res)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue