<commit_before># -*- coding: utf-8 -*-

import os
import re
import time
import datetime
import json
import logging
import socket
import select
import functools

import dateutil.parser
import irc.bot
import irc.client
import irc.modes

from common import utils
from common.config import config
from lrrbot import chatlog, storage, twitch


log = logging.getLogger('lrrbot')

SELF_METADATA = {'specialuser': {'mod', 'subscriber'}, 'usercolor': '#FF0000', 'emoteset': {317}}

class LRRBot(irc.bot.SingleServerIRCBot):
	GAME_CHECK_INTERVAL = 5*60 # Only check the current game at most once every five minutes

	def __init__(self):
		server = irc.bot.ServerSpec(
			host=config['hostname'],
			port=config['port'],
			password="<PASSWORD>" % storage.data['twitch_oauth'][config['username']] if config['password'] == "<PASSWORD>" else config['password'],
		)
		super(LRRBot, self).__init__(
			server_list=[server],
			realname=config['username'],
			nickname=config['username'],
			reconnection_interval=config['reconnecttime'],
		)

		# Send a keep-alive message every minute, to catch network dropouts
		# self.connection has a set_keepalive method, but it crashes
		# if it triggers while the connection is down, so do this instead
		self.reactor.execute_every(period=config['keepalivetime'], function=self.do_keepalive)

		self.reactor.execute_every(period=5, function=self.check_polls)
		self.reactor.execute_every(period=5, function=self.vote_respond)
		self.reactor.execute_every(period=config['checksubstime'], function=self.check_subscriber_list)

		# IRC event handlers
		self.reactor.add_global_handler('welcome', self.on_connect)
		self.reactor.add_global_handler('join', self.on_channel_join)
		self.reactor.add_global_handler('pubmsg', self.on_message)
		self.reactor.add_global_handler('privmsg', self.on_message)
		self.reactor.add_global_handler('action', self.on_message_action)
		self.reactor.add_global_handler('mode', self.on_mode)

		# Commands
		self.commands = {}
		self.re_botcommand = None
		self.command_groups = {}
		self.server_events = {}

		# Precompile regular expressions
		self.re_subscription = re.compile(r"^(.*) just subscribed!", re.IGNORECASE)

		# Set up bot state
		self.game_override = None
		self.show_override = None
		self.calendar_override = None
		self.vote_update = None
		self.access = "all"
		self.show = ""
		self.polls = []
		self.lastsubs = []
		self.havesublist = False

		self.spam_rules = [(re.compile(i['re']), i['message']) for i in storage.data['spam_rules']]
		self.spammers = {}

		self.mods = set(storage.data.get('mods', config['mods']))
		self.subs = set(storage.data.get('subs', []))

		self.metadata = {}
		self.globalflags = {}

		# Let us run on windows, without the socket
		if hasattr(socket, 'AF_UNIX'):
			# TODO: To be more robust, the code really should have a way to shut this socket down
			# when the bot exits... currently, it's assuming that there'll only be one LRRBot
			# instance, that lasts the life of the program... which is true for now...
			try:
				os.unlink(config['socket_filename'])
			except OSError:
				if os.path.exists(config['socket_filename']):
					raise
			self.event_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
			self.event_socket.bind(config['socket_filename'])
			self.event_socket.listen(5)
			self.event_socket.setblocking(False)
		else:
			self.event_socket = None

	def start(self):
		self._connect()

		# Don't fall over if the server sends something that's not real UTF-8
		for conn in self.reactor.connections:<commit_msg>Delay the creation of the RPC socket<commit_after># -*- coding: utf-8 -*-

import os
import re
import time
import datetime
import json
import logging
import socket
import select
import functools

import dateutil.parser
import irc.bot
import irc.client
import irc.modes

from common import utils
from common.config import config
from lrrbot import chatlog, storage, twitch


log = logging.getLogger('lrrbot')

SELF_METADATA = {'specialuser': {'mod', 'subscriber'}, 'usercolor': '#FF0000', 'emoteset': {317}}

class LRRBot(irc.bot.SingleServerIRCBot):
	GAME_CHECK_INTERVAL = 5*60 # Only check the current game at most once every five minutes

	def __init__(self):
		server = irc.bot.ServerSpec(
			host=config['hostname'],
			port=config['port'],
			password="<PASSWORD>" % storage.data['twitch_oauth'][config['username']] if config['password'] == "oauth" else config['password'],
		)
		super(LRRBot, self).__init__(
			server_list=[server],
			realname=config['username'],
			nickname=config['username'],
			reconnection_interval=config['reconnecttime'],
		)

		# Send a keep-alive message every minute, to catch network dropouts
		# self.connection has a set_keepalive method, but it crashes
		# if it triggers while the connection is down, so do this instead
		self.reactor.execute_every(period=config['keepalivetime'], function=self.do_keepalive)

		self.reactor.execute_every(period=5, function=self.check_polls)
		self.reactor.execute_every(period=5, function=self.vote_respond)
		self.reactor.execute_every(period=config['checksubstime'], function=self.check_subscriber_list)

		# IRC event handlers
		self.reactor.add_global_handler('welcome', self.on_connect)
		self.reactor.add_global_handler('join', self.on_channel_join)
		self.reactor.add_global_handler('pubmsg', self.on_message)
		self.reactor.add_global_handler('privmsg', self.on_message)
		self.reactor.add_global_handler('action', self.on_message_action)
		self.reactor.add_global_handler('mode', self.on_mode)

		# Commands
		self.commands = {}
		self.re_botcommand = None
		self.command_groups = {}
		self.server_events = {}

		# Precompile regular expressions
		self.re_subscription = re.compile(r"^(.*) just subscribed!", re.IGNORECASE)

		# Set up bot state
		self.game_override = None
		self.show_override = None
		self.calendar_override = None
		self.vote_update = None
		self.access = "all"
		self.show = ""
		self.polls = []
		self.lastsubs = []
		self.havesublist = False

		self.spam_rules = [(re.compile(i['re']), i['message']) for i in storage.data['spam_rules']]
		self.spammers = {}

		self.mods = set(storage.data.get('mods', config['mods']))
		self.subs = set(storage.data.get('subs', []))

		self.metadata = {}
		self.globalflags = {}

	def start(self):
		# Let us run on windows, without the socket
		if hasattr(socket, 'AF_UNIX'):
			# TODO: To be more robust, the code really should have a way to shut this socket down
			# when the bot exits... currently, it's assuming that there'll only be one LRRBot
			# instance, that lasts the life of the program... which is true for now...
			try:
				os.unlink(config['socket_filename'])
			except OSError:
				if os.path.exists(config['socket_filename']):
					raise
			self.event_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
			self.event_socket.bind(config['socket_filename'])
			self.event_socket.listen(5)
			self.event_socket.setblocking(False)
		else:
			self.event_socket = None

		self._connect()

		# Don't fall over if the server sends something that's not real UTF-8
		for conn in self.reactor.connections:
{'fraction_non_alphanumeric': 0.12380416432189083, 'fraction_numerical': 0.004220596510973551, 'mean_word_length': 4.728444802578566, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5066957', 'n_tokens_mistral': 2552, 'n_tokens_neox': 2293, 'n_words': 559}