Add group username if it has one

This commit is contained in:
Astra 2026-03-01 09:52:54 +00:00
parent fdd1484c48
commit d9f71f1a3f

10
bot.go
View file

@ -414,17 +414,21 @@ func handleNewMessage(ctx context.Context, api *tg.Client, alertPeer *tg.InputPe
log.Printf("Failed to restrict user %d: %v", senderID, err) log.Printf("Failed to restrict user %d: %v", senderID, err)
} }
// Get supergroup name // Get supergroup name and username
chatName := channel.Title chatName := channel.Title
chatDisplay := escapeMarkdown(chatName)
if channel.Username != "" {
chatDisplay += " (@" + escapeMarkdown(channel.Username) + ")"
}
// Build alert message with HTML formatting for markdown v2 // Build alert message with HTML formatting for markdown v2
matchMessageHTML := fmt.Sprintf("🚨 Matched\n<b>Score</b>: %.2f\n<b>Chat</b>: %s (ID: %d)\n<b>User</b>: %s (ID: %d)\n", matchMessageHTML := fmt.Sprintf("🚨 Matched\n<b>Score</b>: %.2f\n<b>Chat</b>: %s (ID: %d)\n<b>User</b>: %s (ID: %d)\n",
result.score, escapeMarkdown(chatName), chatID, displayName+" ("+username+")", senderID) result.score, chatDisplay, chatID, displayName+" ("+username+")", senderID)
// Send ntfy notification if config set (use plain text for ntfy) // Send ntfy notification if config set (use plain text for ntfy)
if cfg.NtfyToken != "" || cfg.NtfyTopic != "" { if cfg.NtfyToken != "" || cfg.NtfyTopic != "" {
plainMessage := fmt.Sprintf("🚨 Matched\nScore: %.2f\nChat: %s (ID: %d)\nUser: %s (ID: %d)\n\n%s", plainMessage := fmt.Sprintf("🚨 Matched\nScore: %.2f\nChat: %s (ID: %d)\nUser: %s (ID: %d)\n\n%s",
result.score, escapeMarkdown(chatName), chatID, escapeMarkdown(displayName+" ("+username+")"), senderID, escapeMarkdown(msg.Message)) result.score, escapeMarkdown(chatDisplay), chatID, escapeMarkdown(displayName+" ("+username+")"), senderID, escapeMarkdown(msg.Message))
notify(plainMessage, cfg.NtfyHost, cfg.NtfyTopic, fmt.Sprintf("Scam Alert: %s", chatName), 5, cfg.NtfyToken) notify(plainMessage, cfg.NtfyHost, cfg.NtfyTopic, fmt.Sprintf("Scam Alert: %s", chatName), 5, cfg.NtfyToken)
} }