-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (59 loc) · 1.31 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
package main
import (
"log"
"os"
"time"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/joho/godotenv"
)
func getMeme() Responce {
var api MemeApi
api = Api{BaseUrl: "https://meme-api.herokuapp.com"}
meme := api.GetMeme()
return meme
}
func sendMeme(bot *tgbotapi.BotAPI, channel string, workTime WorkTime) {
if workTime.IsWorkTime == workTime.CheckTimePeriod(time.Now()) {
return
}
meme := getMeme()
message := tgbotapi.NewPhotoToChannel(channel, tgbotapi.FileURL(meme.URL))
bot.Send(message)
}
func init() {
if err := godotenv.Load(); err != nil {
log.Print("No .env file found")
}
}
func main() {
botToken, _ := os.LookupEnv("BOT_TOKEN")
channelId, _ := os.LookupEnv("CHANNEL")
isLoopBot, _ := os.LookupEnv("IS_LOOP_BOT")
start, _ := time.Parse("15:00", "22:00")
end, _ := time.Parse("15:00", "09:00")
workTime := WorkTime{false, start, end}
time.Parse("15:00", "20")
bot, err := configBot(botToken)
if err != nil {
log.Panicln(err)
}
go startBot(bot)
sendMeme(bot, channelId, workTime)
if isLoopBot == "true" {
ticker := time.NewTicker(60 * time.Minute)
quit := make(chan struct{})
go func() {
for {
select {
case <-ticker.C:
sendMeme(bot, channelId, workTime)
case <-quit:
ticker.Stop()
return
}
}
}()
for {
}
}
}