diff --git a/commands/commands.go b/commands/commands.go index abb85f3..022d20d 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -21,6 +21,9 @@ var commands = []command{ } func Event(dg *discordgo.Session, m *discordgo.MessageCreate) { + if m.Author.Bot { + return + } if !strings.HasPrefix(m.Content, "milen ") { return } diff --git a/reactrole/listener.go b/reactrole/listener.go index 712e483..577eb49 100644 --- a/reactrole/listener.go +++ b/reactrole/listener.go @@ -8,22 +8,38 @@ import ( ) 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) + 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) + err = dg.GuildMemberRoleRemove(r.GuildID, r.UserID, role) if err != nil { util.ReportError(dg, err) } diff --git a/util/query.go b/util/query.go new file mode 100644 index 0000000..f66f827 --- /dev/null +++ b/util/query.go @@ -0,0 +1,13 @@ +package util + +import ( + "github.com/bwmarrin/discordgo" +) + +func GetMember(dg *discordgo.Session, guildID string, userID string) (*discordgo.Member, error) { + member, err := dg.State.Member(guildID, userID) + if err == nil { + return member, nil + } + return dg.GuildMember(guildID, userID) +}