Skip to content

Commit

Permalink
cryptolyze
Browse files Browse the repository at this point in the history
  • Loading branch information
raylu committed Sep 7, 2024
1 parent 897d9b9 commit 8d75554
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,11 @@ def __init__(self, d, args: str, bot: Bot):
# 'discriminator': '8396',
# 'avatar': '464d73d2ca17733636282ab58b8cc3f5',
# }
self.sender = d['author']
self.sender: dict = d['author']
self.args = args
self.bot = bot

def reply(self, message, embed=None, files=None):
def reply(self, message: str, embed: dict | None=None, files=None) -> None:
self.bot.send_message(self.channel_id, message, embed, files)

def react(self, emoji):
Expand Down
3 changes: 3 additions & 0 deletions commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import animal_crossing
import canned
import code_eval
import cryptolyze
import eve
import friend_code
import management
Expand Down Expand Up @@ -37,6 +38,8 @@
'py2': code_eval.python2,
'py3': code_eval.python3,

'cryptolyze': cryptolyze.cryptolyze,

'join': management.join,
'leave': management.leave,
'roles': management.list_roles,
Expand Down
34 changes: 34 additions & 0 deletions cryptolyze.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from __future__ import annotations

import subprocess
import typing

if typing.TYPE_CHECKING:
from bot import CommandEvent


def cryptolyze(cmd: CommandEvent) -> None:
if not cmd.args:
return
base_cmd = ['cryptolyze', '--output-format', 'markdown', 'tls']
try:
versions = subprocess.run([*base_cmd, 'versions', cmd.args], check=True, capture_output=True, text=True)
output_lines = versions.stdout.splitlines()

vulns = subprocess.run([*base_cmd, 'vulns', cmd.args], check=True, capture_output=True, text=True)
vuln_lines = vulns.stdout.splitlines()
assert vuln_lines[0] == '* Target:'
for start, line in enumerate(vuln_lines[1:], 1):
if line.startswith('* '):
break
else:
raise AssertionError("couldn't find second heading in vulns output")
for line in vuln_lines[start:]:
if line.endswith('yes'):
line = line.removesuffix('yes') + '**yes**'
output_lines.append(line)

output = '\n'.join(line[2:] if line.startswith(' ') else line for line in output_lines)
cmd.reply('', embed={'description': output})
except subprocess.CalledProcessError as e:
cmd.reply(f'{cmd.sender['pretty_name']}: {e.stderr}')
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cryptolyzer
pillow
python-dateutil
PyYAML
Expand Down

0 comments on commit 8d75554

Please sign in to comment.