From 8dfd0f07cc7c65672832a32e5ac32f71c0405ede Mon Sep 17 00:00:00 2001 From: nemunaire Date: Sun, 2 Nov 2014 18:31:53 +0100 Subject: [PATCH] IRC server: differentiate nick and username --- prompt/builtins.py | 2 +- server/IRC.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/prompt/builtins.py b/prompt/builtins.py index b653694..2af2e18 100644 --- a/prompt/builtins.py +++ b/prompt/builtins.py @@ -78,7 +78,7 @@ def load_file(filename, context): } # Optional keyword arguments - for optional_opt in [ "port", "realname", "password", "encoding", "caps" ]: + for optional_opt in [ "port", "username", "realname", "password", "encoding", "caps" ]: if server.hasAttribute(optional_opt): opts[optional_opt] = server[optional_opt] elif optional_opt in config: diff --git a/server/IRC.py b/server/IRC.py index 2693a48..9700a23 100644 --- a/server/IRC.py +++ b/server/IRC.py @@ -31,7 +31,7 @@ import tools class IRC(SocketServer): def __init__(self, owner, nick="nemubot", host="localhost", port=6667, - ssl=False, password=None, realname="Nemubot", + ssl=False, username=None, password=None, realname="Nemubot", encoding="utf-8", caps=None, channels=list(), on_connect=None): """Prepare a connection with an IRC server @@ -42,6 +42,7 @@ class IRC(SocketServer): host -- host to join port -- port on the host to reach ssl -- is this server using a TLS socket + username -- the username as sent to server password -- if a password is required to connect to the server realname -- the bot's realname encoding -- the encoding used on the whole server @@ -50,15 +51,16 @@ class IRC(SocketServer): on_connect -- generator to call when connection is done """ - self.id = nick + "@" + host + ":" + port - self.printer = IRCPrinter - SocketServer.__init__(self, host=host, port=port, ssl=ssl) - + self.username = username if username is not None else nick self.password = password self.nick = nick self.owner = owner self.realname = realname + self.id = self.username + "@" + host + ":" + port + self.printer = IRCPrinter + SocketServer.__init__(self, host=host, port=port, ssl=ssl) + self.encoding = encoding # Keep a list of joined channels @@ -227,7 +229,7 @@ class IRC(SocketServer): if self.capabilities is not None: self.write("CAP LS") self.write("NICK :" + self.nick) - self.write("USER %s %s bla :%s" % (self.nick, self.host, self.realname)) + self.write("USER %s %s bla :%s" % (self.username, self.host, self.realname)) return True return False