2024-03-11 20:15:27 +00:00
|
|
|
package bot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mymmrac/telego"
|
|
|
|
"github.com/mymmrac/telego/telegohandler"
|
2024-03-12 19:10:34 +00:00
|
|
|
"log/slog"
|
2024-03-11 20:15:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (b *Bot) chatTypeStatsCounter(bot *telego.Bot, update telego.Update, next telegohandler.Handler) {
|
|
|
|
message := update.Message
|
|
|
|
|
|
|
|
if message == nil {
|
2024-10-27 21:35:35 +00:00
|
|
|
slog.Info("stats-middleware: update has no message. skipping.")
|
2024-03-12 19:10:34 +00:00
|
|
|
|
2024-03-11 20:15:27 +00:00
|
|
|
next(bot, update)
|
2024-03-12 19:10:34 +00:00
|
|
|
|
|
|
|
return
|
2024-03-11 20:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch message.Chat.Type {
|
|
|
|
case telego.ChatTypeGroup, telego.ChatTypeSupergroup:
|
2024-10-27 21:35:35 +00:00
|
|
|
if b.isMentionOfMe(update) || b.isReplyToMe(update) {
|
|
|
|
slog.Info("stats-middleware: counting message chat type in stats", "type", message.Chat.Type)
|
|
|
|
b.stats.GroupRequest()
|
|
|
|
}
|
2024-03-11 20:15:27 +00:00
|
|
|
case telego.ChatTypePrivate:
|
2024-10-27 21:35:35 +00:00
|
|
|
slog.Info("stats-middleware: counting message chat type in stats", "type", message.Chat.Type)
|
2024-03-11 20:15:27 +00:00
|
|
|
b.stats.PrivateRequest()
|
|
|
|
}
|
|
|
|
|
|
|
|
next(bot, update)
|
|
|
|
}
|
2024-10-27 21:35:35 +00:00
|
|
|
|
|
|
|
func (b *Bot) chatHistory(bot *telego.Bot, update telego.Update, next telegohandler.Handler) {
|
|
|
|
message := update.Message
|
|
|
|
|
|
|
|
if message == nil {
|
|
|
|
slog.Info("chat-history-middleware: update has no message. skipping.")
|
|
|
|
|
|
|
|
next(bot, update)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
slog.Info("chat-history-middleware: saving message to history for", "chat_id", message.Chat.ID)
|
|
|
|
|
|
|
|
b.saveChatMessageToHistory(message)
|
|
|
|
|
|
|
|
next(bot, update)
|
|
|
|
}
|