예제 #1
0
                        def repl(match):

                            return format.bold(match.group(0))
예제 #2
0
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)
예제 #3
0
 def start(self, game):
     raise util.UsageError("There is already a game of %s going on at the moment." % format.bold(self.game.name))