mirror of
https://github.com/jlu5/PyLink.git
synced 2025-02-02 23:54:08 +01:00
make Irc.connected a threaded event object, setting it to True ONLY when we receive server capabilities from our uplink
The previous behavior set this to True as soon as we ran connect(), but this caused problems because the default capabilities (i.e. nicklen) that Irc() initializes won't match the real value of the network.
This commit is contained in:
parent
8d914720b3
commit
6e37e1c05d
8
main.py
8
main.py
@ -16,7 +16,7 @@ import utils
|
||||
class Irc():
|
||||
def __init__(self, netname, proto, conf):
|
||||
# Initialize some variables
|
||||
self.connected = False
|
||||
self.connected = threading.Event()
|
||||
self.name = netname.lower()
|
||||
self.conf = conf
|
||||
# Server, channel, and user indexes to be populated by our protocol module
|
||||
@ -62,11 +62,10 @@ class Irc():
|
||||
log.error('(%s) Failed to connect to IRC: %s: %s',
|
||||
self.name, type(e).__name__, str(e))
|
||||
self.disconnect()
|
||||
self.connected = True
|
||||
self.run()
|
||||
|
||||
def disconnect(self):
|
||||
self.connected = False
|
||||
self.connected.clear()
|
||||
self.socket.close()
|
||||
autoconnect = self.serverdata.get('autoconnect')
|
||||
if autoconnect is not None and autoconnect >= 0:
|
||||
@ -77,7 +76,7 @@ class Irc():
|
||||
def run(self):
|
||||
buf = ""
|
||||
data = ""
|
||||
while self.connected:
|
||||
while True:
|
||||
try:
|
||||
data = self.socket.recv(2048).decode("utf-8")
|
||||
buf += data
|
||||
@ -91,6 +90,7 @@ class Irc():
|
||||
log.error('(%s) Disconnected from IRC: %s: %s',
|
||||
self.name, type(e).__name__, str(e))
|
||||
self.disconnect()
|
||||
break
|
||||
|
||||
def send(self, data):
|
||||
# Safeguard against newlines in input!! Otherwise, each line gets
|
||||
|
@ -540,6 +540,8 @@ def handle_events(irc, data):
|
||||
irc.umodes['*A'], irc.umodes['*B'], irc.umodes['*C'], irc.umodes['*D'] \
|
||||
= caps['USERMODES'].split(',')
|
||||
irc.prefixmodes = re.search(r'\((.*?)\)', caps['PREFIX']).group(1)
|
||||
# Sanity check: set this AFTER we fetch the capabilities for the network!
|
||||
irc.connected.set()
|
||||
try:
|
||||
real_args = []
|
||||
for arg in args:
|
||||
|
Loading…
Reference in New Issue
Block a user