klafirc/klafirc/loader.py
2018-08-28 21:55:39 +02:00

46 lines
1.4 KiB
Python

import yaml
from .bot import Bot
from .settings import logger
class Loader:
def __init__(self, filename):
logger.info('Loading configuration from ' + filename)
with open(filename) as f:
self.dict = yaml.load(f)
self.bots = []
def load_bot_template(self, name, channel, serv, port):
template = self.dict['bots'][name]
b = Bot(nickname=name)
b.server = serv
b.channel = channel
b.port = port
for ping in template.get('on_ping', []):
b.add_ping(ping)
for ping in template.get('on_ping_python', []):
b.add_python_ping(ping)
matches = template.get('on_match', [])
for match in matches:
b.add_reaction(match, matches[match])
for match in template.get('on_match_python', []):
b.add_python_reaction(match, matches[match])
b.on_join = template.get('on_join', None)
b.min_time = template.get('min_time', 20)
return b
def load_bots(self):
for channel in self.dict['channels']:
name = channel['channel']
serv = channel['server']
port = channel.get('port', 6667)
bots_name = channel['bots']
for nickname in bots_name:
b = self.load_bot_template(nickname, name, serv, port)
self.bots.append(b)