def is_valid_request(child, db, log): ''' Ensures request is from an account older than MINIMUM_REQUESTER_AGE days, and the accounts last request was over MINIMUM_REQUEST_DAYS days ago. If not, removes the request and comments with the reason for removal Returns: True if post is valid request, False if request is not valid and was removed. ''' if type(child) != Post: return True request_is_valid = False # Check if last request was < MINIMUM_REQUEST_DAYS days ago now = timegm(gmtime()) for (date, permalink) in db.select('date, permalink', 'amarch_requests', 'username = ?', [child.author]): if date + (3600 * 24 * AmArch.MINIMUM_REQUEST_DAYS) > now: # Last request was < MINIMUM_REQUEST_DAYS days ago, check if the request was 'removed' post = Reddit.get(permalink) if post.banned_by == None: # Last request was < MINIMUM_REQUEST_DAYS days ago, wasn't removed child.remove(mark_as_spam=False) log('AmArch.is_valid_request: Request < %d days old: %s' % (AmArch.MINIMUM_REQUEST_DAYS, child.permalink())) body = '## Rule: [Requests must be at least %d days apart](/r/AmateurArchives/about/sidebar)\n\n' % AmArch.MINIMUM_REQUEST_DAYS body += 'The [**last request**](%s) from your account was submitted %s' % (permalink, Reddit.utc_timestamp_to_hr(post.created)) response = child.reply(body) response.distinguish() child.flair('last req < %dd' % AmArch.MINIMUM_REQUEST_DAYS) return False else: # XXX OPTIMIZATION # Last request was > MINIMUM_REQUEST_DAYS days ago but was removed # Therefore: User account must be > MINIMUM_REQUESTER_AGE days old request_is_valid = True if not request_is_valid: # Check if user is < MINIMUM_REQUESTER_AGE days old user = Reddit.get_user_info(child.author) if user.created > now - (3600 * 24 * AmArch.MINIMUM_REQUESTER_AGE): child.remove(mark_as_spam=False) log('AmArch.is_valid_request: Requester /u/%s < %d days old: %s' % (child.author, AmArch.MINIMUM_REQUESTER_AGE, child.permalink())) body = '## Rule: [Requests must be from accounts more than %d days old](/r/AmateurArchives/about/sidebar)\n\n' % AmArch.MINIMUM_REQUESTER_AGE body += 'The account (/u/%s) was created %s.' % (child.author, Reddit.utc_timestamp_to_hr(user.created)) response = child.reply(body) response.distinguish() child.flair('user < %dd' % AmArch.MINIMUM_REQUESTER_AGE) return False # Request is valid. Add it to the database for checking in the future log('AmArch.is_valid_request: Allowing request from /u/%s' % child.author) if db.count('amarch_requests', 'username = ?', [child.author]) == 0: db.insert('amarch_requests', (child.author, child.created, child.permalink())) else: db.update('amarch_requests', 'date = ?, permalink = ?', 'username = ?', [child.created, child.permalink(), child.author]) return True
def gonewild_check(child, json, db, log): ''' Check if image(s) in child were posted to gonewild and the child author is not the original gonewild author. Remove child and explain in comment. Args: child: reddit child (post) json: results from rarchives Returns: True if post originated on gonewild, False otherwise. ''' # Disable this on /r/AmateurArchives if child.subreddit.lower() == 'amateurarchives': return False # XXX Only enforce posts by gonewild users (not comments) for post in json['posts']: if post['subreddit'].lower() == 'gonewild' and \ post['author'].lower() != child.author.lower() and \ post['author'] != '[deleted]': # Child author is not the gonewild user, image *is* though # Remove and comment the source child.remove(mark_as_spam=False) log('Rarchives.gonewild_check: Removed %s - matches /u/%s @ http://reddit.com%s' % (child.permalink(), post['author'], post['permalink'])) title = post['title'].replace('[', '\\[').replace('(', '\\(').replace(']', '\\]').replace(')', '\\)').replace('*', '') body = '## This post was removed because it is a repost of a /r/gonewild submission:\n\n' body += '* **/u/%s** submitted [*%s*](%s) %s' % (post['author'], title, post['permalink'], Reddit.utc_timestamp_to_hr(post['created'])) try: response = child.reply(body) response.distinguish() child.flair('Gonewild repost: /u/%s' % post['author']) except Exception, e: log('Rarchives.gonewild_check: Error while replying to %s : %s' % (child.permalink(), str(e))) # Update 'log_amarch' db table db.insert('log_amarch', ('removed', child.permalink(), timegm(gmtime()), 'gonewild repost of /u/%s: %s' % (post['author'], post['permalink']))) return True