2022-12-04 17:30:08 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/NicoNex/echotron/v3"
|
2022-12-06 00:57:09 +03:00
|
|
|
"nefrace.ru/doomer/config"
|
2022-12-04 17:30:08 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type bot struct {
|
|
|
|
chatID int64
|
|
|
|
doomer *Doomer
|
|
|
|
logChatID int64
|
|
|
|
echotron.API
|
|
|
|
}
|
|
|
|
|
2022-12-06 00:57:09 +03:00
|
|
|
func createBot(cfg config.TelegramConfig, doomer *Doomer) echotron.NewBotFn {
|
2022-12-04 17:30:08 +03:00
|
|
|
return func(chatID int64) echotron.Bot {
|
|
|
|
return &bot{
|
|
|
|
chatID: chatID,
|
|
|
|
doomer: doomer,
|
2022-12-06 00:57:09 +03:00
|
|
|
logChatID: cfg.LogChatID,
|
|
|
|
API: echotron.NewAPI(cfg.Token),
|
2022-12-04 17:30:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bot) Update(update *echotron.Update) {
|
|
|
|
log.Println("We got update")
|
|
|
|
if update.InlineQuery != nil {
|
|
|
|
b.inlineHandler(update)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if update.Message != nil {
|
|
|
|
if update.Message.Text == "/help" {
|
|
|
|
b.showHelp(update)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(update.Message.Text, "/start") {
|
|
|
|
b.showHelp(update)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(update.Message.Text, "/gen") {
|
|
|
|
b.genHandler(update)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-06 00:57:09 +03:00
|
|
|
func NewDispatcher(doomer *Doomer) *echotron.Dispatcher {
|
|
|
|
cfg := config.Conf()
|
|
|
|
dp := echotron.NewDispatcher(cfg.Telegram.Token, createBot(cfg.Telegram, doomer))
|
2022-12-04 17:30:08 +03:00
|
|
|
return dp
|
|
|
|
}
|