Skip to content

Commit

Permalink
extract id if there is one
Browse files Browse the repository at this point in the history
  • Loading branch information
lfayoux committed Jan 2, 2021
1 parent cc44d9e commit cd5fb27
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dgwidgets

import (
"errors"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cd5fb27

Please sign in to comment.