add /start and /ping commands

This commit is contained in:
Владимир Фёдоров 2022-04-03 18:06:45 +07:00
parent 80ba885152
commit 7ee6c27c39
3 changed files with 27 additions and 2 deletions

View File

@ -43,8 +43,8 @@ steps:
script: script:
- cd bots - cd bots
- pkill butler_tg_bot - pkill butler_tg_bot
- ./butler_tg_bot --token=$${TOKEN} & - echo $${TOKEN} > token.txt
- exit - sudo systemctl restart butler_tg_bot
trigger: trigger:
event: event:

3
.gitignore vendored
View File

@ -24,3 +24,6 @@ go.work
# Goland # Goland
.idea .idea
bin bin
# bot
token.txt

22
main.go
View File

@ -2,9 +2,11 @@ package main
import ( import (
"errors" "errors"
"fmt"
"git.user-penguin.space/vladimir/all_tg_bot/commands" "git.user-penguin.space/vladimir/all_tg_bot/commands"
tgbot "github.com/go-telegram-bot-api/telegram-bot-api" tgbot "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/umputun/go-flags" "github.com/umputun/go-flags"
"io/ioutil"
"log" "log"
"os" "os"
"strings" "strings"
@ -22,6 +24,15 @@ type Opts struct {
var opts Opts 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() { func main() {
run() run()
} }
@ -36,6 +47,15 @@ func run() {
os.Exit(2) 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) bot, err := tgbot.NewBotAPI(opts.Token)
if err != nil { if err != nil {
panic(err) panic(err)
@ -49,6 +69,8 @@ func run() {
panic(err) panic(err)
} }
log.Println("Run", opts.Name)
for update := range updates { for update := range updates {
if update.Message == nil { if update.Message == nil {