예제 #1
0
def main():
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('config_file', type=argparse.FileType('r'))

    args = arg_parser.parse_args()
    config = json.load(args.config_file)

    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(levelname)s - %(name)s - %(message)s',
        handlers=[
            logging.handlers.TimedRotatingFileHandler(config['log_file'],
                                                      when='midnight',
                                                      utc=True),
            logging.StreamHandler(),
        ])

    client = Client()
    client.autoconnect(
        'irc.chat.twitch.tv',
        6697,
        nickname=config['username'],
        password=config['password'],
        connect_factory=irc.connection.Factory(wrapper=ssl.wrap_socket))

    try:
        client.reactor.process_forever()
    except Exception:
        _logger.exception('Fatal error')
        raise
예제 #2
0
파일: betbot.py 프로젝트: chfoo/chatbot383
def main():
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('config_file', type=argparse.FileType('r'))

    args = arg_parser.parse_args()
    config = json.load(args.config_file)

    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(levelname)s - %(name)s - %(message)s',
        handlers=[
            logging.handlers.TimedRotatingFileHandler(config['log_file'], when='midnight', utc=True),
            logging.StreamHandler(),
        ]
    )

    client = Client()
    client.autoconnect(
        'irc.chat.twitch.tv',
        6697,
        nickname=config['username'],
        password=config['password'],
        connect_factory=irc.connection.Factory(wrapper=ssl.wrap_socket)
    )

    try:
        client.reactor.process_forever()
    except Exception:
        _logger.exception('Fatal error')
        raise
예제 #3
0
def main():
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('channels_file')
    arg_parser.add_argument('log_dir')
    arg_parser.add_argument('--host', default='irc.twitch.tv')
    arg_parser.add_argument('--port', type=int, default=6667)
    arg_parser.add_argument('--nickname')
    arg_parser.add_argument('--oauth-file')

    args = arg_parser.parse_args()

    logging.basicConfig(level=logging.INFO)

    if not os.path.isfile(args.channels_file):
        sys.exit('channels file provided is not a file.')

    if not os.path.isdir(args.log_dir):
        sys.exit('log dir provided is not a directory.')

    if args.oauth_file:
        with open(args.oauth_file, 'r') as file:
            password = '******' + file.read().strip()
    else:
        password = None

    _logger.info('Starting IRC client.')

    chat_logger = ChatLogger(args.log_dir)
    client = Client(chat_logger, args.channels_file)
    running = True
    nickname = args.nickname or 'justinfan{}'.format(random.randint(
        0, 9000000))

    def stop(dummy1, dummy2):
        nonlocal running
        running = False

    client.autoconnect(args.host, args.port, nickname, password=password)

    signal.signal(signal.SIGINT, stop)
    signal.signal(signal.SIGTERM, stop)

    while running:
        client.reactor.process_once(0.2)

    client.stop()

    _logger.info('Stopped IRC client.')
예제 #4
0
def main():
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('channels_file')
    arg_parser.add_argument('log_dir')
    arg_parser.add_argument('--host', default='irc.twitch.tv')
    arg_parser.add_argument('--port', type=int, default=6667)
    arg_parser.add_argument('--nickname')
    arg_parser.add_argument('--oauth-file')

    args = arg_parser.parse_args()

    logging.basicConfig(level=logging.INFO)

    if not os.path.isfile(args.channels_file):
        sys.exit('channels file provided is not a file.')

    if not os.path.isdir(args.log_dir):
        sys.exit('log dir provided is not a directory.')

    if args.oauth_file:
        with open(args.oauth_file, 'r') as file:
            password = '******' + file.read().strip()
    else:
        password = None

    _logger.info('Starting IRC client.')

    chat_logger = ChatLogger(args.log_dir)
    client = Client(chat_logger, args.channels_file)
    running = True
    nickname = args.nickname or 'justinfan{}'.format(random.randint(0, 9000000))

    def stop(dummy1, dummy2):
        nonlocal running
        running = False
        client.stop()

    client.autoconnect(args.host, args.port, nickname, password=password)

    signal.signal(signal.SIGINT, stop)
    signal.signal(signal.SIGTERM, stop)

    while running:
        client.reactor.process_once(0.2)

    _logger.info('Stopped IRC client.')