discord tester in english
This commit is contained in:
@@ -23,15 +23,15 @@ class TestCVEDiscordBot(discord.Client):
|
||||
self.test_sent = False
|
||||
|
||||
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)
|
||||
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()
|
||||
return
|
||||
|
||||
logger.info(f"✓ Połączono z kanałem: #{channel.name}")
|
||||
logger.info(f"Connected to channel: #{channel.name}")
|
||||
|
||||
test_cves = [
|
||||
{
|
||||
@@ -60,23 +60,19 @@ class TestCVEDiscordBot(discord.Client):
|
||||
}
|
||||
]
|
||||
|
||||
logger.info(f"\n{'='*60}")
|
||||
logger.info(f"Wysyłanie {len(test_cves)} testowych powiadomień CVE...")
|
||||
logger.info(f"{'='*60}\n")
|
||||
logger.info(f"Sending {len(test_cves)} test CVE notifications...")
|
||||
|
||||
for i, cve in enumerate(test_cves, 1):
|
||||
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)
|
||||
await channel.send(embed=embed)
|
||||
logger.info(f"✓ Wysłano {cve['cve_id']}")
|
||||
logger.info(f"Sent {cve['cve_id']}")
|
||||
await asyncio.sleep(1)
|
||||
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 zakończony - wysłano {len(test_cves)} powiadomień")
|
||||
logger.info(f"{'='*60}")
|
||||
logger.info(f"Test completed - sent {len(test_cves)} notifications")
|
||||
|
||||
self.test_sent = True
|
||||
await asyncio.sleep(2)
|
||||
@@ -100,17 +96,17 @@ class TestCVEDiscordBot(discord.Client):
|
||||
|
||||
embed = discord.Embed(
|
||||
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,
|
||||
timestamp=datetime.utcnow()
|
||||
)
|
||||
|
||||
embed.add_field(name="🏢 Vendor", value=vendor_name, inline=True)
|
||||
embed.add_field(name="⚠️ Severity", value=severity, inline=True)
|
||||
embed.add_field(name="Vendor", value=vendor_name, inline=True)
|
||||
embed.add_field(name="Severity", value=severity, inline=True)
|
||||
|
||||
cvss_score = cve.get('cvss_score')
|
||||
embed.add_field(
|
||||
name="📊 CVSS Score",
|
||||
name="CVSS Score",
|
||||
value=f"**{cvss_score:.1f}**" if cvss_score else "N/A",
|
||||
inline=True
|
||||
)
|
||||
@@ -120,7 +116,7 @@ class TestCVEDiscordBot(discord.Client):
|
||||
try:
|
||||
pub_date = datetime.fromisoformat(published.replace('Z', '+00:00'))
|
||||
embed.add_field(
|
||||
name="📅 Published",
|
||||
name="Published",
|
||||
value=pub_date.strftime('%Y-%m-%d %H:%M UTC'),
|
||||
inline=True
|
||||
)
|
||||
@@ -129,13 +125,13 @@ class TestCVEDiscordBot(discord.Client):
|
||||
|
||||
nvd_url = f"https://nvd.nist.gov/vuln/detail/{cve['cve_id']}"
|
||||
embed.add_field(
|
||||
name="🔗 Links",
|
||||
name="Links",
|
||||
value=f"[View on NVD]({nvd_url})",
|
||||
inline=False
|
||||
)
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -144,32 +140,29 @@ class TestCVEDiscordBot(discord.Client):
|
||||
def run_test():
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
logger.info("\n" + "="*60)
|
||||
logger.info("🧪 CVE MONITOR - TEST DISCORD NOTIFICATIONS")
|
||||
logger.info("="*60)
|
||||
logger.info("CVE MONITOR - Discord Bot Test")
|
||||
logger.info(f"Token: {config.DISCORD_BOT_TOKEN[:20]}...")
|
||||
logger.info(f"Channel ID: {config.DISCORD_CHANNEL_ID}")
|
||||
logger.info(f"Min CVSS: {config.DISCORD_MIN_CVSS}")
|
||||
logger.info("="*60 + "\n")
|
||||
|
||||
bot = TestCVEDiscordBot()
|
||||
|
||||
try:
|
||||
bot.run(config.DISCORD_BOT_TOKEN)
|
||||
except discord.LoginFailure:
|
||||
logger.error("✗ Nieprawidłowy token Discord bot")
|
||||
logger.error("Invalid Discord bot token")
|
||||
except KeyboardInterrupt:
|
||||
logger.info("\n✗ Test przerwany przez użytkownika")
|
||||
logger.info("Test interrupted by user")
|
||||
except Exception as e:
|
||||
logger.error(f"✗ Błąd: {e}", exc_info=True)
|
||||
logger.error(f"Error: {e}", exc_info=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_test()
|
||||
run_test()
|
||||
Reference in New Issue
Block a user