Defines registry of commands this IRC server handles.
+Numeric reply codes are supposed to be sent back as:
+:this.server.net 421 <nick>
newnick = message.parameters
if newnick not in db.nicks:
+ db.nickToUserId[newnick] = userId
po.send([userId], ":%s NICK %s"%(user["nick"], user["nick"]))
def privMsg(db, po, userId, message):
+ target = message.parameters
+ text = " ".join(message.parameters[1:])
+ if target.startswith("#"):
+ targetId = db.channelNameToId[target]
+ targetId = db.nickToUserId[target]
+ po.send([targetId], "PRIVMSG %s %s"%(target, text)
+ po.send([userId], irc.ERR_UNKNOWNCOMMAND)
+def ping(db, po, userId, message):
+ """Servers aren't supposed to respond to PINGs, but
+ it would be reasonable to update any idle connection
+ timeout whenever you receive a ping from a client"""
+ user = db.getUser(userId)
+ # say we had a 5m (300s) timeout
+ # we'd reset it when we got a ping from the user
+ # that indicates their connection is still alive
+def pong(db, po, userId, message):
+ """Again, seems like we can probably ignore these.
+ The RFC suggests that we should forward PONG messages
+ to the 'daemon(s)' specified in the first and second
+"""Error commands are specialized notifications that need to be
+forwarded to operators on this server. They seem to be used
+to propagate error messages between servers.
+Probably not important to us at this time.