Skip to content

Instantly share code, notes, and snippets.

@borntyping
Created January 24, 2012 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borntyping/1670373 to your computer and use it in GitHub Desktop.
Save borntyping/1670373 to your computer and use it in GitHub Desktop.
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
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