56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"strings"
|
|
|
|
"github.com/NicoNex/echotron/v3"
|
|
)
|
|
|
|
type bot struct {
|
|
chatID int64
|
|
doomer *Doomer
|
|
db *Db
|
|
logChatID int64
|
|
echotron.API
|
|
}
|
|
|
|
func createBot(token string, doomer *Doomer, db *Db) echotron.NewBotFn {
|
|
return func(chatID int64) echotron.Bot {
|
|
return &bot{
|
|
chatID: chatID,
|
|
doomer: doomer,
|
|
db: db,
|
|
logChatID: -1001688182314,
|
|
API: echotron.NewAPI(token),
|
|
}
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|
|
|
|
func NewDispatcher(token string, doomer *Doomer, db *Db) *echotron.Dispatcher {
|
|
dp := echotron.NewDispatcher(token, createBot(token, doomer, db))
|
|
return dp
|
|
}
|