emojy: trim some characters here and there

This commit is contained in:
Chris Sexton 2022-06-07 10:27:17 -04:00
parent 61cdb66546
commit 2f8bf0edcb
1 changed files with 5 additions and 1 deletions

View File

@ -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
}