add prompting

This commit is contained in:
Owl 2025-03-03 04:10:37 +07:00
parent a6d58ebf6b
commit 2bb1e2dccb
9 changed files with 277 additions and 48 deletions

View file

@ -1,41 +1,9 @@
import argparse
import io
import shlex
class CustomArgParser(argparse.ArgumentParser):
def __init__(
self,
*args, **kwargs,
):
super().__init__(*args, **kwargs)
self.help_message = None
def print_help(self, file=None):
# Store the help message in a buffer instead of printing
if file is None:
help_buffer = io.StringIO()
super().print_help(file=help_buffer)
self.help_message = help_buffer.getvalue()
help_buffer.close()
else:
super().print_help(file=file)
def parse_args(self, args=None, namespace=None):
# Check for --help manually to avoid stdout output
if '--help' in args:
self.print_help()
raise RuntimeError("Help requested")
return super().parse_args(args, namespace)
def exit(self, status=0, message=None):
raise RuntimeError(message)
def error(self, message):
raise RuntimeError(f"Error: {message}")
from tgbot.shit.custom_argparser import CustomArgParser
def create_parser():
def create_hentai_parser():
parser = CustomArgParser(
description="A command to search random stuff on various image boorus. Feel free to use it irresponsibly!",
usage="@owlrandomshitbot hentai BOORU_NAME --tags TAG1,TAG2,TAG3 -l LIMIT --random -s",
@ -68,7 +36,7 @@ def create_parser():
return parser
def parse_args(args: str, parser: CustomArgParser):
def hentai_parse_args(args: str, parser: CustomArgParser):
args = parser.parse_args(shlex.split(args)).__dict__
args["tags"] = args["tags"].split(",")