secret
Created

  • Download Gist
irc.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
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()
# ...

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.