diff --git a/.gitignore b/.gitignore index 72f8dd3..f6d9da2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ *.kate-swp *.log data/ -config/owncast.json +config.ini # ---> Python # Byte-compiled / optimized / DLL files diff --git a/alias.json b/alias.json deleted file mode 100644 index 16bb249..0000000 --- a/alias.json +++ /dev/null @@ -1 +0,0 @@ - {} diff --git a/ameliabot/__init__.py b/ameliabot/__init__.py index 09066b5..5b2764e 100644 --- a/ameliabot/__init__.py +++ b/ameliabot/__init__.py @@ -1,10 +1,10 @@ -import json +from configparser import ConfigParser import sys from ameliabot.logger import ColorizedArgsFormatter, BraceFormatStyleFormatter from ameliabot.logger import logging -__version__ = "0.0.1" +__version__ = "0.1.0" # Set up logging root_logger = logging.getLogger() @@ -25,20 +25,40 @@ file_format = "%(asctime)s - %(name)s (%(lineno)s) - %(levelname)-8s - %(threadN file_handler.setFormatter(BraceFormatStyleFormatter(file_format)) root_logger.addHandler(file_handler) -# Get basic owncast bot config +# Load bot config +config = ConfigParser() try: - with open("config/owncast.json", "r") as f: - config = json.load(f) - logging.info("Configuration loaded") + config.read("config.ini") + logging.info("Configuration loaded") except FileNotFoundError: - logging.error("Configuration file not found.") - logging.error("Please see README.md for more information.") + config["DEFAULT"] = {"BotName": "ameliabot", "BotOwner": "Some Name"} + config["owncast"] = { + "ServerURL": "https://yourowncloud.server", + "AccessToken": "Someaccesstoken23-209523dfsd"} + with open("config.ini", "w") as f: + config.write(f) + logging.error("Configuration file not found so minimal one generated.") + logging.error("Please edit config.ini and try again.") + logging.error("See config.example.ini for full options") raise SystemExit -with open("commands.json", "r") as f: - commands = json.load(f) +cmd_file = ConfigParser() +try: + cmd_file.read("commands.ini") + commands = cmd_file["commands"] + if config["quotes"]["Enabled"]: + # Perhaps configparser handles this and I haven't figured it out + for cmd in cmd_file["commands.quote"]: + commands[cmd] = cmd_file["commands.quote"][cmd] logging.info("Commands loaded") -with open("alias.json", "r") as f: - aliases = json.load(f) + aliases = cmd_file["aliases"] logging.info("Aliases loaded") +except FileNotFoundError: + cmd_file["commands"] = { + "!version": "I am running ameliabot {bot_version}"} + cmd_file["aliases"] = {"!bot": "!version"} + with open("commands.ini", "w") as f: + cmd_file.write(f) + logging.error("Missing commands.ini! Generated basic file.") + raise SystemExit diff --git a/ameliabot/owncast.py b/ameliabot/owncast.py index 0dc70cc..ad55c5e 100644 --- a/ameliabot/owncast.py +++ b/ameliabot/owncast.py @@ -6,16 +6,16 @@ from ameliabot.logger import logging from flask import request # Make quote system and dependencies optional -if config["quote_enabled"]: +if config["quotes"]["Enabled"]: from ameliabot.quote import Quote quote = Quote() # prepare the header for the bot posts headers = CaseInsensitiveDict() headers["Content-Type"] = "application/json" -headers["Authorization"] = "Bearer {}".format(config["access_token"]) +headers["Authorization"] = "Bearer {}".format(config["owncast"]["AccessToken"]) -post_url = "%s/api/integrations/chat/send" % config["owncast_server"] +post_url = "%s/api/integrations/chat/send" % config["owncast"]["ServerURL"] def parse_webhook(): @@ -79,7 +79,7 @@ def process_chat(data): # This is so bad, it runs everything every command :pikajoy: placeholders = { "sender": sender, - "streamer": config["streamer_name"], + "streamer": config["DEFAULT"]["BotOwner"], "target": first_parameter, "random": str(random.randrange(1, 100, 1)), "commands": ", ".join(list(commands.keys())), diff --git a/bot.py b/bot.py index a894253..8ed1f2e 100644 --- a/bot.py +++ b/bot.py @@ -4,11 +4,12 @@ from ameliabot import owncast, __version__ from ameliabot.logger import logging -logging.info("Loaded %s v%s" % (owncast.config["bot_name"], __version__)) +logging.info("Loaded %s, running ameliabot v%s)" % ( + owncast.config["DEFAULT"]["BotName"], __version__)) # the url of the Owncast API for bot posts owncast_url = "{}/api/integrations/chat/send".format( - owncast.config["owncast_server"]) + owncast.config["owncast"]["ServerURL"]) app = Flask(__name__) diff --git a/commands.ini b/commands.ini new file mode 100644 index 0000000..e1eec47 --- /dev/null +++ b/commands.ini @@ -0,0 +1,16 @@ +[commands] +!help = Commands {command} +!backseat = **No backseating** unless {botowner} specifically asks for help +!hydrate = [HYDRATE] {sender} wants {botowner} to take a drink! +!stretch = [STRETCH] {sender} reminds {botowner} to stretch! +!save = {sender} is reminding {botowner} to _**SAVE NOW**_! +!slap = *slaps {target} with a large trout!* +!version = I am running ameliabot {bot_version} + +[commands.quote] +!quote = {quote} +!addquote = {quote_parameters} + +[aliases] +help = commands +bot = version diff --git a/commands.json b/commands.json deleted file mode 100644 index 8a66ca5..0000000 --- a/commands.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "!help": "Commands: {commands}", - "!backseat": "**No backseating** unless I specifically ask for help.", - "!hydrate": "[HYDRATE] {sender} wants {streamer} to take a drink!", - "!stretch": "[STRETCH] {sender} reminds {streamer} to stretch dat body.", - "!save": "SAVE! **NOW!!!**", - "!love": "There is **{random}% love** between {sender} and {target} <3", - "!slap": "*slaps {target} with a large trout!*", - "!bot": "I am currently running **ameliabot {bot_version}**", - "!quote": "{quote}", - "!addquote": "{quote_parameters}" -} diff --git a/config.example.ini b/config.example.ini new file mode 100644 index 0000000..e3be706 --- /dev/null +++ b/config.example.ini @@ -0,0 +1,10 @@ +[DEFAULT] +BotName = ameliabot +BotOwner = Some Name + +[owncast] +ServerURL = https://yourowncloud.server +AccessToken = Someaccesstoken23-209523dfsd + +[quotes] +Enabled = False diff --git a/config/owncast.example.json b/config/owncast.example.json deleted file mode 100644 index d7b4c97..0000000 --- a/config/owncast.example.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "owncast_server": "localhost", - "access_token": "", - "bot_name": "ameliabot", - "streamer_name": "owncast streamer", - "quote_enabled": false, -}