From 514f9feeccfd594b241677c6550871ca19a13365 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 2 Aug 2018 20:38:43 +0000 Subject: [PATCH] Use configparser --- .gitignore | 2 +- infobot.py | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 36517c4..5b60467 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ **/__pycache__ yaboli websockets -join_rooms.py +*.conf *.cookie diff --git a/infobot.py b/infobot.py index 4f24472..f8f87d5 100644 --- a/infobot.py +++ b/infobot.py @@ -1,9 +1,9 @@ import asyncio +import configparser import logging import yaboli from yaboli.utils import * -from join_rooms import join_rooms # List of rooms kept in separate file, which is .gitignore'd # Turn all debugging on asyncio.get_event_loop().set_debug(True) @@ -148,10 +148,21 @@ class InfoBot(yaboli.Bot): text = "Hosts that are currently in this room:\n" + "\n".join(sessions) await room.send(text, message.mid) -def main(): - bot = InfoBot("()", "infobot.cookie") - join_rooms(bot) +def main(configfile): + config = configparser.ConfigParser(allow_no_value=True) + config.read(configfile) + + nick = config.get("general", "nick") + cookiefile = config.get("general", "cookiefile", fallback=None) + print(cookiefile) + bot = InfoBot(nick, cookiefile=cookiefile) + + for room, password in config.items("rooms"): + if not password: + password = None + bot.join_room(room, password=password) + asyncio.get_event_loop().run_forever() if __name__ == "__main__": - main() + main("infobot.conf")