Skip to content

Commit

Permalink
feat: deprecation warning on /gentei manage (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-ignacio committed Feb 11, 2024
1 parent af83354 commit 905e761
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions gentei/bot/commands.go
Expand Up @@ -543,6 +543,7 @@ func (b *DiscordBot) handleManage(ctx context.Context, i *discordgo.InteractionC
b.replyNoDM(i)
return
}
ctx = deprecatedContext(ctx)
b.deferredReply(ctx, i, "manage", true,
// the calling user has to be an admin of some sort to run this command
func(logger zerolog.Logger) (*discordgo.WebhookEdit, error) {
Expand Down Expand Up @@ -570,6 +571,23 @@ func (b *DiscordBot) handleManage(ctx context.Context, i *discordgo.InteractionC
}

// helpers
type ctxKey int

// Context key whose value should specifically not be nil to be set
var manageCommandDeprecated ctxKey

func deprecatedContext(ctx context.Context) context.Context {
return context.WithValue(ctx, manageCommandDeprecated, true)
}

func isDeprecatedContext(ctx context.Context) bool {
value, _ := ctx.Value(manageCommandDeprecated).(bool)
return value
}

const (
manageDeprecatedPrefix = "⚠️ `/gentei manage` will be removed soon. Please use the replacement commands `/gentei-audit` and `/gentei-map`, which are admin-only by default! ⚠️"
)

// deferredReply can only be called once, but it'll process each responseFunc in serial. If it gets a WebHookEdit payload, it sends that and stops processing later responseFuncs.
func (b *DiscordBot) deferredReply(ctx context.Context, i *discordgo.InteractionCreate, commandName string, ephemeral bool, responseFuncs ...slashResponseFunc) {
Expand Down Expand Up @@ -614,6 +632,9 @@ func (b *DiscordBot) deferredReply(ctx context.Context, i *discordgo.Interaction
if response == nil {
continue
}
if isDeprecatedContext(ctx) && response.Content != nil {
response.Content = ptr(fmt.Sprintf("%s\n\n%s", manageDeprecatedPrefix, *response.Content))
}
_, err = b.session.InteractionResponseEdit(i.Interaction, response)
if err != nil {
logger.Err(err).Msg("error generating response")
Expand Down

0 comments on commit 905e761

Please sign in to comment.