Example #1
0
def main(_):
    setup_logs()

    # For security
    if not is_in_container():
        logging.error('Error: Not executing from container!')
        sys.exit(1)

    # Telegram API setup
    updater = None
    with open('token.priv') as f:
        updater = Updater(f.read().strip(), use_context=True)
    dp = updater.dispatcher

    # Create handler registration
    Permissions.setup(permisions_f)
    invoke_extra_args = {
        'mmj_lic': ro_path,
        'pubkey': ro_path,
        'shopping': rw_path + '/shopping/',
        'log': log_file
    }
    Loader.setup(dp, module_ordered_path, invoke_extra_args, unknown, error)

    # Load modules
    for mod in Permissions.modules():
        try:
            Loader.load(mod)
        except ModuleNotFoundError as err:
            logging.warning(str(err))

    # Start the Bot
    logging.info('Initiating polling.')
    updater.start_polling()

    # Block until you press Ctrl-C or the process receives SIGINT, SIGTERM or
    # SIGABRT. This should be used most of the time, since start_polling() is
    # non-blocking and will stop the bot gracefully.
    updater.idle()