2020-06-21 19:51:33 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-06-21 19:54:07 +02:00
|
|
|
"encoding/json"
|
|
|
|
|
2020-06-21 19:51:33 +02:00
|
|
|
tb "gopkg.in/tucnak/telebot.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BotHandlers(b *tb.Bot) {
|
|
|
|
|
|
|
|
b.Handle(tb.OnPhoto, botPhoto)
|
|
|
|
b.Handle(tb.OnChannelPost, botChannelPost)
|
|
|
|
b.Handle(tb.OnQuery, botQuery)
|
|
|
|
b.Handle(tb.OnText, botText)
|
|
|
|
b.Handle(tb.OnDocument, botDocument)
|
|
|
|
|
|
|
|
b.Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
func PrintText(m *tb.Message) {
|
|
|
|
logInfoDebug("[%d] %s(%d) | %s(%d) : %s\n", m.ID, m.Chat.Title, m.Chat.ID, m.Sender.Username, m.Sender.ID, m.Text)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func botPhoto(m *tb.Message) {
|
|
|
|
logInfoDebug("botPhoto :", m.Text)
|
|
|
|
// photos only
|
|
|
|
}
|
|
|
|
|
|
|
|
func botDocument(m *tb.Message) {
|
|
|
|
logInfoDebug("botDocument : %s (%d bytes)\n", m.Document.FileName, m.Document.File.FileSize)
|
|
|
|
// documents only
|
|
|
|
}
|
|
|
|
|
|
|
|
func botChannelPost(m *tb.Message) {
|
|
|
|
PrintText(m)
|
|
|
|
b, _ := json.Marshal(m)
|
2020-06-21 19:54:07 +02:00
|
|
|
logInfoDebug("botChannelPost : %s\n", string(b))
|
2020-06-21 19:51:33 +02:00
|
|
|
|
|
|
|
// channel posts only
|
|
|
|
}
|
|
|
|
|
|
|
|
func botQuery(q *tb.Query) {
|
|
|
|
logInfoDebug("botQuery")
|
|
|
|
// incoming inline queries
|
|
|
|
}
|
|
|
|
|
|
|
|
func botText(m *tb.Message) {
|
|
|
|
PrintText(m)
|
|
|
|
}
|
2020-06-21 20:07:37 +02:00
|
|
|
|
|
|
|
func sendChat(chatID int64, text string) {
|
|
|
|
opt := tb.SendOptions{
|
|
|
|
ParseMode: tb.ModeDefault,
|
|
|
|
}
|
|
|
|
|
|
|
|
ch := tb.Chat{
|
|
|
|
ID: chatID,
|
|
|
|
}
|
2020-06-21 20:08:14 +02:00
|
|
|
_, err := bot.Send(&ch, text, &opt)
|
2020-06-21 20:08:45 +02:00
|
|
|
logErrorDebug(err, "sendChat")
|
2020-06-21 20:07:37 +02:00
|
|
|
}
|