From bf5b86e9b87b77de6905870cc61e0d988e18879b Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Mon, 13 Jan 2025 21:39:54 -0800 Subject: fix assistant --- assistant/assistant.go | 22 ++++++++++++++++++++++ main.go | 2 +- ntfy/assistant/assistant.go | 23 ----------------------- 3 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 assistant/assistant.go delete mode 100644 ntfy/assistant/assistant.go diff --git a/assistant/assistant.go b/assistant/assistant.go new file mode 100644 index 0000000..00db82c --- /dev/null +++ b/assistant/assistant.go @@ -0,0 +1,22 @@ +package assistant + +import ( + "fmt" + "net/http" + "os" +) + +func UnlockDoor(webhook string) error { + res, err := http.Get(webhook) + if err != nil || res.StatusCode/100 != 2 { + return fmt.Errorf("got err sending message send %v %s", res, err) + } + return nil +} + +func Do(command string) error { + if command == "unlock" { + return UnlockDoor(os.Getenv("UNLOCK_DOOR_WEBHOOK")) + } + return fmt.Errorf("unknown command %s", command) +} diff --git a/main.go b/main.go index b7aea35..08d7e11 100644 --- a/main.go +++ b/main.go @@ -7,9 +7,9 @@ import ( "git.simponic.xyz/simponic/phoneassistant/api" "git.simponic.xyz/simponic/phoneassistant/args" + "git.simponic.xyz/simponic/phoneassistant/assistant" "git.simponic.xyz/simponic/phoneassistant/database" "git.simponic.xyz/simponic/phoneassistant/ntfy" - "git.simponic.xyz/simponic/phoneassistant/ntfy/assistant" "git.simponic.xyz/simponic/phoneassistant/scheduler" "github.com/joho/godotenv" ) diff --git a/ntfy/assistant/assistant.go b/ntfy/assistant/assistant.go deleted file mode 100644 index 3f15647..0000000 --- a/ntfy/assistant/assistant.go +++ /dev/null @@ -1,23 +0,0 @@ -package assistant - -import ( - "fmt" - "net/http" - "os" -) - -func UnlockDoor(webhook string) error { - req, _ := http.NewRequest("GET", webhook) - res, err := http.DefaultClient.Do(req) - if err != nil || res.StatusCode/100 != 2 { - return fmt.Errorf("got err sending message send req %s %v %s", message, res, err) - } - return nil -} - -func Do(command string) error { - if command == "unlock" { - return UnlockDoor(os.Getenv("UNLOCK_DOOR_WEBHOOK")) - } - return fmt.Errorf("unknown command %s", command) -} -- cgit v1.2.3-70-g09d2