From 2f8bf0edcb328ff51d4a128db6991bedf14b19bb Mon Sep 17 00:00:00 2001 From: Chris Sexton <3216719+chrissexton@users.noreply.github.com> Date: Tue, 7 Jun 2022 10:27:17 -0400 Subject: [PATCH] emojy: trim some characters here and there --- plugins/emojy/emojy.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/emojy/emojy.go b/plugins/emojy/emojy.go index 8c4f50d..3080bcc 100644 --- a/plugins/emojy/emojy.go +++ b/plugins/emojy/emojy.go @@ -48,6 +48,7 @@ func (p *EmojyPlugin) register() { Handler: func(request bot.Request) bool { r := regexp.MustCompile(`:[a-zA-Z0-9_-]+:`) for _, match := range r.FindAllString(request.Msg.Body, -1) { + match = strings.Trim(match, ":") log.Debug().Msgf("Emojy detected: %s", match) p.recordReaction(match) } @@ -128,7 +129,10 @@ func (p *EmojyPlugin) isKnownEmojy(name string) (bool, string, error) { return false, "", err } for _, e := range entries { - if !e.IsDir() && strings.HasPrefix(e.Name(), name) { + if !e.IsDir() && + (strings.HasPrefix(e.Name(), name) || + strings.HasPrefix(e.Name(), strings.Replace(name, "-", "_", -1)) || + strings.HasPrefix(e.Name(), strings.Trim(name, "-_"))) { url := path.Join(baseURL, e.Name()) return true, url, nil }