From 1bcb115b38f97c792aa96aebef8c145fa521f427 Mon Sep 17 00:00:00 2001
From: "Eric S. Raymond" <esr@thyrsus.com>
Date: Sun, 26 Aug 2012 22:07:07 -0400
Subject: [PATCH] Comment fixes.

---
 irker.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/irker.py b/irker.py
index da0c9ca..f02b1d7 100755
--- a/irker.py
+++ b/irker.py
@@ -11,8 +11,7 @@ join/leave traffic.
 
 Requires Python 2.6.
 
-TO-DO: Is there any way to cope is servers drop connections?
-TO-DO: Multiple irkers could try to use the same nick
+TO-DO: Is there any way to cope if servers drop connections?
 TO-DO: Register the port?
 """
 # These things might need tuning
@@ -26,8 +25,9 @@ NAMESTYLE = "irker%03d"	# IRC nick template - must contain '%d'
 
 # No user-serviceable parts below this line
 
-import os, sys, json, irclib, exceptions, getopt, urlparse, time
+import os, sys, json, exceptions, getopt, urlparse, time, socket
 import threading, Queue, SocketServer
+import irclib
 
 class SessionException(exceptions.Exception):
     def __init__(self, message):
@@ -104,6 +104,7 @@ class Irker:
         self.sessions = {}
         self.countmap = {}
         self.servercount = 0
+        self.hostname = socket.getfqdn()
     def logerr(self, errmsg):
         "Log a processing error."
         sys.stderr.write("irker: " + errmsg + "\n")
@@ -111,6 +112,12 @@ class Irker:
         "Debugging information."
         if self.debuglevel >= level:
             sys.stderr.write("irker[%d]: %s\n" % (self.debuglevel, errmsg))
+    def nickname(self, n):
+        "Return a name for the nth server connection."
+        # The purpose of including the FQDN is to ensure that the nicks
+        # of bots managed by instances running on different hosts can
+        # never collide.
+        return (NAMESTYLE % n) + "-" + self.hostname.replace(".", "-")
     def open(self, servername, port):
         "Allocate a new server instance."
         if not (servername, port) in self.countmap:
@@ -121,7 +128,7 @@ class Irker:
             newserver = self.irc.server()
             newserver.connect(servername,
                               port,
-                              NAMESTYLE % self.servercount)
+                              self.nickname(self.servercount))
             self.countmap[(servername, port)] = (1, newserver)
         return self.countmap[(servername, port)][1]
     def close(self, servername, port):
-- 
2.26.2