Skip to content

Commit

Permalink
add new gentei-* command structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-ignacio committed Feb 11, 2024
1 parent a033dea commit be344a6
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions gentei/bot/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (

const (
commandName = "gentei"
adminCommandPrefix = "gentei-"
adminAuditCommandName = adminCommandPrefix + "audit"
adminMapCommandName = adminCommandPrefix + "map"
eaCommandDescription = "Gentei membership management (early access)"
prodCommandDescription = "Gentei membership management"
)
Expand Down Expand Up @@ -56,6 +59,7 @@ var (
},
},
}
// /gentei
globalCommand = &discordgo.ApplicationCommand{
Name: commandName,
Description: prodCommandDescription,
Expand Down Expand Up @@ -134,6 +138,70 @@ var (
},
},
}
// /gentei-admin
adminCommands = []*discordgo.ApplicationCommand{
{
Name: adminAuditCommandName,
Description: "Admin: manage memberships and server settings",
DefaultMemberPermissions: ptr[int64](0),
DMPermission: ptr(false),
Options: []*discordgo.ApplicationCommandOption{
{
Name: "set",
Type: discordgo.ApplicationCommandOptionSubCommand,
Description: "Set/change role management audit log settings.",
Options: []*discordgo.ApplicationCommandOption{
{
Name: "channel",
Description: "The Discord channel that will receive audit logs.",
Type: discordgo.ApplicationCommandOptionChannel,
ChannelTypes: []discordgo.ChannelType{discordgo.ChannelTypeGuildText},
Required: true,
},
},
},
{
Name: "unset",
Description: "Turns off role management audit logs.",
Type: discordgo.ApplicationCommandOptionSubCommand,
},
},
},
{
Name: adminMapCommandName,
Description: "Admin: set/unset role mapping of a channel -> Discord role.",
DefaultMemberPermissions: ptr[int64](0),
DMPermission: ptr(false),
Options: []*discordgo.ApplicationCommandOption{
{
Name: "set",
Type: discordgo.ApplicationCommandOptionSubCommand,
Description: "Set/change mapping between channel -> Discord role",
Options: _adminMapOptions,
},
{
Name: "unset",
Type: discordgo.ApplicationCommandOptionSubCommand,
Description: "Remove mapping between channel -> Discord role",
Options: _adminMapOptions,
},
},
},
}
_adminMapOptions = []*discordgo.ApplicationCommandOption{
{
Name: "youtube-channel-id",
Description: "The YouTube channel ID whose memberships should be monitored. (e.g. UCAL_ZudIZXhCDrniD4ZQobQ)",
Type: discordgo.ApplicationCommandOptionString,
Required: true,
},
{
Name: "role",
Description: "The Discord role for members of this YouTube channel",
Type: discordgo.ApplicationCommandOptionRole,
Required: true,
},
}
)

func (b *DiscordBot) PushCommands(global, earlyAccess bool) error {
Expand Down Expand Up @@ -600,3 +668,20 @@ func ensureRegisteredUserHasGuildEdge(ctx context.Context, db *ent.Client, guild
func ptr[T any](o T) *T {
return &o
}

// just in case you screw it up...
func adminOnlyCommand(cmd *discordgo.ApplicationCommand) *discordgo.ApplicationCommand {
if cmd.DefaultMemberPermissions == nil || *cmd.DefaultMemberPermissions != 0 {
cmd.DefaultMemberPermissions = ptr[int64](0)
}
if cmd.DMPermission == nil || *cmd.DMPermission {
cmd.DMPermission = ptr(false)
}
return cmd
}

func init() {
for i := range adminCommands {
adminCommands[i] = adminOnlyCommand(adminCommands[i])
}
}

0 comments on commit be344a6

Please sign in to comment.