2017-05-15 22:26:10 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-06-30 11:25:56 +00:00
|
|
|
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
|
|
|
|
2017-07-31 14:10:24 +00:00
|
|
|
# noinspection PyPackageRequirements
|
2017-05-15 22:26:10 +00:00
|
|
|
from dotenv import load_dotenv
|
|
|
|
from irc3 import IrcBot
|
|
|
|
|
2017-06-30 11:25:56 +00:00
|
|
|
# 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,
|
2017-05-18 00:01:44 +00:00
|
|
|
'irc3.plugins.command.masks': {
|
|
|
|
'*!admin@127.0.0.1': 'all_permissions',
|
|
|
|
'*': 'view',
|
2017-05-15 22:26:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-30 17:33:26 +00:00
|
|
|
# TODO: ddg
|
2017-05-15 22:26:10 +00:00
|
|
|
def main(cfg_file):
|
2017-06-30 11:25:56 +00:00
|
|
|
# Load dotenv from file
|
2017-05-15 22:26:10 +00:00
|
|
|
load_dotenv('.env')
|
2017-06-30 11:25:56 +00:00
|
|
|
|
|
|
|
# Load config from json file
|
2017-05-15 22:26:10 +00:00
|
|
|
with open(cfg_file, 'r') as fp:
|
|
|
|
cfg = json.load(fp)
|
2017-06-30 11:25:56 +00:00
|
|
|
|
|
|
|
# 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)
|
2017-06-30 11:25:56 +00:00
|
|
|
# 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']
|
2017-06-30 11:25:56 +00:00
|
|
|
|
|
|
|
# Start the bot with constructed config
|
2017-05-15 22:26:10 +00:00
|
|
|
bot = IrcBot.from_config(cfg)
|
2017-07-31 14:10:24 +00:00
|
|
|
|
2017-05-15 22:26:10 +00:00
|
|
|
bot.run()
|
2017-07-31 14:10:24 +00:00
|
|
|
bot.mode(bot.nick, '+R')
|
2017-05-15 22:26:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-07-31 13:29:59 +00:00
|
|
|
main(sys.argv[1])
|