summaryrefslogtreecommitdiff
path: root/IrcConnection.py
diff options
context:
space:
mode:
Diffstat (limited to 'IrcConnection.py')
-rw-r--r--IrcConnection.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/IrcConnection.py b/IrcConnection.py
index 08240fe..22d7cd7 100644
--- a/IrcConnection.py
+++ b/IrcConnection.py
@@ -13,18 +13,22 @@ class ircConnectThread(QThread):
quit_sig = pyqtSignal(str, str)
kick_sig = pyqtSignal(str, str, str, str)
user_mode_sig = pyqtSignal(str, str, str, str)
+ error_sig = pyqtSignal(str, str)
+ status_sig = pyqtSignal(str)
def __init__(self, handler):
QThread.__init__(self)
self.reactor = irc.client.Reactor()
self.server = self.reactor.server()
self.handler = handler
+
def __del__(self):
self.wait()
def run(self):
try:
self.c = self.server.connect("irc.blatech.net", 6667, self.handler.get_nick())
+ self.c.connection_complete = False
except irc.client.ServerConnectionError:
print(sys.exc_info()[1])
raise SystemExit(1)
@@ -46,12 +50,35 @@ class ircConnectThread(QThread):
self.c.add_global_handler("topicinfo", self.on_topic)
self.c.add_global_handler("nick", self.on_nick)
self.c.add_global_handler("motd", self.on_motd)
+ self.c.add_global_handler("motdstart", self.on_motd)
+ self.c.add_global_handler("nicknameinuse", self.on_nicknameinuse)
+ self.c.add_global_handler("welcome", self.on_connectmsg)
+ self.c.add_global_handler("yourhost", self.on_connectmsg)
+ self.c.add_global_handler("created", self.on_connectmsg)
+ self.c.add_global_handler("myinfo", self.on_connectmsg)
+ self.c.add_global_handler("featurelist", self.on_connectmsg)
+ self.c.add_global_handler("luserconns", self.on_connectmsg)
+ self.c.add_global_handler("luserclient", self.on_connectmsg)
+ self.c.add_global_handler("luserop", self.on_connectmsg)
+ self.c.add_global_handler("luserunknown", self.on_connectmsg)
+ self.c.add_global_handler("luserchannels", self.on_connectmsg)
+ self.c.add_global_handler("luserme", self.on_connectmsg)
self.reactor.process_forever()
def on_connect(self, connection, event):
+ print("connected")
+ self.c.connection_complete = True
if irc.client.is_channel("#wtest"):
# self.join_sig.emit("#wtest")
return
+
+ def on_connectmsg(self, connection, event):
+ print(event)
+ status_msg = "* "
+ for status in event.arguments:
+ status_msg = status_msg + status + " "
+ self.status_sig.emit(status_msg)
+
def on_pubmsg(self, connection, event):
print(event)
self.sig.emit(event.target, event.source.split("!")[0], event.arguments[0])
@@ -109,7 +136,19 @@ class ircConnectThread(QThread):
print(event)
def on_motd(self, connection, event):
+ self.status_sig.emit(event.arguments[0])
+ print(event)
+
+ def on_nicknameinuse(self, connection, event):
print(event)
+ if (self.c.connection_complete):
+ self.error_sig.emit("Nick '" + event.arguments[0] + "' is already in use", "")
+ self.handler.set_nick(event.target)
+ else:
+ self.error_sig.emit("Nick '" + event.arguments[0] + "' is already in use, changing to " + connection.get_nickname() + "_", "")
+ self.handler.set_nick(connection.get_nickname() + "_")
+ connection.nick(connection.get_nickname() + "_")
+
@pyqtSlot(str, str)
def send_msg(self, channel, message):
@@ -120,6 +159,13 @@ class ircConnectThread(QThread):
print(message)
@pyqtSlot(str)
+ def change_nick(self, new_nick):
+ self.handler.set_nick(new_nick)
+ self.c.nick(new_nick)
+ #TODO: handle errors such as invalid/passworded channel
+ return True
+
+ @pyqtSlot(str)
def join_channel(self, channel):
print(channel)
self.c.join(channel)