Skip to content

Commit

Permalink
fix: issues with discord bot not removing roles
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Oct 9, 2024
1 parent 7ca12ee commit b4bbe16
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 11 deletions.
7 changes: 1 addition & 6 deletions pkg/discord/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ func NewBot(p BotParams) (*Bot, error) {
state.AddIntents(gateway.IntentGuildPresences)
state.AddIntents(gateway.IntentGuildIntegrations)

state.AddHandler(func(*gateway.ReadyEvent) {
me, _ := state.Me()
p.Logger.Info("connected to gateway", zap.String("me", me.Tag()))
})

cmds, err := commands.New(p.Logger, state, p.Config, p.I18n)
if err != nil {
return nil, fmt.Errorf("error creating commands for discord bot. %w", err)
Expand Down Expand Up @@ -205,7 +200,7 @@ func (b *Bot) start(ctx context.Context) error {
var ready atomic.Bool

b.discord.AddHandler(func(r *gateway.ReadyEvent) {
b.logger.Info(fmt.Sprintf("ready with %d guilds", len(r.Guilds)))
b.logger.Info(fmt.Sprintf("connected to gateway, ready with %d guilds", len(r.Guilds)), zap.String("me", r.User.Tag()))
ready.Store(true)
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/discord/modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewBaseModule(logger *zap.Logger, db *sql.DB, discord *state.State, guild d

func (m *BaseModule) checkIfJobIgnored(job string) bool {
// Ignore certain jobs when syncing (e.g., "temporary" jobs), example:
// "ambulance" job Discord, and an user is currently in the ignored, e.g., "army", jobs.
// "ambulance" job Discord, and an user is currently in the ignored job, e.g., "army".
ignoredJobs := m.appCfg.Get().Discord.IgnoredJobs
if m.job != job && slices.Contains(ignoredJobs, job) {
return true
Expand Down
1 change: 1 addition & 0 deletions pkg/discord/types/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (p *Plan) Apply(ctx context.Context, dc *state.State) ([]discord.Embed, err
}

dc = dc.WithContext(ctx)

if err := p.applyRoles(dc); err != nil {
return logs, err
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/discord/types/calculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ func (s *State) calculateUserUpdates(ctx context.Context, member discord.Member,
if !slices.ContainsFunc(user.Roles.Sum, func(r *Role) bool {
return r.ID == role
}) {
if s.Roles[idx].Job != "" && s.Roles[idx].Job == user.Job {
continue
}

user.Roles.ToRemove = append(user.Roles.ToRemove, s.Roles[idx])
}
}
Expand Down

0 comments on commit b4bbe16

Please sign in to comment.