-
-
Save anfedorov/e7e13f074a2691de6371 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
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