Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions event/reaction/ReactionBase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2022-2023 Kesuaheli
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package reaction

import "github.com/bwmarrin/discordgo"

type Reaction interface {

// All things that should happen when reacting to a message.
AddHandler() func(s *discordgo.Session, i *discordgo.MessageReactionAdd)

// All things that should happen when removing a reaction from a message.
RemoveHandler() func(s *discordgo.Session, i *discordgo.MessageReactionRemove)
}

var ReactionMap map[string]Reaction

func init() {
ReactionMap = make(map[string]Reaction)
}
35 changes: 35 additions & 0 deletions event/reactions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2022-2023 Kesuaheli
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package event

import (
"github.com/bwmarrin/discordgo"

"cake4everybot/event/reaction"
)

func addReactionListeners(s *discordgo.Session) {
s.AddHandler(func(s *discordgo.Session, event *discordgo.MessageReactionAdd) {
if r, ok := reaction.ReactionMap[event.Emoji.Name]; ok {
r.AddHandler()(s, event)
}
})
s.AddHandler(func(s *discordgo.Session, event *discordgo.MessageReactionRemove) {
if r, ok := reaction.ReactionMap[event.Emoji.Name]; ok {
r.RemoveHandler()(s, event)
}
})

}