-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (42 loc) · 1.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"log/slog"
"os"
"time"
)
func main() {
token := os.Getenv("TELEGRAM_BOT_TOKEN")
if token == "" {
slog.Error("TELEGRAM_BOT_TOKEN is required")
}
bot := NewBot(token)
var offset int
for {
updates, err := bot.getUpdates(offset)
if err != nil {
slog.Error("failed to get chat updates:", err)
time.Sleep(5 * time.Second)
continue
}
for _, update := range updates {
offset = update.UpdateID + 1
if !bot.shouldSetFilter(update.Message.Text) {
continue
}
if err := bot.setFilter(update.Message); err != nil {
slog.Error("failed to set filter:", err)
continue
}
if !bot.shoudlDeleteMessage(update.Message) {
continue
}
if err := bot.deleteMessage(update.Message.Chat.ID, update.Message.MessageID); err != nil {
slog.Error("failed to delete message:", err)
continue
}
if err := bot.sendMessage("Filtered message detected and removed", update.Message.Chat.ID, update.Message.MessageID); err != nil {
slog.Error("failed to send reply message that was detected and removed:", err)
}
}
}
}