Rename /plugin to /pluginadm and make /prun and /phelp subcommands of /plugin instead
This commit is contained in:
parent
5d327f3fd2
commit
4f533eac6b
@ -11,8 +11,8 @@ import (
|
||||
"go.elara.ws/owobot/internal/util"
|
||||
)
|
||||
|
||||
// pluginCmd handles the `/plugin` command and routes it to the correct subcommand.
|
||||
func pluginCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||
// pluginadmCmd handles the `/plugin` command and routes it to the correct subcommand.
|
||||
func pluginadmCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||
data := i.ApplicationCommandData()
|
||||
switch name := data.Options[0].Name; name {
|
||||
case "list":
|
||||
@ -22,7 +22,7 @@ func pluginCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||
case "disable":
|
||||
return disableCmd(s, i)
|
||||
default:
|
||||
return fmt.Errorf("unknown plugin subcommand: %s", name)
|
||||
return fmt.Errorf("unknown pluginadm subcommand: %s", name)
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,10 +107,22 @@ func disableCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||
return util.RespondEphemeral(s, i.Interaction, fmt.Sprintf("Successfully disabled the %q plugin", pluginName))
|
||||
}
|
||||
|
||||
// phelpCmd handles the `/phelp` command.
|
||||
func phelpCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||
func pluginCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||
data := i.ApplicationCommandData()
|
||||
cmdStr := data.Options[0].StringValue()
|
||||
switch name := data.Options[0].Name; name {
|
||||
case "run":
|
||||
return pluginRunCmd(s, i)
|
||||
case "help":
|
||||
return pluginHelpCmd(s, i)
|
||||
default:
|
||||
return fmt.Errorf("unknown plugin subcommand: %s", name)
|
||||
}
|
||||
}
|
||||
|
||||
// pluginHelpCmd handles the `/phelp` command.
|
||||
func pluginHelpCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||
data := i.ApplicationCommandData()
|
||||
cmdStr := data.Options[0].Options[0].StringValue()
|
||||
|
||||
args, err := shellquote.Split(cmdStr)
|
||||
if err != nil {
|
||||
@ -176,10 +188,10 @@ func phelpCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||
return fmt.Errorf("command not found: %q", args[0])
|
||||
}
|
||||
|
||||
// prunCmd handles the `/prunCmd` command.
|
||||
func prunCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||
// pluginRunCmd handles the `/pluginRunCmd` command.
|
||||
func pluginRunCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||
data := i.ApplicationCommandData()
|
||||
cmdStr := data.Options[0].StringValue()
|
||||
cmdStr := data.Options[0].Options[0].StringValue()
|
||||
|
||||
args, err := shellquote.Split(cmdStr)
|
||||
if err != nil {
|
||||
|
@ -70,11 +70,11 @@ func handleAutocomplete(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
}
|
||||
|
||||
data := i.ApplicationCommandData()
|
||||
if data.Name != "prun" && data.Name != "phelp" {
|
||||
if data.Name != "plugin" {
|
||||
return
|
||||
}
|
||||
|
||||
cmdStr := data.Options[0].StringValue()
|
||||
cmdStr := data.Options[0].Options[0].StringValue()
|
||||
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionApplicationCommandAutocompleteResult,
|
||||
|
@ -22,36 +22,43 @@ func Init(s *discordgo.Session) error {
|
||||
return err
|
||||
}
|
||||
|
||||
commands.Register(s, prunCmd, &discordgo.ApplicationCommand{
|
||||
Name: "prun",
|
||||
Description: "Run a plugin command",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Name: "cmd",
|
||||
Description: "The plugin command to run",
|
||||
Required: true,
|
||||
Autocomplete: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
commands.Register(s, phelpCmd, &discordgo.ApplicationCommand{
|
||||
Name: "phelp",
|
||||
Description: "Display help for a plugin command",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Name: "cmd",
|
||||
Description: "The plugin command to display help for",
|
||||
Required: true,
|
||||
Autocomplete: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
commands.Register(s, pluginCmd, &discordgo.ApplicationCommand{
|
||||
Name: "plugin",
|
||||
Name: "plugin",
|
||||
Description: "Interact with the plugins on this server",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionSubCommand,
|
||||
Name: "run",
|
||||
Description: "Run a plugin command",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Name: "cmd",
|
||||
Description: "The plugin command to run",
|
||||
Required: true,
|
||||
Autocomplete: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionSubCommand,
|
||||
Name: "help",
|
||||
Description: "See how to use a plugin command",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Name: "cmd",
|
||||
Description: "The plugin command to help with",
|
||||
Required: true,
|
||||
Autocomplete: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
commands.Register(s, pluginadmCmd, &discordgo.ApplicationCommand{
|
||||
Name: "pluginadm",
|
||||
Description: "Manage dynamic plugins for your server",
|
||||
DefaultMemberPermissions: util.Pointer[int64](discordgo.PermissionManageServer),
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
|
Loading…
Reference in New Issue
Block a user