47 lines
985 B
Go
47 lines
985 B
Go
package reactrole
|
|
|
|
import (
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
"gitea.teamortix.com/chanbakjsd/Milen/db"
|
|
"gitea.teamortix.com/chanbakjsd/Milen/util"
|
|
)
|
|
|
|
func EventAdd(dg *discordgo.Session, r *discordgo.MessageReactionAdd) {
|
|
member, err := util.GetMember(dg, r.GuildID, r.UserID)
|
|
if err != nil {
|
|
util.ReportError(dg, err)
|
|
return
|
|
}
|
|
if member.User.Bot {
|
|
return
|
|
}
|
|
role := db.GetReactRole(r.MessageID, r.Emoji.APIName())
|
|
if role == "" {
|
|
return
|
|
}
|
|
err = dg.GuildMemberRoleAdd(r.GuildID, r.UserID, role)
|
|
if err != nil {
|
|
util.ReportError(dg, err)
|
|
}
|
|
}
|
|
|
|
func EventRemove(dg *discordgo.Session, r *discordgo.MessageReactionRemove) {
|
|
member, err := util.GetMember(dg, r.GuildID, r.UserID)
|
|
if err != nil {
|
|
util.ReportError(dg, err)
|
|
return
|
|
}
|
|
if member.User.Bot {
|
|
return
|
|
}
|
|
role := db.GetReactRole(r.MessageID, r.Emoji.APIName())
|
|
if role == "" {
|
|
return
|
|
}
|
|
err = dg.GuildMemberRoleRemove(r.GuildID, r.UserID, role)
|
|
if err != nil {
|
|
util.ReportError(dg, err)
|
|
}
|
|
}
|