diff --git a/gen.py b/gen.py index a46c292..25e94cc 100755 --- a/gen.py +++ b/gen.py @@ -18,13 +18,18 @@ def parse_args(): ) return parser.parse_args() +PAIRED_PUNCTUATION = re.compile(r"[{}]".format(re.escape('[](){}"‘’“”«»„'))) + async def main(): args = parse_args() cfg = utils.load_config(args.cfg) toot = await utils.make_post(cfg, mode=utils.TextGenerationMode.__members__[args.mode]) if cfg['strip_paired_punctuation']: - toot = re.sub(r"[\[\]\(\)\{\}\"“”«»„]", "", toot) + toot = PAIRED_PUNCTUATION.sub("", toot) + toot = toot.replace("@", "@\u200b") # sanitize mentions + toot = utils.remove_mentions(cfg, toot) + if not args.simulate: async with Pleroma(api_base_url=cfg['site'], access_token=cfg['access_token']) as pl: try: diff --git a/third_party/utils.py b/third_party/utils.py index 1eac5f3..3680530 100644 --- a/third_party/utils.py +++ b/third_party/utils.py @@ -54,7 +54,7 @@ def load_config(cfg_path): return cfg -def remove_mention(cfg, sentence): +def remove_mentions(cfg, sentence): # optionally remove mentions if cfg['mention_handling'] == 1: return re.sub(r"^\S*@\u200B\S*\s?", "", sentence)