import pdb from typing import Optional from masto_bridges.config import Config from masto_bridges.repo import Repo from masto_bridges.bot import Bot from masto_bridges.post import Post from masto_bridges.logger import init_logger from time import sleep def post_last_commit(config:Optional[Config]=None): """ Should be triggered as a commit hook because it doesn't validate the last commit hasn't already been posted. """ if config is None: config = Config() logger = init_logger('post-git', basedir=config.LOGDIR) repo = Repo(config.GIT_REPO) last_commit = repo.last_commit post = Post.from_commit(last_commit) if post.text.startswith('xpost'): logger.info('Not xposting an xpost') return bot = Bot(config=config) bot.post(post.format_masto()) def masto_bridgebot(config:Optional[Config]=None): if config is None: config = Config() bot = Bot(config=config) try: bot.init_stream() while True: sleep(1) if bot.caldav: # poll for new events bot.poll_caldav() # pdb.set_trace() # print(events.objects) bot.logger.debug('taking a breath') except KeyboardInterrupt: bot.logger.info('quitting!')