import supybot.utils as utils from supybot.commands import * import supybot.plugins as plugins import supybot.ircutils as ircutils import supybot.callbacks as callbacks import random, re, time, commands, urllib2 import supybot.ircmsgs as ircmsgs _bofhfile = '/home/dennis/ubugtu/plugins/Mess/bofh.txt' _bofhdata = [x.strip() for x in open(_bofhfile).readlines()] _42file = '/home/dennis/ubugtu/plugins/Mess/42.txt' _42data = [x.strip() for x in open(_42file).readlines()] _ballfile = '/home/dennis/ubugtu/plugins/Mess/ball.txt' _balldata = [x.strip() for x in open(_ballfile).readlines()] class Mess(callbacks.PluginRegexp): """Random Mess plugin""" threaded = True regexps = ['hugme','r42','ball'] hugs = ["hugs %s","gives %s a big hug","gives %s a sloppy wet kiss", "huggles %s","squeezes %s","humps %s"] regex = re.compile('.*?
(.*?)
', re.DOTALL) entre = re.compile('&(\S*?);') jre1 = ('http://www.jackbauerfacts.com/index.php?rate_twenty_four', re.compile('current-rating.*?width.*?(.*?)
')) badwords = ['sex','masturbate','fuck','rape','dick','pussy','prostitute','hooker', 'orgasm','sperm','cunt','penis','shit','piss','urin','bitch','semen'] i = 0 time = {} # WARNING: depends on an alteration in supybot/callbacks.py - don't do # str(s) if s is unicode! def dice(self, irc, msg, args, count): if not self.ok(msg.args[0]): return if not count: count = 1 if count > 5: count = 5 if count < 1: count = 1 t = u' '.join([x.__call__([u"\u2680",u"\u2681",u"\u2682",u"\u2683",u"\u2684",u"\u2685"]) for x in [random.choice]*count]) irc.reply(t) dice = wrap(dice, [additional('int')]) def hugme(self, irc, msg, match): r""".*hug.*ubugtu""" irc.queueMsg(ircmsgs.action(msg.args[0], self.hugs[random.randint(0,len(self.hugs)-1)] % msg.nick)) def ok(self, channel, offensive = False): if not channel.startswith('#'): delay = 5 else: if not self.registryValue('enabled', channel): return False if offensive and not self.registryValue('offensive', channel): return False delay = self.registryValue('delay', channel) if channel not in self.time.keys(): self.time[channel] = time.time() return True if self.time[channel] < time.time() - delay: self.time[channel] = time.time() return True return False def fact(self,who,count=0): # The website is buggy, mysql errors rear their ugly head a lot. So we # retry up to 5 times :) if count > 5: return try: fact = utils.web.getUrl('http://4q.cc/index.php?pid=fact&person=%s' % who) reo = self.regex.search(fact) val = reo.group(1) while self.entre.search(val): entity = self.entre.search(val).group(1) if entity in entities: val = self.entre.sub(entities[entity], val) else: val = self.entre.sub('?', val) _val = val.lower() for word in self.badwords: if word in _val: raise RuntimeError return val except: time.sleep(1) return self.fact(who,count+1) def t(self, irc, msg, args): """ Display a mr T. fact """ if not self.ok(msg.args[0]): return f = self.fact('mrt') if f: irc.reply(f) t = wrap(t) def chuck(self, irc, msg, args): """ Display a Chuck Norris fact """ if not self.ok(msg.args[0]): return f = self.fact('chuck') if f: irc.reply(f) chuck = wrap(chuck) def vin(self, irc, msg, args): """ Display a Vin Diesel fact """ if not self.ok(msg.args[0]): return f = self.fact('vin') if f: irc.reply(f) vin = wrap(vin) hre = re.compile('')+3:data.find('
')].strip()) yourmom = wrap(yourmom) def bush(self, irc,msg,args): """Yes, bush needs help....""" if not self.ok(msg.args[0], True): return data = utils.web.getUrl('http://www.dubyaspeak.com/random.phtml') data = data[data.find('')+1:] irc.reply(data.replace("\n",'')) bush = wrap(bush) def _bauer(self,count=0): # if self.i % 2 == 0: # (url, re) = self.jre1 # else: # (url, re) = self.jre2 # self.i += 1 (url, re) = self.jre2 if count > 5: return try: fact = utils.web.getUrl(url) reo = re.search(fact) val = reo.group(1) while self.entre.search(val): entity = self.entre.search(val).group(1) if entity in entities: val = self.entre.sub(entities[entity], val) else: val = self.entre.sub('?', val) _val = val.lower() for word in self.badwords: if word in _val: raise RuntimeError return val except: time.sleep(1) return self._bauer(count+1) Class = Mess