Milen/reactrole/listener.go

47 lines
985 B
Go

2020-05-11 05:30:07 +07:00
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) {
2020-05-12 10:35:02 +07:00
member, err := util.GetMember(dg, r.GuildID, r.UserID)
if err != nil {
util.ReportError(dg, err)
return
}
if member.User.Bot {
return
}
2020-05-11 05:30:07 +07:00
role := db.GetReactRole(r.MessageID, r.Emoji.APIName())
if role == "" {
return
}
2020-05-12 10:35:02 +07:00
err = dg.GuildMemberRoleAdd(r.GuildID, r.UserID, role)
2020-05-11 05:30:07 +07:00
if err != nil {
util.ReportError(dg, err)
}
}
func EventRemove(dg *discordgo.Session, r *discordgo.MessageReactionRemove) {
2020-05-12 10:35:02 +07:00
member, err := util.GetMember(dg, r.GuildID, r.UserID)
if err != nil {
util.ReportError(dg, err)
return
}
if member.User.Bot {
return
}
2020-05-11 05:30:07 +07:00
role := db.GetReactRole(r.MessageID, r.Emoji.APIName())
if role == "" {
return
}
2020-05-12 10:35:02 +07:00
err = dg.GuildMemberRoleRemove(r.GuildID, r.UserID, role)
2020-05-11 05:30:07 +07:00
if err != nil {
util.ReportError(dg, err)
}
}