Created
July 4, 2012 16:51
-
-
Save hellais/3048298 to your computer and use it in GitHub Desktop.
gunnerbot
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
import re | |
import random | |
from twisted.words.protocols import irc | |
from twisted.internet import protocol | |
gunner_words = ['BOOM, love ya!', 'Love it!', | |
'Does anybody have any ah-has they would like to share', | |
'Close your laptops'] | |
class GunnerBot(irc.IRCClient): | |
def _get_nickname(self): | |
return self.factory.nickname | |
nickname = property(_get_nickname) | |
def signedOn(self): | |
self.join(self.factory.channel) | |
print "Signed on as %s." % (self.nickname,) | |
def joined(self, channel): | |
print "Joined %s." % (channel,) | |
def privmsg(self, user, channel, msg): | |
if self.nickname in msg: | |
prefix = "%s: " % (user.split('!', 1)[0], ) | |
phrase = random.choice(gunner_words) | |
self.msg(self.factory.channel, prefix + phrase) | |
print "Saying %s" % phrase | |
class GunnerBotFactory(protocol.ClientFactory): | |
protocol = GunnerBot | |
def __init__(self, channel, nickname='gunnerbot'): | |
self.channel = channel | |
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,) | |
import sys | |
from twisted.internet import reactor | |
if __name__ == "__main__": | |
reactor.connectTCP('irc.oftc.net', 6667, GunnerBotFactory('#nottor')) | |
reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment