From 7ee6c27c399ccf3799f4fb2908c72c84d682554a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=20=D0=A4?= =?UTF-8?q?=D0=B5=D0=B4=D0=BE=D1=80=D0=BE=D0=B2?= Date: Sun, 3 Apr 2022 18:06:45 +0700 Subject: [PATCH] add /start and /ping commands --- .drone.yml | 4 ++-- .gitignore | 3 +++ main.go | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 9a3aa0a..b58eee1 100644 --- a/.drone.yml +++ b/.drone.yml @@ -43,8 +43,8 @@ steps: script: - cd bots - pkill butler_tg_bot - - ./butler_tg_bot --token=$${TOKEN} & - - exit + - echo $${TOKEN} > token.txt + - sudo systemctl restart butler_tg_bot trigger: event: diff --git a/.gitignore b/.gitignore index c16bb89..476ae33 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ go.work # Goland .idea bin + +# bot +token.txt diff --git a/main.go b/main.go index d13cba6..a609761 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,11 @@ package main import ( "errors" + "fmt" "git.user-penguin.space/vladimir/all_tg_bot/commands" tgbot "github.com/go-telegram-bot-api/telegram-bot-api" "github.com/umputun/go-flags" + "io/ioutil" "log" "os" "strings" @@ -22,6 +24,15 @@ type Opts struct { var opts Opts +func readToken() (string, error) { + b, err := ioutil.ReadFile("token.txt") + if err != nil { + return "", err + } + str := string(b) + return str, nil +} + func main() { run() } @@ -36,6 +47,15 @@ func run() { os.Exit(2) } + if opts.Token == "" { + token, err := readToken() + if err != nil { + panic(err) + } + opts.Token = token + } + fmt.Println(opts.Token) + bot, err := tgbot.NewBotAPI(opts.Token) if err != nil { panic(err) @@ -49,6 +69,8 @@ func run() { panic(err) } + log.Println("Run", opts.Name) + for update := range updates { if update.Message == nil {