Use configparser in examplebot
This commit is contained in:
parent
78bb6b935f
commit
5c254f4e70
4 changed files with 28 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,2 @@
|
||||||
**/__pycache__/
|
**/__pycache__/
|
||||||
*.db
|
|
||||||
*.cookie
|
*.cookie
|
||||||
|
|
|
||||||
9
examplebot.conf
Normal file
9
examplebot.conf
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
[general]
|
||||||
|
nick = ExampleBot
|
||||||
|
cookiefile = examplebot.cookie
|
||||||
|
|
||||||
|
[rooms]
|
||||||
|
# Format:
|
||||||
|
# room
|
||||||
|
# room=password
|
||||||
|
test
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
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)
|
||||||
logging.getLogger("asyncio").setLevel(logging.INFO)
|
#logging.getLogger("asyncio").setLevel(logging.INFO)
|
||||||
logging.getLogger("yaboli").setLevel(logging.DEBUG)
|
#logging.getLogger("yaboli").setLevel(logging.DEBUG)
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
class ExampleBot(yaboli.Bot):
|
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_kill(room, message, text="/me dies spectacularly")
|
||||||
await self.botrulez_restart(room, message, text="/me restarts spectacularly")
|
await self.botrulez_restart(room, message, text="/me restarts spectacularly")
|
||||||
|
|
||||||
def main():
|
def main(configfile):
|
||||||
bot = ExampleBot("ExampleBot", "examplebot.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 = 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()
|
asyncio.get_event_loop().run_forever()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main("examplebot.conf")
|
||||||
|
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
def join_rooms(bot):
|
|
||||||
bot.join_room("test")
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue