def check_messages(): ''' Checks for new messages, handles incoming messages Returns: true: New messages altered the database (added/removed filters) false: No messages, or the messages were innocuous ''' has_new_messages = False last_pm_time = Bot.db.get_config('last_pm_time') if last_pm_time == None: last_pm_time = 0 else: last_pm_time = int(float(last_pm_time)) for msg in Reddit.get('/message/inbox'): # TODO unread if msg.created <= last_pm_time or (type(msg) == Message and not msg.new): continue try: response = Filter.parse_pm(msg, Bot.db) while response.endswith('\n'): response = response[:-1] Bot.log('Bot.check_messages: Replying to %s with: %s' % (msg.author, response)) msg.reply(response) has_new_messages = True except Exception, e: # No need to reply Bot.log('Bot.check_messages: %s' % str(e)) last_pm_time = int(float(msg.created)) Bot.db.set_config('last_pm_time', str(last_pm_time)) msg.mark_as_read()
def handle_url(url, pages=1): children = [] for child in Bot.get_content(url, pages=pages): if Filter.handle_child(child, Bot.db, Bot.log): # Filter removed the child for spam continue # Retry images if necessary Rarchives.rescrape(child, Bot.db, Bot.log) if Bot.db.count('checked_posts', 'postid = ?', [child.id]) == 0: # Has not been checked yet if not AmArch.handle_child(child, Bot.db, Bot.log): children.append(child) Bot.db.insert('checked_posts', (child.id, )) Bot.db.commit() return children