Commits

Mike Steder  committed 086f5a5

Added first cut of NAMES

  • Participants
  • Parent commits 84b4e24

Comments (0)

Files changed (1)

File noir/commands.py

 # NAMES
 @registerCommand("NAMES")
 def names(db, po, userId, message):
-    return []
-
+    data = {"serverName":db.serverName,
+            "replyCode":irc.RPL_NAMREPLY,
+            "channel":None,
+            "nicks":None}
+    namesReply = "%(serverName)s %(replyCode)s %(channel)s :%(nicks)s"
+    endNamesReply = "%(serverName)s %(replyCode)s %(channel)s :End of /NAMES list"
+    if message.parameters:
+        channelName = message.parameters[0].upper()
+        channel = db.channelByName[channelName]
+        data["channel"] = channelName
+        users = [db.getUser(u) for u in channel.users]
+        nicks = [u.nick for u in users]
+        data["nicks"] = " ".join(nicks)
+        po.send([userId], namesReply % (data))
+        po.send([userId], endNamesReply % (data))
+    else:
+        for channelName, channel in db.channelByName.iteritems():
+            data["channel"] = channelName
+            users = [db.getUser(u) for u in channel.users]
+            nicks = [u.nick for u in users]
+            data["nicks"] = " ".join(nicks)
+            po.send([userId], namesReply % (data))
+        po.send([userId], endNamesReply % (data))
 
 # LIST
 @registerCommand("LIST")