From dc33b49fd8eaaaf760ac3aee65a87ed16eddd3f3 Mon Sep 17 00:00:00 2001 From: AnisB Date: Mon, 16 Aug 2021 13:42:14 +0100 Subject: [PATCH] constant for timer Former-commit-id: 14406e99e5ae4b118aaec55be6375d83aa47f73f --- hodlhodl-bot.REMOVED.git-id | 1 - main.go | 19 +++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) delete mode 100644 hodlhodl-bot.REMOVED.git-id diff --git a/hodlhodl-bot.REMOVED.git-id b/hodlhodl-bot.REMOVED.git-id deleted file mode 100644 index b4ab2f2..0000000 --- a/hodlhodl-bot.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -ccfbe1adb71858c6f07073d72fd686b90ef95dbb \ No newline at end of file diff --git a/main.go b/main.go index 673a883..bdbb2bc 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,7 @@ const ( // APIEndpoint = "https://hodlhodl.com/api/v1" //TestAPIEndpoint = "https://hhtestnet.com/api/v1" //APIkey = "***REMOVED***" - JobSchedulerInterval = 60 * time.Second + HodlHodlCheckTimer = 5 * time.Second // Config infoFormat = "====== " @@ -97,7 +97,6 @@ type HelloCmd struct { } type HelpCmd struct { - } func (*DefaultCmd) Run(args []string) (string, error) { @@ -117,7 +116,6 @@ func (*HelpCmd) Help(args []string) (string, error) { return "this is help of help", nil } - func (*HelloCmd) Run(args []string) (string, error) { /*for _, result := range args { if result == "help" { @@ -133,13 +131,13 @@ func (*HelloCmd) Help(args []string) (string, error) { } 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" - } + } return result } else if len(args) != 0 && args[0] != "help" { return "Unkown command" @@ -223,15 +221,16 @@ func startClient(config *config) { fmt.Println("Client is running") } - timer := time.NewTicker(5 * time.Second) + timer := time.NewTicker(HodlHodlCheckTimer) notifications := make(chan string, 100) go hodlNotifications(client, config, notifications) + fmt.Println("checking notifs every ", HodlHodlCheckTimer) for { select { case <-timer.C: - fmt.Println("checking notifs...") + //fmt.Println("checking notifs...") notifications <- gethdlNotif(config.Hodlhodl[APIKey], config.Hodlhodl[APIEndPoint]) } } @@ -245,7 +244,7 @@ func answerMessage(s xmpp.Sender, p stanza.Packet) { return } _, _ = fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", msg.Body, msg.From) - + //answersArray := []string{"Test", "Help", "Time"} if len(msg.Body) > 0 { fmt.Println("keep the message", msg.Body) @@ -262,7 +261,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) @@ -272,7 +271,7 @@ func answerMessage(s xmpp.Sender, p stanza.Packet) { s.Send(reply) } } - + //switch { //case strings.Contains(strings.ToLower(msg.Body), "test"): //answer := "succesful test"