Cleaner message format, add malware family extraction

This commit is contained in:
bot
2026-04-23 22:34:58 +03:00
parent e3307391c7
commit a9460cec07
2 changed files with 51 additions and 35 deletions
+15 -32
View File
@@ -449,7 +449,6 @@ class RSSFeedManager:
@staticmethod
def format_telegram_message(article: Dict) -> Tuple[str, Optional[str]]:
"""Format article for Telegram message"""
# Category emoji mapping
category_emojis = {
'news': '📰',
'malware': '🦠',
@@ -459,48 +458,32 @@ class RSSFeedManager:
}
emoji = category_emojis.get(article.get('category', ''), '📰')
category_display = article.get('category', '').replace('_', ' ').title()
title = escape(article.get('title', 'No Title'))
description = escape(article.get('description', ''))
source = escape(article.get('source', 'Unknown Source'))
published_human = escape(article.get('published_human', 'Unknown'))
category_safe = escape(category_display)
url = escape(article.get('url', ''), quote=True)
severity = article.get('severity', 'unknown').lower()
quality_score = article.get('quality_score')
cves = article.get('cves', [])[:3]
classifications = article.get('classifications', [])[:3]
severity_emoji = {
'critical': '🚨',
'high': '🔴',
'medium': '🟠',
'low': '🟡',
}.get(severity, '')
severity_safe = escape(severity.upper())
cves = article.get('cves', [])[:5]
threat_actors = article.get('threat_actors', [])[:3]
malware_families = article.get('malware_families', [])[:3]
message = f"{emoji} <b>{title}</b>\n\n"
if description:
message += f"📋 {description}\n\n"
message += f"{description}\n\n"
message += f"📡 {source} · {published_human}\n"
message += f"🏷️ <b>Category:</b> {category_safe}\n"
message += f"📡 <b>Source:</b> {source}\n"
message += f"{severity_emoji} <b>Severity:</b> {severity_safe}\n"
if quality_score is not None:
message += f"⭐ <b>Quality:</b> {int(quality_score)}/100\n"
if classifications:
class_text = ", ".join(escape(c) for c in classifications)
message += f"🧠 <b>Type:</b> {class_text}\n"
if cves:
cve_text = ", ".join(escape(cve) for cve in cves)
message += f"🆔 <b>CVEs:</b> {cve_text}\n"
why_this_matters = RSSFeedManager.build_why_this_matters(article)
if why_this_matters:
message += f"🎯 <b>Why This Matters:</b> {escape(why_this_matters)}\n"
message += f"⏰ <b>Published:</b> {published_human}\n"
message += f"🔗 <b><a href=\"{url}\">Read Full Article</a></b>"
message += f"🆔 {', '.join(escape(c) for c in cves)}\n"
if threat_actors:
message += f"👤 {', '.join(escape(a.title()) for a in threat_actors)}\n"
if malware_families:
message += f"🦠 {', '.join(escape(f) for f in malware_families)}\n"
message += f"\n🔗 <a href=\"{url}\">Read Full Article</a>"
return message, article.get('thumbnail')