from irc import * from time import * import sys, httplib, pycurl, re, random, MultipartPostHandler, urllib2, cookielib class basicCURL: def __init__(self): self.contents = '' def body_callback(self, buf): self.contents = self.contents + buf class mzxbot(IRC): seencheck = 0 seentarget = "" seenargs = "" leftseen = [] departures = [] yahtzee = 0 yplayers = [] dice = [0, 0, 0, 0, 0] keep = [] pnum = 0 rolls = 0 def on_privmsg(self, nick, ident, host, target, msg): if 'CJA' in nick: pass else: if msg.startswith(('.','!')) and target[:1] == '#': msg = msg.lstrip('.!') if msg != "": templist = msg.split() command = templist[0] args = msg.split(command + " ") try: args = args[1] except: args = '' if command == "help": if args == '': self.msg(target, "Current commands are: wiki, mzxwiki, trope, help, version, whotoblame, seen, dict, foldoc, jargon, restart*, quit*, code. Prefix commands with . or ! Commands with an asterisk are privileged only.") elif "whotoblame" in args: self.msg(target, "Syntax: (./!)whotoblame, Purpose: Tells you who made this bot.") elif "version" in args: self.msg(target, "Syntax: (./!)version, Purpose: Gives the current version of the bot.") elif "wiki" in args: self.msg(target, "Syntax: (./!)wiki , Purpose: Looks up the specified string on wikipedia.") elif "mzxwiki" in args: self.msg(target, "Syntax: (./!)mzxwiki , Purpose: Looks up the specified string on MZXWiki.") elif "trope" in args: self.msg(target, "Syntax: (./!)trope , Purpose: Looks up the specified string on TVTropes. Title search only.") elif "seen" in args: self.msg(target, "Syntax: (./!)seen , Purpose: Ask if the bot has seen a nick. It will reply with the last time it saw them quit, part, or nickchange. Or if they're still here, it'll tell you that, and make you feel like an idiot.") elif "dict" in args: self.msg(target, "Syntax: (./!)dict , Purpose: Look up a word in the WordNet dictionary.") elif "foldoc" in args: self.msg(target, "Syntax: (./!)foldoc , Purpose: Look up a term in the Free On-Line Dictionary of Computing") elif "jargon" in args: self.msg(target, "Syntax: (./!)jargon , Purpose: Look up some jargon in the Jargon File") elif "help" in args: self.msg(target, "You're using it, moron.") elif "code" in args: self.msg(target, "Syntax: (./!)code, Purpose: MSGs the nick with the code of the bot.") else: self.msg(target, "I don't appear to have that command implemented/documented!") if command == "restart" and nick.lower() == "insidious": self.msg(target, "Restarting.") sys.exit(0) if command == "quit" and nick.lower() == "insidious": self.msg(target, "Quitting.") sys.exit(1) if command == "code": binit = "" f = open("mzxbot.py") for line in f: binit = binit + line o = basicCURL() c = pycurl.Curl() c.setopt(c.URL, 'http://pastebin.ca/index.php') c.setopt(c.WRITEFUNCTION, o.body_callback) c.setopt(c.HTTPPOST, [("s", "Submit Post"), ("content", binit)]) c.setopt(c.HTTPHEADER, [ "Expect: " ]) c.perform() c.close() try: url = o.contents.split('URL for it is:

')[0] self.msg(target, "http://pastebin.ca" + url) except: self.msg(target, "Unable to pastebin my code for some reason.") if command == "whotoblame": self.msg(target, "I was created by Insidious.") if command == "version": self.msg(target, "MZXBot v1.0"); if command == "wiki": wiki = httplib.HTTPConnection("en.wikipedia.org") wiki.request("GET", "/w/index.php?title=Special%3ASearch&search=" + args.replace(" ", "_") + '&go=Go') response = wiki.getresponse() if response.status == 302: self.msg(target, response.msg['location']) else: message = response.read() if 'Search results' in message: if 'No page text matches' in message and 'No article title matches' in message: self.msg(target, "Can't find anything. Sorry.") else: temp = message.split('