Use configparser in examplebot

This commit is contained in:
Joscha 2018-08-02 20:18:21 +00:00
parent 78bb6b935f
commit 5c254f4e70
4 changed files with 28 additions and 10 deletions

1
.gitignore vendored
View file

@ -1,3 +1,2 @@
**/__pycache__/
*.db
*.cookie

9
examplebot.conf Normal file
View file

@ -0,0 +1,9 @@
[general]
nick = ExampleBot
cookiefile = examplebot.cookie
[rooms]
# Format:
# room
# room=password
test

View file

@ -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")

View file

@ -1,2 +0,0 @@
def join_rooms(bot):
bot.join_room("test")