# Chat Server- Better Way of interpreting commands?

This topic is 2611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am working on a chat program as an introduction to network programming in python, using the asyncore module. It is all working fine, but I want to make my command system better.This is how I handle commands like login,logout,look(see other people in the same chat room),etc.:

 def handle(self, session, line): 'Handle a received line from a given session' if not line.strip(): return # Split off the command: parts = line.split(' ', 1) cmd = parts[0] try: line = parts[1].strip() except IndexError: line = '' # Try to find a handler: meth = getattr(self, 'do_'+cmd, None) try: # Assume it's callable: meth(session, line) except TypeError: # If it isn't, respond to the unknown command: self.unknown(session, cmd)

It works fine if you use it the right way, but I want to make it more user-friendly by changing the way it works a bit. First off, whenever you want to send a message, you have to type "say " first, while most users would be accustomed to just typing something in and expecting the client to show it. I want to prefix all the commands with a "/" so when the user types in "/login heromal" they will login with the name heromal. Everything that isn't a command will be treated as general chatting(thereby eliminating the need for a say command, since you will say everything that isn't a command). How do most chat programs go about interpreting chat commands?
Here is the full code(about 200 lines so far):http://pastebin.com/0yjk666A

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633691
• Total Posts
3013341
×