Add help command
This commit is contained in:
parent
a89629ab20
commit
9a292fba94
|
@ -1,8 +1,102 @@
|
||||||
package telegram
|
package telegram
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
const notEnoughArguments string = "Not enough arguments"
|
const notEnoughArguments string = "Not enough arguments"
|
||||||
const telegramNotInitialized string = "Telegram connection is not initialized yet"
|
const telegramNotInitialized string = "Telegram connection is not initialized yet"
|
||||||
|
|
||||||
|
var transportCommands = map[string]command{
|
||||||
|
"login": command{"phone", "sign in"},
|
||||||
|
//"logout": command{"", "sign out"},
|
||||||
|
"code": command{"", "check one-time code"},
|
||||||
|
"password": command{"", "check 2fa password"},
|
||||||
|
//"setusername": command{"", "update @username"},
|
||||||
|
//"setname": command{"first last", "update name"},
|
||||||
|
//"setbio": command{"", "update about"},
|
||||||
|
//"setpassword": command{"[old] [new]", "set or remove password"},
|
||||||
|
//"config": command{"[param] [value]", "view or update configuration options"},
|
||||||
|
}
|
||||||
|
|
||||||
|
var chatCommands = map[string]command{
|
||||||
|
//"d": command{"[n]", "delete your last message(s)"},
|
||||||
|
//"s": command{"regex replace", "edit your last message"},
|
||||||
|
//"add": command{"@username", "add @username to your chat list"},
|
||||||
|
//"join": command{"https://t.me/invite_link", "join to chat via invite link"},
|
||||||
|
//"group": command{"title", "create groupchat «title» with current user"},
|
||||||
|
//"supergroup": command{"title description", "create new supergroup «title» with «description»"},
|
||||||
|
//"channel": command{"title description", "create new channel «title» with «description»"},
|
||||||
|
//"secret": command{"", "create secretchat with current user"},
|
||||||
|
//"search": command{"string [limit]", "search <string> in current chat"},
|
||||||
|
//"history": command{"[limit]", "get last [limit] messages from current chat"},
|
||||||
|
//"block": command{"", "blacklist current user"},
|
||||||
|
//"unblock": command{"", "unblacklist current user"},
|
||||||
|
//"invite": command{"id or @username", "add user to current chat"},
|
||||||
|
//"kick": command{"id or @username", "remove user to current chat"},
|
||||||
|
//"ban": command{"id or @username [hours]", "restrict @username from current chat for [hours] or forever"},
|
||||||
|
//"leave": command{"", "leave current chat"},
|
||||||
|
//"close": command{"", "close current secret chat"},
|
||||||
|
//"delete": command{"", "delete current chat from chat list"},
|
||||||
|
//"members": command{"[query]", "search members [by optional query] in current chat (requires admin rights)"},
|
||||||
|
}
|
||||||
|
|
||||||
|
var transportConfigurationOptions = map[string]configurationOption{
|
||||||
|
//"timezone": configurationOption{"00:00", "adjust timezone for Telegram user statuses"}
|
||||||
|
}
|
||||||
|
|
||||||
|
type command struct {
|
||||||
|
arguments string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
type configurationOption command
|
||||||
|
|
||||||
|
type helpType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
helpTypeTransport helpType = iota
|
||||||
|
helpTypeChat
|
||||||
|
)
|
||||||
|
|
||||||
|
func helpString(ht helpType) string {
|
||||||
|
var str strings.Builder
|
||||||
|
var commandMap map[string]command
|
||||||
|
|
||||||
|
switch ht {
|
||||||
|
case helpTypeTransport:
|
||||||
|
commandMap = transportCommands
|
||||||
|
case helpTypeChat:
|
||||||
|
commandMap = chatCommands
|
||||||
|
}
|
||||||
|
|
||||||
|
str.WriteString("Available commands:\n")
|
||||||
|
for name, command := range commandMap {
|
||||||
|
str.WriteString("/")
|
||||||
|
str.WriteString(name)
|
||||||
|
if command.arguments != "" {
|
||||||
|
str.WriteString(" ")
|
||||||
|
str.WriteString(command.arguments)
|
||||||
|
}
|
||||||
|
str.WriteString(" — ")
|
||||||
|
str.WriteString(command.description)
|
||||||
|
str.WriteString("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ht == helpTypeTransport {
|
||||||
|
str.WriteString("Configuration options\n")
|
||||||
|
for name, option := range transportConfigurationOptions {
|
||||||
|
str.WriteString(name)
|
||||||
|
str.WriteString(" ")
|
||||||
|
str.WriteString(option.arguments)
|
||||||
|
str.WriteString(" — ")
|
||||||
|
str.WriteString(option.description)
|
||||||
|
str.WriteString("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return str.String()
|
||||||
|
}
|
||||||
|
|
||||||
// ProcessTransportCommand executes commands sent directly to the component
|
// ProcessTransportCommand executes commands sent directly to the component
|
||||||
func (c *Client) ProcessTransportCommand(cmd string, args []string) string {
|
func (c *Client) ProcessTransportCommand(cmd string, args []string) string {
|
||||||
switch cmd {
|
switch cmd {
|
||||||
|
@ -27,6 +121,8 @@ func (c *Client) ProcessTransportCommand(cmd string, args []string) string {
|
||||||
case "password":
|
case "password":
|
||||||
c.authorizer.Password <- args[0]
|
c.authorizer.Password <- args[0]
|
||||||
}
|
}
|
||||||
|
case "help":
|
||||||
|
return helpString(helpTypeTransport)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
Loading…
Reference in a new issue