Skip to content

Commit

Permalink
add permission checks to report actions
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Nov 1, 2023
1 parent a97fd0a commit 7c1bb97
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions dbot/commands/report_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ func reportActionHandler(b *dbot.Bot) handler.ComponentHandler {
value := e.StringSelectMenuInteractionData().Values[0]
switch value {
case "delete-message":
if e.Member().Permissions.Missing(discord.PermissionManageMessages) {
return e.CreateMessage(discord.MessageCreate{
Content: "You need the `Manage Messages` permission to use this action.",
Flags: discord.MessageFlagEphemeral,
})
}
if err = b.Client.Rest().DeleteMessage(snowflake.MustParse(report.ChannelID), snowflake.MustParse(report.MessageID), rest.WithReason(reason)); err != nil {
b.Logger.Errorf("Failed to delete message: %s", err)
content = "Failed to delete message, please reach out to a bot developer."
Expand Down Expand Up @@ -252,6 +258,12 @@ func reportActionHandler(b *dbot.Bot) handler.ComponentHandler {
}

case "timeout":
if e.Member().Permissions.Missing(discord.PermissionModerateMembers) {
return e.CreateMessage(discord.MessageCreate{
Content: "You need the `Moderate Members` permission to use this action.",
Flags: discord.MessageFlagEphemeral,
})
}
return e.CreateModal(discord.ModalCreate{
CustomID: fmt.Sprintf("handler:report-action-confirm:timeout:%s", report.UserID),
Title: "Timeout User",
Expand Down Expand Up @@ -281,6 +293,12 @@ func reportActionHandler(b *dbot.Bot) handler.ComponentHandler {
})

case "kick":
if e.Member().Permissions.Missing(discord.PermissionKickMembers) {
return e.CreateMessage(discord.MessageCreate{
Content: "You need the `Kick Members` permission to use this action.",
Flags: discord.MessageFlagEphemeral,
})
}
return e.CreateModal(discord.ModalCreate{
CustomID: fmt.Sprintf("handler:report-action-confirm:kick:%s", report.UserID),
Title: "Kick User",
Expand All @@ -299,6 +317,12 @@ func reportActionHandler(b *dbot.Bot) handler.ComponentHandler {
})

case "ban":
if e.Member().Permissions.Missing(discord.PermissionBanMembers) {
return e.CreateMessage(discord.MessageCreate{
Content: "You need the `Ban Members` permission to use this action.",
Flags: discord.MessageFlagEphemeral,
})
}
return e.CreateModal(discord.ModalCreate{
CustomID: fmt.Sprintf("handler:report-action-confirm:ban:%s", report.UserID),
Title: "Ban User",
Expand Down

0 comments on commit 7c1bb97

Please sign in to comment.