Skip to content

Instantly share code, notes, and snippets.

@anfedorov

anfedorov/irc.py Secret

Created April 22, 2010 01:12
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 anfedorov/e7e13f074a2691de6371 to your computer and use it in GitHub Desktop.
Save anfedorov/e7e13f074a2691de6371 to your computer and use it in GitHub Desktop.
from twisted.words.protocols.irc import IRCClient
from twisted.internet import protocol, reactor
class Connect(object):
class IMBot(IRCClient):
def signedOn(self):
self.connected = True
@property
def nickname(self):
return self.factory.nickname
def privmsg(self, user, channel, msg):
# needs to return from `next' below
class IMBotFactory(protocol.ClientFactory):
protocol = IMBot
def __init__(self, nickname):
self.nickname = nickname
def clientConnectionLost(self, connector, reason):
print "Lost connection (%s), reconnecting." % (reason,)
connector.connect()
def clientConnectionFailed(self, connector, reason):
print "Could not connect: %s" % (reason,)
def __init__(self, host='irc.freenode.net', port=6667, nick='robot'):
self.host = host
self.port = port
self.connector = reactor.connectTCP(host, port, IMBotFactory(nick))
def join(self, *chans):
return Channels(self, *chans)
class Channels(object):
def __init__(self, connection, *chans):
self.connection = connection
self.chans = chans
def __next__(self):
# ...
reactor.run()
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment