def get_submissions(multi): global multi_reddits start = bot.start_time while multi['list'] and start == bot.start_time: if multi['updated']: multi['sub'] = r.get_subreddit('+'.join(multi['list'])) new_threads = [] try: for thread in multi['sub'].get_new(limit = len(multi['list']) * 5): if thread.created_utc > multi['time']: new_threads.append(thread) multi['time'] = time.time() except: print 'Failed to fetch new posts. %s' % time.strftime("%H:%M:%S") for thread in reversed(new_threads): sub = thread.subreddit.display_name prefix = 'Self post:' if thread.is_self else 'Link post:' url = thread.url if 'imgur' in urlparse(thread.url).netloc else urlparse(thread.url).netloc message = '%s: <%s> %s ( %s ) [ %s ] %s' % ( format.bold('/r/'+sub), thread.author, thread.title, thread.short_link, 'self.'+sub if thread.is_self else url, format.color(' NSFW', format.RED) if thread.over_18 else '' ) ''' message = '%s "%s" posted in /r/%s by %s. (%s)%s' % ( format.color(prefix, format.GREEN), thread.title, sub, thread.author, thread.short_link, format.color(' NSFW', format.RED) if thread.over_18 else '' ) ''' for chan in bot.config['watch'][sub.lower()]: if chan in bot.config['stopped']: continue if len(bot.config['watch'][sub.lower()][chan]): words = bot.config['watch'][sub.lower()][chan] regex = re.compile(r'\b(%s)\b' % '|'.join(words), re.I) if re.search(regex, thread.title): def repl(match): return format.bold(match.group(0)) new_title = re.sub(regex, repl, thread.title) bot.say(chan, message.replace(thread.title, new_title)) else: bot.say(chan, message) time.sleep(30)
def _command_kill(self, channel, sender, args): if args == "": args = random.choice(self.channels[channel].users()) else: args = args.rstrip() deaths = [ format.color(args, format.RED) + format.color(" has been chopped by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" has been trimmed by ", format.WHITE) + format.color(sender, format.GREEN), format.color(sender, format.GREEN) + format.color(" has butchered ", format.WHITE) + format.color(args, format.RED), format.color(args, format.RED) + format.color(" got buzzed by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" was massacred by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" was removed by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" got the Drill! (by ", format.WHITE) + format.color(sender, format.GREEN) + format.color(")", format.WHITE), format.color(args, format.RED) + format.color(" has been filed D for 'Dead' by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" was squashed by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" has been called a stupid Hoe by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" has been jackhammered into pieces by ", format.WHITE) + format.color(sender, format.GREEN), "<" + format.color(args, format.RED) + format.color("> " + sender + " what are you doing?, " + sender + "?!? STAHP!!!", format.WHITE), format.color(args, format.RED) + format.color(" was grounded by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" got mined by ", format.WHITE) + format.color(sender, format.GREEN), format.color(sender, format.GREEN) + format.color(" plew through the yard of ", format.WHITE) + format.color(args, format.RED), format.color(args, format.RED) + format.color(" got stuck trying to escape through a Pipe while fighting ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" got flattened by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" was getting cut down by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" got scooped up by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" is screwed! (by ", format.WHITE) + format.color(sender, format.GREEN) + format.color(")", format.WHITE), format.color(sender, format.GREEN) + format.color(" has taken the Soul of ", format.WHITE) + format.color(args, format.RED), format.color(args, format.RED) + format.color(" got dug up by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" was hammered to death by ", format.WHITE) + format.color(sender, format.GREEN), format.color(args, format.RED) + format.color(" has been digged by ", format.WHITE) + format.color(sender, format.GREEN), format.color(sender, format.GREEN) + format.color(" has cut the Cable for the Life Support Machine of ", format.WHITE) + format.color(args, format.RED), format.color(sender, format.GREEN) + format.color(" threw a Monkey Wrench into the Plans of ", format.WHITE) + format.color(args, format.RED) ] death = random.choice(deaths) self.sendMessage(channel, death)
def rainbow6(text): finalText = u'' for i, c in enumerate(text): finalText = finalText + unicode(format.color(c, pattern[0][i%6], pattern[1][i%6])).print()) return(finalText)
def loop(self): self.running = True while self.running: try: self.buffer = self.buffer + self.socket.recv(2048) except: sys.exit('ERROR: Failed to recv.') lines = str.split(self.buffer, '\r\n') self.buffer = lines.pop() for line in lines: # print line print line regex = re.compile(r'^(?::([^@!\ ]*)(?:(?:\!([^@]*))?@([^\ ]*))?\ )?([^\ ]+)\ ?((?:[^:\ ]*){0,14})(?:\ :?(.*))?$') nick, ident, host, type, destination, message = re.findall(regex, line)[0] params = message.split(' ') # do events if type in self.events: for func in self.events[type]: self.thread(func, ((nick, ident, host), destination, params)) # do commands print 'params[0] : ' + params[0] print 'self.config[\'prefix\'] : '+ self.config['prefix'] try: if params[0].startswith(self.config['prefix']): command = params[0][1:] params.pop(0) if command in self.commands: if self.config['log'] and destination != self.config['log']: self.say(self.config['log'], '%s %s called by %s in %s (%s)' % ( format.color('Command:', format.GREEN), command, nick, destination, ', '.join(params) )) if destination == self.nick: destination = nick for func in self.commands[command]: # admin perm overrides all if host in self.config['perms']['admin']: self.thread(func, ((nick, ident, host), destination, params)) continue # perms override flags elif hasattr(func, '_perm'): perm = getattr(func, '_perm') if perm not in self.config['perms']: continue if host not in self.config['perms'][perm]: continue # check required flags elif hasattr(func, '_flags'): self.check_perms.append({ 'nick': nick, 'func': func, 'perm': getattr(func, '_flags'), 'chan': destination, 'args': ((nick, ident, host), destination, params) }) self.do('WHO', destination) continue self.thread(func, ((nick, ident, host), destination, params)) except UnicodeDecodeError: print 'DECODE ERROR'