You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB

#!/usr/bin/env python3
# SPDX-License-Identifier: AGPL-3.0-only
import re
from third_party import utils
from pleroma import Pleroma
def parse_args():
parser = utils.arg_parser_factory(description='Generate and post a toot.')
'-s', '--simulate', dest='simulate', action='store_true',
help="Print the toot without actually posting it. Use this to make sure your bot's actually working.",
'-m', '--mode',
help='Pass one of these: ' + ', '.join(utils.TextGenerationMode.__members__),
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 = PAIRED_PUNCTUATION.sub("", toot)
toot = toot.replace("@", "@\u200b") # sanitize mentions
toot = utils.remove_mentions(cfg, toot)
except UnicodeEncodeError:
print(toot.encode("ascii", "ignore")) # encode as ASCII, dropping any non-ASCII characters
if args.simulate:
async with Pleroma(api_base_url=cfg['site'], access_token=cfg['access_token']) as pl:
await, visibility='unlisted', cw=cfg['cw'])
if __name__ == '__main__':
import anyio