You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.4 KiB
45 lines
1.4 KiB
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)
|
|
|