/
main.go
84 lines (65 loc) · 1.87 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"time"
"github.com/denisqsound/bot_god_say_go/helpers"
"github.com/denisqsound/bot_god_say_go/internal"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/joho/godotenv"
)
func init() {
if err := godotenv.Load(); err != nil {
log.Print("No .env file found")
}
}
// 401 картинка скачана 10 июля 2021 года
// 516 уникальных картинок до 16 февраля 2022 года
func main() {
botToken := internal.GetToken()
timeSleep := internal.GetTime()
internal.CheckFolderImages()
bot, err := tgbotapi.NewBotAPI(botToken)
if err != nil {
log.Panic(err)
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 10
updates, err := bot.GetUpdatesChan(u)
if err != nil {
log.Fatalf("Can't get update chan %v", err)
}
for update := range updates {
log.Printf("BOT UPDATE : %v", update.Message)
if update.Message == nil { // ignore any non-Message Updates
continue
}
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
if update.Message.Text == "/start" {
for {
pathImages, _ := os.LookupEnv("PICTURE_PATH")
fileName := fmt.Sprintf("%v/bible-%d.JPG", pathImages, helpers.Random(1, 516))
photoBytes, err := ioutil.ReadFile(fileName)
if err != nil {
log.Fatalln("Unable read file: ", err)
}
photoFileBytes := tgbotapi.FileBytes{
Name: "picture",
Bytes: photoBytes,
}
//num := 1
//text := fmt.Sprintf("Это %v", num)
_, _ = bot.Send(tgbotapi.NewPhotoUpload(update.Message.Chat.ID, photoFileBytes))
//_, err = bot.Send(tgbotapi.NewMessage(update.Message.Chat.ID, text))
if err != nil {
log.Fatalln("Unable send photo: ", err)
}
time.Sleep(time.Duration(timeSleep) * time.Second)
}
}
}
}