aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2024-02-03 12:24:22 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2024-02-03 12:24:22 +0300
commit21dc5fa6c6c843fcf263b6483d21bc4b284aad1c (patch)
tree740a591ce6e8ba15f3dccd50f8c85d245ed477c6 /telegram
parente3a51919051a5597b49e7b8825f22ddfb24ddc58 (diff)
Form support for transport Ad-Hoc commands with arguments
Diffstat (limited to 'telegram')
-rw-r--r--telegram/commands.go21
1 files changed, 14 insertions, 7 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
index 47438e0..4dafdf5 100644
--- a/telegram/commands.go
+++ b/telegram/commands.go
@@ -107,9 +107,9 @@ var transportConfigurationOptions = map[string]configurationOption{
}
type command struct {
- requiredArgs int
- arguments []string
- description string
+ RequiredArgs int
+ Arguments []string
+ Description string
}
type configurationOption struct {
arguments string
@@ -138,14 +138,21 @@ func GetCommands(typ CommandType) map[string]command {
return commandMap
}
+// GetCommand obtains one command
+func GetCommand(typ CommandType, cmd string) (command, bool) {
+ commands := GetCommands(typ)
+ command, ok := commands[cmd]
+ return command, ok
+}
+
// CommandToHelpString builds a text description of a command
func CommandToHelpString(name string, cmd command) string {
var str strings.Builder
str.WriteString("/")
str.WriteString(name)
- for i, arg := range cmd.arguments {
- optional := i >= cmd.requiredArgs
+ for i, arg := range cmd.Arguments {
+ optional := i >= cmd.RequiredArgs
str.WriteString(" ")
if optional {
str.WriteString("[")
@@ -156,7 +163,7 @@ func CommandToHelpString(name string, cmd command) string {
}
}
str.WriteString(" — ")
- str.WriteString(cmd.description)
+ str.WriteString(cmd.Description)
return str.String()
}
@@ -267,7 +274,7 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) string
if !ok {
return "Unknown command"
}
- if len(args) < command.requiredArgs {
+ if len(args) < command.RequiredArgs {
return notEnoughArguments
}