From a518dece041dac858dc3e050d8a3560f0ad46d02 Mon Sep 17 00:00:00 2001 From: Siina Mashek Date: Tue, 19 Apr 2022 14:12:27 +0300 Subject: [PATCH] Made quote system and its dependencies optional --- README.md | 4 ++-- ameliabot/owncast.py | 16 +++++++++------- config/owncast.example.json | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1bcfb07..232bf40 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ Code attributions can be found in `ATTRIBUTIONS.md` ## Setup -* Install Flask and psycopg2 - * `pip --user install Flask psycopg2` +* Install Flask and (optionally for the quote system) psycopg2 + * `pip --user install Flask` * If you don't want to fiddle with psycopg2, you can install `python-psycopg2` from your distribution's package manager * Create an Owncast webhook url pointing to your bot's location * http://localhost:5000/webhook/owncast if bot and owncast are on the same machine diff --git a/ameliabot/owncast.py b/ameliabot/owncast.py index 033e185..4a4bc80 100644 --- a/ameliabot/owncast.py +++ b/ameliabot/owncast.py @@ -5,7 +5,6 @@ import requests from requests.structures import CaseInsensitiveDict from ameliabot.init_logging import init_logging from ameliabot.logger import logging -from ameliabot.quote import Quote from flask import request init_logging() @@ -21,6 +20,15 @@ except FileNotFoundError: logging.error("Please see README.md for more information.") raise SystemExit +# Make quote system and dependencies optional +if config["quote_enabled"]: + from ameliabot.quote import Quote + quote = Quote( + database=config["quote_db_name"], + user=config["quote_db_user"], + password=config["quote_db_pass"], + ) + with open("commands.json", "r") as f: commands = json.load(f) logging.info("Commands loaded") @@ -29,12 +37,6 @@ with open("alias.json", "r") as f: aliases = json.load(f) logging.info("Aliases loaded") -quote = Quote( - database=config["quote_db_name"], - user=config["quote_db_user"], - password=config["quote_db_pass"], - ) - # prepare the header for the bot posts headers = CaseInsensitiveDict() headers["Content-Type"] = "application/json" diff --git a/config/owncast.example.json b/config/owncast.example.json index c85b798..ef8ba45 100644 --- a/config/owncast.example.json +++ b/config/owncast.example.json @@ -2,6 +2,7 @@ "owncast_server": "localhost", "access_token": "", "streamer_name": "owncast streamer", + "quote_enabled": false, "quote_db_name": "", "quote_db_user": "", "quote_db_pass": ""