Skip to content

@anfedorov /irc.py secret

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.