King-Leonidas/irc.py

29 lines
727 B
Python

import sys
import socket
import ssl
import time
import importlib
from bot import Bot
from regexmultimatch import multimatch
class IRC():
def __init__(self, config):
self.config = config
self.bot = Bot({})
def go(self):
s0 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s = ssl.wrap_socket(s0)
s.connect((self.config.server, int(self.config.port)))
f = s.makefile(mode='rw', buffering=1, encoding='utf-8', newline='\r\n')
self.bot.f = f
self.bot.connect(self.config)
for line in f:
try:
multimatch(self.bot.tbl, line.rstrip())
except:
print("Unexpected error:", sys.exc_info())