diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2003-12-02 20:51:55 +0000 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2011-08-21 15:53:50 +0200 |
commit | ee15d17a91d010c8c128f4ae4bd8bda6dbb87a67 (patch) | |
tree | 8d451325caa062e09b5144d0d911a8f261f1b350 | |
parent | 950137bab9d0d36ac5156317f56e8643d2ecb280 (diff) | |
download | miniircd-ee15d17a91d010c8c128f4ae4bd8bda6dbb87a67.tar.gz miniircd-ee15d17a91d010c8c128f4ae4bd8bda6dbb87a67.zip |
Make handler functions for commands
Broke a big if/elif/.../elfi/else chunk into functions.
-rwxr-xr-x | miniircd | 54 |
1 files changed, 41 insertions, 13 deletions
@@ -211,8 +211,7 @@ class Client(object): self.__handleCommand = self.__commandHandler def __commandHandler(self, command, arguments): - server = self.__server - if command == "JOIN": + def joinHandler(): if len(arguments) < 1: self.message( ":%s 461 %s JOIN :Not enough parameters" % ( @@ -270,7 +269,8 @@ class Client(object): server.name, self.nickname, channelname)) - elif command == "LIST": + + def listHandler(): if len(arguments) < 1: channels = server.channels else: @@ -289,7 +289,8 @@ class Client(object): channel.topic)) self.message( ":%s 323 %s :End of LIST" % (server.name, self.nickname)) - elif command == "MODE": + + def modeHandler(): if len(arguments) < 1: self.message( ":%s 461 %s MODE :Not enough parameters" % ( @@ -325,7 +326,8 @@ class Client(object): server.name, self.nickname, targetname)) - elif command == "NICK": + + def nickHandler(): if len(arguments) < 1: self.message( ":%s 431 :No nickname given" % server.name) @@ -356,8 +358,9 @@ class Client(object): self.user, self.host, self.nickname), + True) - elif command in ("NOTICE", "PRIVMSG"): + def noticeAndPrivmsgHandler(): if len(arguments) == 0: self.message(":%s 411 %s :No recipient given" % ( server.name, @@ -391,7 +394,8 @@ class Client(object): server.name, self.nickname, targetname)) - elif command == "PART": + + def partHandler(): if len(arguments) < 1: self.message( ":%s 461 %s PART :Not enough parameters" % ( @@ -426,7 +430,8 @@ class Client(object): True) del self.__channels[irc_lower(channelname)] server.removeMemberFromChannel(self, channelname) - elif command == "PING": + + def pingHandler(): if len(arguments) < 1: self.message( ":%s 409 %s :No origin specified" % ( @@ -438,15 +443,18 @@ class Client(object): server.name, server.name, arguments[0])) - elif command == "PONG": + + def pongHandler(): pass - elif command == "QUIT": + + def quitHandler(): if len(arguments) < 1: quitmsg = self.nickname else: quitmsg = arguments[0] self.disconnect(quitmsg) - elif command == "TOPIC": + + def topicHandler(): if len(arguments) < 1: self.message( ":%s 461 %s TOPIC :Not enough parameters" % ( @@ -485,7 +493,8 @@ class Client(object): ":%s 442 %s :You're not on that channel" % ( server.name, channelname)) - elif command == "WHO": + + def whoHandler(): if len(arguments) < 1: pass else: @@ -508,12 +517,31 @@ class Client(object): server.name, self.nickname, targetname)) - else: + + handlerTable = { + "JOIN": joinHandler, + "LIST": listHandler, + "MODE": modeHandler, + "NICK": nickHandler, + "NOTICE": noticeAndPrivmsgHandler, + "PART": partHandler, + "PING": pingHandler, + "PONG": pongHandler, + "PRIVMSG": noticeAndPrivmsgHandler, + "QUIT": quitHandler, + "TOPIC": topicHandler, + "WHO": whoHandler, + } + server = self.__server + try: + handlerTable[command]() + except KeyError: self.message(":%s 421 %s %s :Unknown command" % ( server.name, self.nickname, command)) + def socketReadableNotification(self): try: data = self.socket.recv(2**10) |