Skip to content

Commit

Permalink
add basic anti-spam filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagleft committed Feb 20, 2023
1 parent 5edc9e9 commit 5357197
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func (b *bot) onTelegramMessage(c tb.Context) error {
chatID = c.Chat().ID
)

text = basicAntispam(text)
if text == "" {
return nil
}

uChannelID, isExists := b.getTelegramBridge(chatID)
if !isExists {
log.Printf("unknown telegram chat ID %v, bridge not found", chatID)
Expand All @@ -149,7 +154,12 @@ func (b *bot) onUtopiaChannelMessage(m structs.WsChannelMessage) {
return
}

if err := b.sendToTelegram(chatID, m.Nick, m.Text); err != nil {
message := basicAntispam(m.Text)
if message == "" {
return
}

if err := b.sendToTelegram(chatID, m.Nick, message); err != nil {
color.Red("send message to telegram: %s", err.Error())
}
}
Expand Down
8 changes: 8 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ func getTelegramNickname(user *tb.User) string {

return "anonymos"
}

func basicAntispam(message string) string {
if message == "Hi" || message == "Hello" || message == "Hilo" {
return ""
}

return message
}

0 comments on commit 5357197

Please sign in to comment.