diff --git a/.gitignore b/.gitignore index 0fc3ef1..ce41371 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ **/__pycache__/ -*.db *.cookie diff --git a/examplebot.conf b/examplebot.conf new file mode 100644 index 0000000..a2386ee --- /dev/null +++ b/examplebot.conf @@ -0,0 +1,9 @@ +[general] +nick = ExampleBot +cookiefile = examplebot.cookie + +[rooms] +# Format: +# room +# room=password +test diff --git a/examplebot.py b/examplebot.py index 22536e3..1aad8eb 100644 --- a/examplebot.py +++ b/examplebot.py @@ -1,14 +1,15 @@ 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) -logging.getLogger("asyncio").setLevel(logging.INFO) -logging.getLogger("yaboli").setLevel(logging.DEBUG) +#logging.getLogger("asyncio").setLevel(logging.INFO) +#logging.getLogger("yaboli").setLevel(logging.DEBUG) +logging.basicConfig(level=logging.DEBUG) class ExampleBot(yaboli.Bot): @@ -28,10 +29,21 @@ class ExampleBot(yaboli.Bot): await self.botrulez_kill(room, message, text="/me dies spectacularly") await self.botrulez_restart(room, message, text="/me restarts spectacularly") -def main(): - bot = ExampleBot("ExampleBot", "examplebot.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 = ExampleBot(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("examplebot.conf") diff --git a/join_rooms.py b/join_rooms.py deleted file mode 100644 index cd3f3c4..0000000 --- a/join_rooms.py +++ /dev/null @@ -1,2 +0,0 @@ -def join_rooms(bot): - bot.join_room("test")