Skip to content

Commit

Permalink
autorole: ignore muted users (#1806)
Browse files Browse the repository at this point in the history
  • Loading branch information
jo3-l authored Dec 31, 2024
1 parent ab5971f commit 8c996a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions autorole/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
scheduledEventsModels "github.com/botlabs-gg/yagpdb/v2/common/scheduledevents2/models"
"github.com/botlabs-gg/yagpdb/v2/lib/dcmd"
"github.com/botlabs-gg/yagpdb/v2/lib/discordgo"
"github.com/botlabs-gg/yagpdb/v2/moderation"
"github.com/mediocregopher/radix/v3"
)

Expand Down Expand Up @@ -489,8 +490,9 @@ func handleAssignRole(evt *scheduledEventsModels.ScheduledEvent, data interface{
func handleGuildMemberUpdate(evt *eventsystem.EventData) (retry bool, err error) {
update := evt.GuildMemberUpdate()
member := update.Member
// ignore timedout users
if member.CommunicationDisabledUntil != nil && member.CommunicationDisabledUntil.After(time.Now()) {
// Ignore timed out and muted users.
if (member.CommunicationDisabledUntil != nil && member.CommunicationDisabledUntil.After(time.Now())) ||
moderation.IsMuted(member.GuildID, member.User.ID) {
return false, nil
}

Expand Down
11 changes: 11 additions & 0 deletions moderation/punishments.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,17 @@ const (
ErrNoMuteRole = errors.Sentinel("No mute role")
)

func IsMuted(guildID, userID int64) bool {
mute, err := models.MutedUsers(
models.MutedUserWhere.UserID.EQ(userID),
models.MutedUserWhere.GuildID.EQ(guildID),
).OneG(context.Background())
if err != nil {
return false // assume not muted
}
return mute.ExpiresAt.IsZero() || mute.ExpiresAt.Time.After(time.Now())
}

// Unmut or mute a user, ignore duration if unmuting
// TODO: i don't think we need to track mutes in its own database anymore now with the new scheduled event system
func MuteUnmuteUser(config *Config, mute bool, guildID int64, channel *dstate.ChannelState, message *discordgo.Message, author *discordgo.User, reason string, member *dstate.MemberState, duration int, executedByCommandTemplate bool) error {
Expand Down

0 comments on commit 8c996a4

Please sign in to comment.