Author | Message | Time |
---|---|---|
Yegg | I have a quick question about this ParseData code. It prints out the stuff like 1005 TALK Yegg "Hello.". It does the USER, WHISPER, all that stuff. I can't figure out what is creating this text, here is the code: [code]def event_user(username): print username+"is currently in the channel." def event_join(username): print username+" has just joined the channel." def event_leave(username): print username+" has just left the channel." def event_recvwhisper(username, message): print "<From: "+username+"> "+message def event_talk(username, message): print "<"+username+"> "+message def event_broadcast(message): print message def event_channel(channel): print "You have joined channel: "+channel def event_flags(args, string_args): pass def event_sendwhisper(username, message): print "<To: "+username+"> "+message def event_channelfull(message): print "That channel is full." def event_channelnotexist(message): print "That channel does not exist." def event_channelrestricted(message): print "That channel is restricted." def event_info(message): print message def event_error(message): print message def event_emote(username, message): print "<"+username+" "+message+">" def event_name(username): pass def event_unknown(error): print error event_handlers = { 1001: event_user, 1002: event_join, 1003: event_leave, 1004: event_recvwhisper, 1005: event_talk, 1006: event_broadcast, 1007: event_channel, 1009: event_flags, 1010: event_sendwhisper, 1013: event_channelfull, 1014: event_channelnotexist, 1015: event_channelrestricted, 1016: event_info, 1018: event_info, 1019: event_error, 1023: event_emote, 2010: event_name, 3000: event_info, } def handle_event(d): try: if d.find('"') > -1: string_arg = d[d.find('"')+1:d.rfind('"')] else: string_arg = "" args = d.split(" ") event_handlers[int(args[0])](args, string_arg) except: event_unknown(d) try: parse_data = lambda d: map(handle_event, d.split("\r\n")) except: print traceback.print_exc()[/code] I tried doing print "4fghfddf" under parse_data = lambda d: map(handle_event, d.split("\r\n")) and event_handlers[int(args[0])](args, string_arg) but nothing seems to happen. The bot has, [code]while True: parse_data(s.recv(1024))[/code] in the code, I know this is what brings up the messages but it takes it to parse_data, then where does it go? Also, I can't figure out how to get rid of the 1005 WHISPER Yegg "test......." kind of stuff. The bot doesn't seem to get to event_handlers. Thanks. | January 19, 2005, 9:22 PM |