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"
|
"go.elara.ws/owobot/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// pluginCmd handles the `/plugin` command and routes it to the correct subcommand.
|
// pluginadmCmd handles the `/plugin` command and routes it to the correct subcommand.
|
||||||
func pluginCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
func pluginadmCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||||
data := i.ApplicationCommandData()
|
data := i.ApplicationCommandData()
|
||||||
switch name := data.Options[0].Name; name {
|
switch name := data.Options[0].Name; name {
|
||||||
case "list":
|
case "list":
|
||||||
@ -22,7 +22,7 @@ func pluginCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
|||||||
case "disable":
|
case "disable":
|
||||||
return disableCmd(s, i)
|
return disableCmd(s, i)
|
||||||
default:
|
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))
|
return util.RespondEphemeral(s, i.Interaction, fmt.Sprintf("Successfully disabled the %q plugin", pluginName))
|
||||||
}
|
}
|
||||||
|
|
||||||
// phelpCmd handles the `/phelp` command.
|
func pluginCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||||
func phelpCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
|
||||||
data := i.ApplicationCommandData()
|
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)
|
args, err := shellquote.Split(cmdStr)
|
||||||
if err != nil {
|
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])
|
return fmt.Errorf("command not found: %q", args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// prunCmd handles the `/prunCmd` command.
|
// pluginRunCmd handles the `/pluginRunCmd` command.
|
||||||
func prunCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
func pluginRunCmd(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||||
data := i.ApplicationCommandData()
|
data := i.ApplicationCommandData()
|
||||||
cmdStr := data.Options[0].StringValue()
|
cmdStr := data.Options[0].Options[0].StringValue()
|
||||||
|
|
||||||
args, err := shellquote.Split(cmdStr)
|
args, err := shellquote.Split(cmdStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -70,11 +70,11 @@ func handleAutocomplete(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := i.ApplicationCommandData()
|
data := i.ApplicationCommandData()
|
||||||
if data.Name != "prun" && data.Name != "phelp" {
|
if data.Name != "plugin" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdStr := data.Options[0].StringValue()
|
cmdStr := data.Options[0].Options[0].StringValue()
|
||||||
|
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
Type: discordgo.InteractionApplicationCommandAutocompleteResult,
|
Type: discordgo.InteractionApplicationCommandAutocompleteResult,
|
||||||
|
@ -22,36 +22,43 @@ func Init(s *discordgo.Session) error {
|
|||||||
return err
|
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{
|
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",
|
Description: "Manage dynamic plugins for your server",
|
||||||
DefaultMemberPermissions: util.Pointer[int64](discordgo.PermissionManageServer),
|
DefaultMemberPermissions: util.Pointer[int64](discordgo.PermissionManageServer),
|
||||||
Options: []*discordgo.ApplicationCommandOption{
|
Options: []*discordgo.ApplicationCommandOption{
|
||||||
|
Loading…
Reference in New Issue
Block a user