nxy/bot/__main__.py

54 lines
1.1 KiB
Python
Raw Normal View History

2017-05-15 22:26:10 +00:00
# -*- coding: utf-8 -*-
import os
2017-05-15 22:26:10 +00:00
import sys
2017-07-04 13:22:20 +00:00
import json
2017-05-15 22:26:10 +00:00
from dotenv import load_dotenv
from irc3 import IrcBot
# This is a development config for use with irc3s server
2017-05-15 22:26:10 +00:00
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',
2017-05-15 22:26:10 +00:00
}
}
# TODO: regex
2017-06-30 17:33:26 +00:00
# TODO: ddg
2017-05-15 22:26:10 +00:00
def main(cfg_file):
# Load dotenv from file
2017-05-15 22:26:10 +00:00
load_dotenv('.env')
# Load config from json file
2017-05-15 22:26:10 +00:00
with open(cfg_file, 'r') as fp:
cfg = json.load(fp)
# Apply dev config if env variable is set
2017-05-15 22:26:10 +00:00
if bool(os.environ.get('DEV')):
cfg.update(CFG_DEV)
# If PASSWORD in env set it in config
2017-06-30 17:33:26 +00:00
if 'PASSWORD' in os.environ:
2017-05-15 22:26:10 +00:00
cfg['password'] = os.environ['PASSWORD']
# Start the bot with constructed config
2017-05-15 22:26:10 +00:00
bot = IrcBot.from_config(cfg)
bot.run()
if __name__ == '__main__':
2017-07-07 00:11:20 +00:00
if len(sys.argv) > 1:
config = sys.argv[1]
else:
config = 'config.json'
main(config)