fix bot --rr flag; tidy up bot /help & /start; cosmetics

master
Tomáš Mládek 2021-09-22 23:56:42 +02:00
parent 04ba5b7e4e
commit a5068e4b64
1 changed files with 14 additions and 15 deletions

View File

@ -1,10 +1,7 @@
from genericpath import isdir
import logging
import os
import subprocess
from typing import List, Optional
import re
from tempfile import NamedTemporaryFile
@ -14,7 +11,6 @@ from telegram.ext import (
CommandHandler,
DictPersistence,
CallbackContext,
defaults,
)
from telegram.parsemode import ParseMode
from parser import SafeArgumentParser, safe_str
@ -48,11 +44,11 @@ class KollagenBot:
parser = SafeArgumentParser(prog="/generate", add_help=False)
parser.add_argument(
"directories",
metavar="dir",
metavar="path",
type=safe_str,
nargs="*",
default=[self.base_dir] if self.base_dir else [],
help="Directories to process. By default, the entire directory is processed.",
help="Directories or files to process. By default, the entire base directory is processed.",
)
parser.add_argument(
"-m",
@ -61,14 +57,14 @@ class KollagenBot:
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.",
help=f"Collage modes to use. By default, one is chosen at random. Multiple modes can be specified, separated by commas. When no value is specified, all modes are listed.",
)
parser.add_argument(
"-n",
dest="num_images",
metavar="N",
type=int,
help=f"How many images to have in a collage. Random (2<n<5) by default.",
help=f"How many images to use in a single collage. Random (or collage-dependant) by default.",
)
parser.add_argument(
"-w",
@ -88,7 +84,7 @@ class KollagenBot:
"--rm",
dest="recursive_modes",
type=safe_str,
help=f"Collage modes to use in a recursive collage. All by default.",
help=f"Collage modes (comma-separated) to use in a recursive collage. All by default.",
)
parser.add_argument(
"--rl",
@ -100,9 +96,8 @@ class KollagenBot:
parser.add_argument(
"--rr",
dest="recursive_repeat",
type=bool,
default=False,
help=f"Allow repeating images in recursive collages. False by default.",
action="store_true",
help=f"Allow repeating images in (different levels of) recursive collages. False by default.",
)
self.parser = parser
@ -113,7 +108,7 @@ class KollagenBot:
return modes.stdout.decode("utf-8").strip().split(", ")
def tg_start(self, update: Update, context: CallbackContext):
update.message.reply_text("Hi! Check out https://gitlab.com/tmladek/kollagen")
update.message.reply_text("Hi! I make random collages. Check out https://gitlab.com/tmladek/kollagen and /help. Here's one to get you started:")
self._process([], update)
def tg_generate(self, update: Update, context: CallbackContext):
@ -154,9 +149,13 @@ 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_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 []
recursive_modes = (
["--rm", str(args.recursive_modes)] if args.recursive_modes else []
)
with NamedTemporaryFile(suffix=".png") as ntf:
shell_cmd_line = [