Skip to content

Commit

Permalink
Fix approve command timing out (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
myrkvi authored Aug 17, 2024
2 parents d6fdb64 + b403a44 commit d200d1b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions commands/gatekeep.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/disgoorg/disgo/rest"
"github.com/disgoorg/json"
"github.com/disgoorg/snowflake/v2"

"github.com/myrkvi/heimdallr/model"
"github.com/myrkvi/heimdallr/utils"
)
Expand Down Expand Up @@ -60,19 +61,25 @@ func ApproveSlashCommandHandler(e *handler.CommandEvent) error {
}

func approvedInnerHandler(e *handler.CommandEvent, guild discord.Guild, member discord.ResolvedMember) error {
_ = e.DeferCreateMessage(true)
guildSettings, err := model.GetGuildSettings(guild.ID)
if err != nil {
slog.Error("Failed to get guild settings.",
"guild_id", guild.ID,
"err", err)
_, err = e.CreateFollowupMessage(discord.NewMessageCreateBuilder().
SetContent("Failed to get guild information.").
SetEphemeral(true).
Build())
return err
}

if !guildSettings.GatekeepEnabled {
return e.CreateMessage(discord.NewMessageCreateBuilder().
_, err := e.CreateFollowupMessage(discord.NewMessageCreateBuilder().
SetContentf("Gatekeep is not enabled in this server.").
SetEphemeral(true).
Build())
return err
}

hasApprovedRole := false
Expand All @@ -86,10 +93,11 @@ func approvedInnerHandler(e *handler.CommandEvent, guild discord.Guild, member d
}

if hasApprovedRole && (!hasPendingRole || !guildSettings.GatekeepAddPendingRoleOnJoin) {
return e.CreateMessage(discord.NewMessageCreateBuilder().
_, err := e.CreateFollowupMessage(discord.NewMessageCreateBuilder().
SetContentf("User %s is already approved.", member.Mention()).
SetEphemeral(true).
Build())
return err

}

Expand Down Expand Up @@ -122,10 +130,11 @@ func approvedInnerHandler(e *handler.CommandEvent, guild discord.Guild, member d

if guildSettings.GatekeepApprovedMessage == "" {
slog.Info("No approved message set; not sending message.")
return e.CreateMessage(discord.NewMessageCreateBuilder().
_, err := e.CreateFollowupMessage(discord.NewMessageCreateBuilder().
SetContentf("No approved message set; not sending message. Roles have been set.").
SetEphemeral(true).
Build())
return err
}

channel := guildSettings.JoinLeaveChannel
Expand All @@ -151,13 +160,15 @@ func approvedInnerHandler(e *handler.CommandEvent, guild discord.Guild, member d
Build(),
)
if err != nil {
return e.CreateMessage(discord.NewMessageCreateBuilder().
_, err := e.CreateFollowupMessage(discord.NewMessageCreateBuilder().
SetEphemeral(true).
SetContent("Failed to send message to approved user.").
Build())
return err
}
return e.CreateMessage(discord.NewMessageCreateBuilder().
_, err = e.CreateFollowupMessage(discord.NewMessageCreateBuilder().
SetEphemeral(true).
SetContent("User has been approved!").
Build())
return err
}

0 comments on commit d200d1b

Please sign in to comment.