Skip to content

Instantly share code, notes, and snippets.

@Rembane
Created June 26, 2012 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rembane/2995897 to your computer and use it in GitHub Desktop.
Save Rembane/2995897 to your computer and use it in GitHub Desktop.
A bot built in Python on top of Twisted when I was drunk.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from random import choice, randint
from time import sleep
from twisted.words.protocols import irc
from twisted.internet import protocol, reactor
import sys
memory = []
class DrunkenBot(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,)
sleep(3)
self.say('#luder', 'Hurrrrr....')
def privmsg(self, user, channel, msg):
if 'dump' in msg:
fh = open('memory.txt', 'w')
fh.write('\n'.join(map(strip, memory)))
fh.close()
else:
memory.append(msg)
if len(memory) > 0 and (self.nickname in msg or randint(1,10) > 9):
sleep(randint(1,5))
self.say('#luder', choice(memory))
print msg
class DrunkenBotFactory(protocol.ClientFactory):
protocol = DrunkenBot
def __init__(self, channel, nickname='DrunkBot'):
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,)
if __name__ == "__main__":
fh = open('memory.txt', 'r')
memory = list(set(fh.readlines()))
fh.close()
chan = '#luder' #sys.argv[1]
reactor.connectTCP('irc.underworld.no', 6667, DrunkenBotFactory(chan))
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment