Use configparser

This commit is contained in:
Joscha 2018-08-02 20:38:43 +00:00
parent b2f379d8e7
commit 514f9feecc
2 changed files with 17 additions and 6 deletions

2
.gitignore vendored
View file

@ -1,5 +1,5 @@
**/__pycache__ **/__pycache__
yaboli yaboli
websockets websockets
join_rooms.py *.conf
*.cookie *.cookie

View file

@ -1,9 +1,9 @@
import asyncio import asyncio
import configparser
import logging import logging
import yaboli import yaboli
from yaboli.utils import * 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 # Turn all debugging on
asyncio.get_event_loop().set_debug(True) 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) text = "Hosts that are currently in this room:\n" + "\n".join(sessions)
await room.send(text, message.mid) await room.send(text, message.mid)
def main(): def main(configfile):
bot = InfoBot("()", "infobot.cookie") config = configparser.ConfigParser(allow_no_value=True)
join_rooms(bot) 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() asyncio.get_event_loop().run_forever()
if __name__ == "__main__": if __name__ == "__main__":
main() main("infobot.conf")