add recursive args to bot as well
This commit is contained in:
parent
e391b9b6bf
commit
fd06a2a618
2 changed files with 28 additions and 2 deletions
|
@ -58,7 +58,7 @@ class KollagenBot:
|
|||
"-m",
|
||||
dest="mode",
|
||||
metavar="mode",
|
||||
choices=self._get_modes(),
|
||||
type=safe_str,
|
||||
nargs="?",
|
||||
const=True,
|
||||
help=f"Which collage mode to use. By default, one is chosen at random. When no value is specified, all modes are listed.",
|
||||
|
@ -84,6 +84,26 @@ class KollagenBot:
|
|||
default=640,
|
||||
help=f"Height of resulting output (in px). 640px by default.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--rm",
|
||||
dest="recursive_modes",
|
||||
type=safe_str,
|
||||
help=f"Collage modes to use in a recursive collage. All by default.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--rl",
|
||||
dest="recursive_level",
|
||||
type=int,
|
||||
default=3,
|
||||
help=f"Level/depth of recursive collage. 3 by default.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--rr",
|
||||
dest="recursive_repeat",
|
||||
type=bool,
|
||||
default=False,
|
||||
help=f"Allow repeating images in recursive collages. False by default.",
|
||||
)
|
||||
self.parser = parser
|
||||
|
||||
def _get_modes(self):
|
||||
|
@ -134,6 +154,9 @@ class KollagenBot:
|
|||
|
||||
mode = ["-m", args.mode] if args.mode else []
|
||||
num_images = ["-n", str(args.num_images)] if args.num_images else []
|
||||
recursive_level = ["--rl", str(args.recursive_level)] if args.recursive_level else []
|
||||
recursive_repeat = ["--rr"] if args.recursive_repeat else []
|
||||
recursive_modes = ["--rm", str(args.recursive_modes)] if args.recursive_modes else []
|
||||
|
||||
with NamedTemporaryFile(suffix=".png") as ntf:
|
||||
shell_cmd_line = [
|
||||
|
@ -145,6 +168,9 @@ class KollagenBot:
|
|||
str(args.height),
|
||||
*mode,
|
||||
*num_images,
|
||||
*recursive_level,
|
||||
*recursive_repeat,
|
||||
*recursive_modes,
|
||||
"-o",
|
||||
ntf.name,
|
||||
]
|
||||
|
|
|
@ -11,6 +11,6 @@ class SafeArgumentParser(argparse.ArgumentParser):
|
|||
raise ArgumentParserError(message)
|
||||
|
||||
def safe_str(val: str):
|
||||
if re.findall(r'[^\w]', val):
|
||||
if re.findall(r'[^\w,]', val):
|
||||
raise RuntimeError("No special characters in arguments allowed!")
|
||||
return val
|
Loading…
Reference in a new issue