2013-12-28 09:58:20 -08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
import logging
|
2017-03-27 22:57:03 -07:00
|
|
|
import signal
|
2016-11-06 15:00:15 -08:00
|
|
|
from argparse import ArgumentParser
|
2017-11-27 18:58:20 -08:00
|
|
|
from pyircbot.common import load
|
2015-06-18 19:29:46 -07:00
|
|
|
from pyircbot import PyIRCBot
|
2017-05-01 08:29:20 -07:00
|
|
|
from json import loads
|
2013-12-28 09:58:20 -08:00
|
|
|
|
2017-03-27 22:57:03 -07:00
|
|
|
|
2013-12-28 09:58:20 -08:00
|
|
|
if __name__ == "__main__":
|
2015-11-01 18:03:11 -08:00
|
|
|
" logging level and facility "
|
2017-01-01 14:59:01 -08:00
|
|
|
logging.basicConfig(level=logging.INFO,
|
|
|
|
format="%(asctime)-15s %(levelname)-8s %(filename)s:%(lineno)d %(message)s")
|
2015-11-01 18:03:11 -08:00
|
|
|
log = logging.getLogger('main')
|
2016-11-06 15:00:15 -08:00
|
|
|
|
2015-11-01 18:03:11 -08:00
|
|
|
" parse command line args "
|
2016-11-06 15:00:15 -08:00
|
|
|
parser = ArgumentParser(description="Run pyircbot")
|
|
|
|
parser.add_argument("-c", "--config", help="Path to config file", required=True)
|
|
|
|
parser.add_argument("--debug", action="store_true", help="Dump raw irc network")
|
2017-05-01 08:29:20 -07:00
|
|
|
parser.add_argument("-q", "--quit-message", help="Quit message if killed by signal",
|
|
|
|
default="received signal {}")
|
2016-11-06 15:00:15 -08:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.debug:
|
|
|
|
logging.getLogger().setLevel(logging.DEBUG)
|
|
|
|
log.debug(args)
|
|
|
|
|
|
|
|
if not args.config:
|
2015-11-01 18:03:11 -08:00
|
|
|
log.critical("No bot config file specified (-c). Exiting.")
|
2017-05-01 08:29:20 -07:00
|
|
|
sys.exit(1)
|
2016-11-06 15:00:15 -08:00
|
|
|
|
2017-11-27 18:58:20 -08:00
|
|
|
botconfig = loads(sys.stdin.read()) if args.config == "-" else load(args.config)
|
2016-11-06 15:00:15 -08:00
|
|
|
|
2015-11-01 18:03:11 -08:00
|
|
|
log.debug(botconfig)
|
2016-11-06 15:00:15 -08:00
|
|
|
|
2015-11-01 18:03:11 -08:00
|
|
|
bot = PyIRCBot(botconfig)
|
2017-03-27 22:57:03 -07:00
|
|
|
|
|
|
|
def signal_handler(signum, stack):
|
|
|
|
print('Received:', signum)
|
2017-05-01 08:29:20 -07:00
|
|
|
bot.kill(message=args.quit_message.format(signum))
|
2017-03-27 22:57:03 -07:00
|
|
|
|
|
|
|
signal.signal(signal.SIGINT, signal_handler)
|
|
|
|
signal.signal(signal.SIGTERM, signal_handler)
|
|
|
|
|
|
|
|
bot.run()
|