discord tester in english
This commit is contained in:
@@ -23,15 +23,15 @@ class TestCVEDiscordBot(discord.Client):
|
|||||||
self.test_sent = False
|
self.test_sent = False
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
logger.info(f'✓ Bot zalogowany jako {self.user}')
|
logger.info(f'Bot logged in as {self.user}')
|
||||||
|
|
||||||
channel = self.get_channel(self.channel_id)
|
channel = self.get_channel(self.channel_id)
|
||||||
if not channel:
|
if not channel:
|
||||||
logger.error(f"✗ Nie można znaleźć kanału {self.channel_id}")
|
logger.error(f"Cannot find channel {self.channel_id}")
|
||||||
await self.close()
|
await self.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info(f"✓ Połączono z kanałem: #{channel.name}")
|
logger.info(f"Connected to channel: #{channel.name}")
|
||||||
|
|
||||||
test_cves = [
|
test_cves = [
|
||||||
{
|
{
|
||||||
@@ -60,23 +60,19 @@ class TestCVEDiscordBot(discord.Client):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
logger.info(f"\n{'='*60}")
|
logger.info(f"Sending {len(test_cves)} test CVE notifications...")
|
||||||
logger.info(f"Wysyłanie {len(test_cves)} testowych powiadomień CVE...")
|
|
||||||
logger.info(f"{'='*60}\n")
|
|
||||||
|
|
||||||
for i, cve in enumerate(test_cves, 1):
|
for i, cve in enumerate(test_cves, 1):
|
||||||
try:
|
try:
|
||||||
logger.info(f"[{i}/{len(test_cves)}] Wysyłanie: {cve['cve_id']} ({cve['severity']})")
|
logger.info(f"[{i}/{len(test_cves)}] Sending: {cve['cve_id']} ({cve['severity']})")
|
||||||
embed = self.create_cve_embed(cve)
|
embed = self.create_cve_embed(cve)
|
||||||
await channel.send(embed=embed)
|
await channel.send(embed=embed)
|
||||||
logger.info(f"✓ Wysłano {cve['cve_id']}")
|
logger.info(f"Sent {cve['cve_id']}")
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"✗ Błąd przy wysyłaniu {cve['cve_id']}: {e}")
|
logger.error(f"Error sending {cve['cve_id']}: {e}")
|
||||||
|
|
||||||
logger.info(f"\n{'='*60}")
|
logger.info(f"Test completed - sent {len(test_cves)} notifications")
|
||||||
logger.info(f"✓ Test zakończony - wysłano {len(test_cves)} powiadomień")
|
|
||||||
logger.info(f"{'='*60}")
|
|
||||||
|
|
||||||
self.test_sent = True
|
self.test_sent = True
|
||||||
await asyncio.sleep(2)
|
await asyncio.sleep(2)
|
||||||
@@ -100,17 +96,17 @@ class TestCVEDiscordBot(discord.Client):
|
|||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title=f"🧪 TEST: {cve['cve_id']}",
|
title=f"🧪 TEST: {cve['cve_id']}",
|
||||||
description=f"**[TESTOWE POWIADOMIENIE]**\n\n{cve.get('description', 'No description')}",
|
description=f"**[TEST NOTIFICATION]**\n\n{cve.get('description', 'No description')}",
|
||||||
color=color,
|
color=color,
|
||||||
timestamp=datetime.utcnow()
|
timestamp=datetime.utcnow()
|
||||||
)
|
)
|
||||||
|
|
||||||
embed.add_field(name="🏢 Vendor", value=vendor_name, inline=True)
|
embed.add_field(name="Vendor", value=vendor_name, inline=True)
|
||||||
embed.add_field(name="⚠️ Severity", value=severity, inline=True)
|
embed.add_field(name="Severity", value=severity, inline=True)
|
||||||
|
|
||||||
cvss_score = cve.get('cvss_score')
|
cvss_score = cve.get('cvss_score')
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="📊 CVSS Score",
|
name="CVSS Score",
|
||||||
value=f"**{cvss_score:.1f}**" if cvss_score else "N/A",
|
value=f"**{cvss_score:.1f}**" if cvss_score else "N/A",
|
||||||
inline=True
|
inline=True
|
||||||
)
|
)
|
||||||
@@ -120,7 +116,7 @@ class TestCVEDiscordBot(discord.Client):
|
|||||||
try:
|
try:
|
||||||
pub_date = datetime.fromisoformat(published.replace('Z', '+00:00'))
|
pub_date = datetime.fromisoformat(published.replace('Z', '+00:00'))
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="📅 Published",
|
name="Published",
|
||||||
value=pub_date.strftime('%Y-%m-%d %H:%M UTC'),
|
value=pub_date.strftime('%Y-%m-%d %H:%M UTC'),
|
||||||
inline=True
|
inline=True
|
||||||
)
|
)
|
||||||
@@ -129,13 +125,13 @@ class TestCVEDiscordBot(discord.Client):
|
|||||||
|
|
||||||
nvd_url = f"https://nvd.nist.gov/vuln/detail/{cve['cve_id']}"
|
nvd_url = f"https://nvd.nist.gov/vuln/detail/{cve['cve_id']}"
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="🔗 Links",
|
name="Links",
|
||||||
value=f"[View on NVD]({nvd_url})",
|
value=f"[View on NVD]({nvd_url})",
|
||||||
inline=False
|
inline=False
|
||||||
)
|
)
|
||||||
|
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text=f"🧪 CVE Monitor TEST • {vendor_name}",
|
text=f"CVE Monitor TEST • {vendor_name}",
|
||||||
icon_url="https://nvd.nist.gov/favicon.ico"
|
icon_url="https://nvd.nist.gov/favicon.ico"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -144,31 +140,28 @@ class TestCVEDiscordBot(discord.Client):
|
|||||||
def run_test():
|
def run_test():
|
||||||
|
|
||||||
if not config.DISCORD_BOT_TOKEN:
|
if not config.DISCORD_BOT_TOKEN:
|
||||||
logger.error("✗ DISCORD_BOT_TOKEN nie jest ustawiony w .env")
|
logger.error("DISCORD_BOT_TOKEN not set in .env")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not config.DISCORD_CHANNEL_ID:
|
if not config.DISCORD_CHANNEL_ID:
|
||||||
logger.error("✗ DISCORD_CHANNEL_ID nie jest ustawiony w .env")
|
logger.error("DISCORD_CHANNEL_ID not set in .env")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
logger.info("\n" + "="*60)
|
logger.info("CVE MONITOR - Discord Bot Test")
|
||||||
logger.info("🧪 CVE MONITOR - TEST DISCORD NOTIFICATIONS")
|
|
||||||
logger.info("="*60)
|
|
||||||
logger.info(f"Token: {config.DISCORD_BOT_TOKEN[:20]}...")
|
logger.info(f"Token: {config.DISCORD_BOT_TOKEN[:20]}...")
|
||||||
logger.info(f"Channel ID: {config.DISCORD_CHANNEL_ID}")
|
logger.info(f"Channel ID: {config.DISCORD_CHANNEL_ID}")
|
||||||
logger.info(f"Min CVSS: {config.DISCORD_MIN_CVSS}")
|
logger.info(f"Min CVSS: {config.DISCORD_MIN_CVSS}")
|
||||||
logger.info("="*60 + "\n")
|
|
||||||
|
|
||||||
bot = TestCVEDiscordBot()
|
bot = TestCVEDiscordBot()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bot.run(config.DISCORD_BOT_TOKEN)
|
bot.run(config.DISCORD_BOT_TOKEN)
|
||||||
except discord.LoginFailure:
|
except discord.LoginFailure:
|
||||||
logger.error("✗ Nieprawidłowy token Discord bot")
|
logger.error("Invalid Discord bot token")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logger.info("\n✗ Test przerwany przez użytkownika")
|
logger.info("Test interrupted by user")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"✗ Błąd: {e}", exc_info=True)
|
logger.error(f"Error: {e}", exc_info=True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user