Skip to content

Instantly share code, notes, and snippets.

@EntityReborn
Created April 10, 2011 03:31
Show Gist options
  • Save EntityReborn/912021 to your computer and use it in GitHub Desktop.
Save EntityReborn/912021 to your computer and use it in GitHub Desktop.
from twisted.application import internet, service
from twisted.words.protocols import irc
from twisted.internet import protocol
class Bot(irc.IRCClient):
nickname = "SocPuppet"
def connectionMade(self):
irc.IRCClient.connectionMade(self)
print "Connected"
def connectionLost(self, reason):
irc.IRCClient.connectionLost(self, reason)
print "Disconnected"
def signedOn(self):
"""Called when bot has succesfully signed on to server."""
self.join(self.factory.channel)
def joined(self, channel):
"""This will get called when the bot joins the channel."""
print "I have joined %s" % channel
class BotFactory(protocol.ClientFactory):
"""A factory for LogBots.
A new protocol instance will be created each time we connect to the server.
"""
# the class of the protocol to build when new connection is made
protocol = LogBot
def __init__(self, channel):
self.channel = channel
def clientConnectionLost(self, connector, reason):
"""If we get disconnected, reconnect to server."""
connector.connect()
def clientConnectionFailed(self, connector, reason):
print "connection failed:", reason
reactor.stop()
f = BotFactory("##socialites-bots")
# this is the important bit
application = service.Application("socbot") # create the Application
botService = internet.TCPClient("irc.freenode.net", 6667, f) # create the service
# add the service to the application
botService.setServiceParent(application)
botService.startService()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment