1
0
Fork 0

Create a bot that read messages

main
Daniele Tricoli 7 months ago
parent 3771e5f5bd
commit 629370c1c5
  1. 12
      .drone.yml
  2. 14
      go.mod
  3. 13
      go.sum
  4. 44
      main.go
  5. 18
      main_test.go

@ -0,0 +1,12 @@
---
kind: pipeline
type: docker
name: default
steps:
- name: test
image: golang:1.17
commands:
- go build
- go vet
- go test -v

@ -0,0 +1,14 @@
module noa.mornie.org/eriol/tg2rss
go 1.17
require (
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/stretchr/testify v1.7.0
)
require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)

@ -0,0 +1,13 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

@ -0,0 +1,44 @@
package main
import (
"log"
"os"
"strconv"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
const (
DEBUG = "DEBUG"
TELEGRAM_BOT_TOKEN = "TELEGRAM_BOT_TOKEN"
)
func main() {
bot, err := tgbotapi.NewBotAPI(os.Getenv(TELEGRAM_BOT_TOKEN))
if err != nil {
log.Panic(err)
}
bot.Debug = parseBoolOrFalse(os.Getenv(DEBUG))
u := tgbotapi.NewUpdate(0)
u.Timeout = 30
updates := bot.GetUpdatesChan(u)
for update := range updates {
if update.Message != nil {
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
}
}
}
func parseBoolOrFalse(s string) bool {
r, err := strconv.ParseBool(s)
if err != nil {
return false
}
return r
}

@ -0,0 +1,18 @@
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseBoolOrFalse(t *testing.T) {
assert.Equal(t, parseBoolOrFalse("True"), true)
assert.Equal(t, parseBoolOrFalse("TRUE"), true)
assert.Equal(t, parseBoolOrFalse("true"), true)
assert.Equal(t, parseBoolOrFalse(""), false)
assert.Equal(t, parseBoolOrFalse("False"), false)
assert.Equal(t, parseBoolOrFalse("FALSE"), false)
assert.Equal(t, parseBoolOrFalse("false"), false)
}
Loading…
Cancel
Save