command help() fix, command symbol const, commandsymbol check

Former-commit-id: 4cd0a9b3e1be0c44ec45cf7c6b41ef41c0e55bc7
botanswer
AnisB 3 years ago
parent dc33b49fd8
commit e1fe6ce75a

@ -29,6 +29,7 @@ const (
//TestAPIEndpoint = "https://hhtestnet.com/api/v1"
//APIkey = "***REMOVED***"
HodlHodlCheckTimer = 5 * time.Second
commandSymbol = "/"
// Config
infoFormat = "====== "
@ -87,7 +88,7 @@ type config struct {
type Command interface {
Run(args []string) (string, error)
Help(args []string) (string, error)
Help(args []string) (string)
}
type DefaultCmd struct {
@ -103,17 +104,16 @@ func (*DefaultCmd) Run(args []string) (string, error) {
return "Type help to get available commands", nil
}
func (*DefaultCmd) Help(args []string) (string, error) {
return "Help of Default", nil
func (*DefaultCmd) Help(args []string) (string) {
return "Help of Default"
}
func (*HelpCmd) Run(args []string) (string, error) {
helpText := " this is help"
return helpText, nil
return "this is help", nil
}
func (*HelpCmd) Help(args []string) (string, error) {
return "this is help of help", nil
func (*HelpCmd) Help(args []string) (string) {
return "this is help of help"
}
func (*HelloCmd) Run(args []string) (string, error) {
@ -126,18 +126,15 @@ func (*HelloCmd) Run(args []string) (string, error) {
return "Hi, My name is Skynet 1.0. \n How can I help you ? ", nil
}
func (*HelloCmd) Help(args []string) (string, error) {
return "Help of Hello", nil
func (*HelloCmd) Help(args []string) (string) {
return "Help of Hello"
}
func handleCommand(command Command, args []string) string {
if len(args) != 0 && args[0] == "help" {
fmt.Println("Inside 1")
result, err := command.Help(args)
if err != nil {
return "error"
}
result := command.Help(args)
return result
} else if len(args) != 0 && args[0] != "help" {
return "Unkown command"
@ -246,9 +243,9 @@ func answerMessage(s xmpp.Sender, p stanza.Packet) {
_, _ = fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", msg.Body, msg.From)
//answersArray := []string{"Test", "Help", "Time"}
if len(msg.Body) > 0 {
if len(msg.Body) > 0 && msg.Body[0:1] == commandSymbol {
fmt.Println("keep the message", msg.Body)
receivedCmd := strings.Fields(msg.Body)[0]
receivedCmd := strings.Replace(strings.Fields(msg.Body)[0], "/", "", -1)
args := strings.Fields(msg.Body)[1:]
fmt.Println("command is : ", receivedCmd)
fmt.Println("args are : ", args)
@ -261,7 +258,7 @@ func answerMessage(s xmpp.Sender, p stanza.Packet) {
for regCommandName, regCommand := range Commands {
var result string
if receivedCmd == "/"+regCommandName {
if receivedCmd == regCommandName {
result = handleCommand(regCommand, args)
} /*else {
result = handleCommand(Commands["default"], args)

Loading…
Cancel
Save