KickerBot/kicker/handlers.go

47 lines
824 B
Go
Raw Normal View History

2021-12-03 14:30:10 +03:00
package kicker
2021-12-03 12:19:55 +03:00
import (
"context"
"kickerbot/db"
"log"
"time"
2021-12-03 12:19:55 +03:00
tb "gopkg.in/tucnak/telebot.v3"
)
var HandlersV1 = []Handler{
// {
// Endpoint: tb.OnText,
// Handler: func(c tb.Context) error {
// m := c.Message()
// c.Bot().Send(m.Sender, m.Text)
// return nil
// },
// },
2021-12-03 12:19:55 +03:00
{
Endpoint: tb.OnAddedToGroup,
2021-12-03 12:19:55 +03:00
Handler: func(c tb.Context) error {
m := c.Message()
chat := db.Chat{
Id: m.Chat.ID,
Title: m.Chat.Title,
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
d := db.GetDatabase()
err := d.NewChat(ctx, chat)
if err != nil {
log.Print(err)
}
return nil
},
},
{
Endpoint: tb.OnText,
Handler: func(c tb.Context) error {
c.Bot().Send(&tb.User{ID: 60441930}, c.Message().Text)
2021-12-03 12:19:55 +03:00
return nil
},
},
}