From cd5fb27d08ca2a69c8bea83e829d8052c184751e Mon Sep 17 00:00:00 2001 From: Lucas Fayoux Date: Fri, 1 Jan 2021 22:03:10 -0500 Subject: [PATCH] extract id if there is one --- widget.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/widget.go b/widget.go index 9429e1f..51a4147 100644 --- a/widget.go +++ b/widget.go @@ -2,6 +2,7 @@ package dgwidgets import ( "errors" + "strings" "sync" "time" @@ -157,9 +158,14 @@ func (w *Widget) Spawn() error { // handler : handler function to call when the emoji is clicked // func(*Widget, *discordgo.MessageReaction) func (w *Widget) Handle(emojiName string, handler WidgetHandler) error { - if _, ok := w.Handlers[emojiName]; !ok { + emojiId := emojiName + if len(emojiName) > 4 && strings.Contains(emojiName, ":") { + emojiId = strings.Split(emojiName, ":")[1] + } + + if _, ok := w.Handlers[emojiId]; !ok { w.Keys = append(w.Keys, emojiName) - w.Handlers[emojiName] = handler + w.Handlers[emojiId] = handler } // if the widget is running, append the added emoji to the message. if w.Running() && w.Message != nil {