Conn now holds its own name.
This commit is contained in:
parent
ffee5bf1ff
commit
f70baa778c
1 changed files with 11 additions and 4 deletions
15
core/irc.py
15
core/irc.py
|
@ -123,8 +123,8 @@ irc_param_ref = re.compile(r'(?:^|(?<= ))(:.*|[^ ]+)').findall
|
||||||
|
|
||||||
class IRC(object):
|
class IRC(object):
|
||||||
"handles the IRC protocol"
|
"handles the IRC protocol"
|
||||||
#see the docs/ folder for more information on the protocol
|
def __init__(self, name, server, nick, port=6667, channels=[], conf={}):
|
||||||
def __init__(self, server, nick, port=6667, channels=[], conf={}):
|
self.name = name
|
||||||
self.channels = channels
|
self.channels = channels
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
self.server = server
|
self.server = server
|
||||||
|
@ -152,12 +152,14 @@ class IRC(object):
|
||||||
|
|
||||||
def parse_loop(self):
|
def parse_loop(self):
|
||||||
while True:
|
while True:
|
||||||
|
# get a message from the input queue
|
||||||
msg = self.conn.iqueue.get()
|
msg = self.conn.iqueue.get()
|
||||||
|
|
||||||
if msg == StopIteration:
|
if msg == StopIteration:
|
||||||
self.connect()
|
self.connect()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# parse the message
|
||||||
if msg.startswith(":"): # has a prefix
|
if msg.startswith(":"): # has a prefix
|
||||||
prefix, command, params = irc_prefix_rem(msg).groups()
|
prefix, command, params = irc_prefix_rem(msg).groups()
|
||||||
else:
|
else:
|
||||||
|
@ -170,8 +172,10 @@ class IRC(object):
|
||||||
if paramlist[-1].startswith(':'):
|
if paramlist[-1].startswith(':'):
|
||||||
paramlist[-1] = paramlist[-1][1:]
|
paramlist[-1] = paramlist[-1][1:]
|
||||||
lastparam = paramlist[-1]
|
lastparam = paramlist[-1]
|
||||||
|
# put the parsed message in the response queue
|
||||||
self.out.put([msg, prefix, command, params, nick, user, host,
|
self.out.put([msg, prefix, command, params, nick, user, host,
|
||||||
mask, paramlist, lastparam])
|
mask, paramlist, lastparam])
|
||||||
|
# if the server pings us, pong them back
|
||||||
if command == "PING":
|
if command == "PING":
|
||||||
self.cmd("PONG", paramlist)
|
self.cmd("PONG", paramlist)
|
||||||
|
|
||||||
|
@ -183,16 +187,19 @@ class IRC(object):
|
||||||
self.cmd("NICK", [nick])
|
self.cmd("NICK", [nick])
|
||||||
|
|
||||||
def join(self, channel):
|
def join(self, channel):
|
||||||
|
""" makes the bot join a channel """
|
||||||
self.cmd("JOIN", [channel])
|
self.cmd("JOIN", [channel])
|
||||||
if channel not in self.channels:
|
if channel not in self.channels:
|
||||||
self.channels.append(channel)
|
self.channels.append(channel)
|
||||||
|
|
||||||
def part(self, channel):
|
def part(self, channel):
|
||||||
|
""" makes the bot leave a channel """
|
||||||
self.cmd("PART", [channel])
|
self.cmd("PART", [channel])
|
||||||
if channel in self.channels:
|
if channel in self.channels:
|
||||||
self.channels.remove(channel)
|
self.channels.remove(channel)
|
||||||
|
|
||||||
def msg(self, target, text):
|
def msg(self, target, text):
|
||||||
|
""" makes the bot send a message to a user """
|
||||||
self.cmd("PRIVMSG", [target, text])
|
self.cmd("PRIVMSG", [target, text])
|
||||||
|
|
||||||
def cmd(self, command, params=None):
|
def cmd(self, command, params=None):
|
||||||
|
@ -207,10 +214,10 @@ class IRC(object):
|
||||||
|
|
||||||
|
|
||||||
class SSLIRC(IRC):
|
class SSLIRC(IRC):
|
||||||
def __init__(self, server, nick, port=6667, channels=[], conf={},
|
def __init__(self, name, server, nick, port=6667, channels=[], conf={},
|
||||||
ignore_certificate_errors=True):
|
ignore_certificate_errors=True):
|
||||||
self.ignore_cert_errors = ignore_certificate_errors
|
self.ignore_cert_errors = ignore_certificate_errors
|
||||||
IRC.__init__(self, server, nick, port, channels, conf)
|
IRC.__init__(self, name, server, nick, port, channels, conf)
|
||||||
|
|
||||||
def create_connection(self):
|
def create_connection(self):
|
||||||
return crlf_ssl_tcp(self.server, self.port, self.ignore_cert_errors)
|
return crlf_ssl_tcp(self.server, self.port, self.ignore_cert_errors)
|
||||||
|
|
Reference in a new issue