chore: initial commit

This commit is contained in:
2024-12-30 03:01:21 -05:00
commit 47955cdfd5
15 changed files with 1322 additions and 0 deletions

29
arguments.py Normal file
View File

@@ -0,0 +1,29 @@
import argparse
import contextlib
import io
class ArgumentParser:
def __init__(self, command, description):
self.parser = argparse.ArgumentParser(
command, description=description, exit_on_error=False
)
def print_help(self):
help_buffer = io.StringIO()
with contextlib.redirect_stdout(help_buffer):
self.parser.print_help()
return help_buffer.getvalue().replace(" and exit", "")
def add_argument(self, *args, **kwargs):
self.parser.add_argument(*args, **kwargs)
async def parse_args(self, message, tokens) -> argparse.Namespace | None:
try:
with contextlib.redirect_stdout(io.StringIO()):
args = self.parser.parse_args(tokens[1:])
return args
except SystemExit:
await message.reply(f"```\n{self.print_help()}```", mention_author=False)
except Exception as e:
await message.reply(f"`{e}`", mention_author=False)