Created
January 24, 2012 14:14
-
-
Save borntyping/1670373 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
class Event (object): | |
message = re.compile("^(?::(?P<prefix>\S+) )?(?P<command>\w+|\d\d\d) (?P<params>.+)$") | |
def __new__ (cls, line, **kwargs): | |
message = cls.message.search(line) | |
if message: | |
prefix, command, params = message.groups() | |
print prefix, command, params | |
if command == 'PRIVMSG': | |
return PRIVMSG(prefix, params) | |
return object.__new__(cls, line, **kwargs) | |
else: | |
print "Line is not an irc message" | |
return None | |
def __init__ (self, line): | |
print "Event created from line '{}'".format(line) | |
class Message (): | |
def __init__ (self, prefix, params): | |
print (self.__class__.__name__, prefix, params) | |
class PRIVMSG (Message): | |
pass | |
print Event('Not_a_valid_irc_message') | |
print Event('PRIVMSG #lambda :Blah blah blah') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment