Massive refactoring/-structuring

This commit is contained in:
mrhanky
2017-07-07 02:11:20 +02:00
parent a82175a44b
commit 59b67d9570
41 changed files with 202 additions and 1011 deletions

53
bot/__main__.py Normal file
View File

@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
import os
import sys
import json
from dotenv import load_dotenv
from irc3 import IrcBot
# This is a development config for use with irc3s server
CFG_DEV = {
'nick': 'nxy',
'autojoins': ['#dev'],
'host': 'localhost',
'port': 6667,
'ssl': False,
'raw': True,
'debug': True,
'verbose': True,
'irc3.plugins.command.masks': {
'*!admin@127.0.0.1': 'all_permissions',
'*': 'view',
}
}
# TODO: regex
# TODO: ddg
def main(cfg_file):
# Load dotenv from file
load_dotenv('.env')
# Load config from json file
with open(cfg_file, 'r') as fp:
cfg = json.load(fp)
# Apply dev config if env variable is set
if bool(os.environ.get('DEV')):
cfg.update(CFG_DEV)
# If PASSWORD in env set it in config
if 'PASSWORD' in os.environ:
cfg['password'] = os.environ['PASSWORD']
# Start the bot with constructed config
bot = IrcBot.from_config(cfg)
bot.run()
if __name__ == '__main__':
if len(sys.argv) > 1:
config = sys.argv[1]
else:
config = 'config.json'
main(config)