import socket import urllib2 import httplib import mechanize channel = '#testbot' botnick = 'tastybot' network = 'irc.freenode.net' port = 6667 irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM ) irc.connect ( ( network, port ) ) print irc.recv ( 4096 ) irc.send ( 'NICK' + botnick + ':\r\n' ) irc.send ( 'USER tastybot tastybot tastybot :Python IRC\r\n' ) irc.send ( 'JOIN' + channel + ':\r\n' ) irc.send ( 'PRIVMSG' + channel + ':What's up?\r\n' ) running = True # def Bored(): # UrlDict = {'1':'http://www.notdoppler.com/', '2':'http://thereifixedit.failblog.org/',} # print UrlDict # irc.send ('PRIVMSG' + channel + RandomBored + '\r' ) def WikiFact(): host = 'en.wikipedia.org/wiki' #Setting the site I want to go to random = '/Special:Random' url = 'http://' + host + random httplib.HTTPConnection.debuglevel = 1 # found this on stackoverflow. request = mechanize.Request(url, headers={'User-Agent': 'Windows NT 7.1'}) response = mechanize.urlopen(request) ResultUrl = response.geturl() irc.send ('PRIVMSG' + ResultUrl + 'Here, learn something!') # def Dice(): # random_number = random.randint(1, 6) # if data.find ( '!roll a dice' ) != -1: # irc.send ( 'PRIVMSG' + channel + ':The roll is ' + random_number + '!\r') while running: data = irc.recv ( 4096 ) if data.find ( 'PING' ) != -1: irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' ) if data.find ( '!' + botnick + 'quit' ) != -1: if data.find ( 'reallyrose' ) != -1: irc.send ( 'PRIVMSG' + channel + ':Fine, if you don\'t want me. ;_;\r\n' ) irc.send ( 'QUIT\r\n' ) running = False else: irc.send ( 'PRIVMSG' + channel + ':Only reallyrose can tell me to do that.\r\n' ) if data.find ( 'hi ' + botnick) != -1: irc.send ( 'PRIVMSG' + channel + ':I already said hi...\r\n' ) if data.find ( 'hello ' + botnick) != -1: irc.send ( 'PRIVMSG' + channel + ':I already said hi...\r\n' ) if data.find ( 'KICK' ) != -1: irc.send ( 'JOIN' + channel + '\r\n' ) if data.find ( 'cheese' ) != -1: irc.send ( 'PRIVMSG' + channel + ':OMG WHERE?!?!\r' ) if data.find ( 'slaps ' + botnick ) != -1: irc.send ( 'PRIVMSG' + channel + ':Hey! That\'s mean. Why would you do that? ;_;\r\n' ) # if data.find ( 'PRIVMSG' + channel + ':!roll a dice' ) != -1: Dice() if data.find ( 'PRIVMSG' + channel + ':!kittenbot teach' ) != -1: WikiFact()