-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainbot.go
43 lines (40 loc) · 1.41 KB
/
mainbot.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
package main
import (
. "TGAnimeBot/config"
"TGAnimeBot/modules"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"log"
)
func main() {
var bot modules.Specialbot
err := bot.InitBot(GetToken(), true, 60)
if err != nil {
log.Println(err)
return
}
log.Printf("Authorized on account %s", bot.Bot.Self.UserName)
for update := range bot.Updates {
if update.Message != nil {
switch update.Message.Text {
case "/start":
bot.Msg = tgbotapi.NewMessage(update.Message.From.ID, "Привет, здесь ты можешь получить как случайное аниме, так и произвести поиск аниме по названию!")
case "random":
anime, err := bot.RandomAnime()
if err != nil {
bot.Msg = tgbotapi.NewMessage(update.Message.From.ID, "Привет, здесь ты можешь получить как случайное аниме, так и произвести поиск аниме по названию!")
} else {
bot.Msg = anime[0].ConvectAnimeToMsg(update.Message.From.ID)
}
default:
anime, err := bot.FoundName(update.Message.Text)
if err != nil {
bot.Msg = tgbotapi.NewMessage(update.Message.From.ID, "Не удалось найти аниме по вашему запросу")
} else {
bot.Msg = anime[0].ConvectAnimeToMsg(update.Message.From.ID)
}
}
bot.Bot.Send(bot.Msg)
bot.Msg.Text = ""
}
}
}