Beispiel #1
0
def populate_formatting(tor, config):
    """
    Grabs the contents of the three wiki pages that contain the
    formatting examples and stores them in the config object.

    :return: None.
    """
    # zero out everything so we can reinitialize later
    config.audio_formatting = ''
    config.video_formatting = ''
    config.image_formatting = ''

    config.audio_formatting = get_wiki_page('format/audio', tor=tor)
    config.video_formatting = get_wiki_page('format/video', tor=tor)
    config.image_formatting = get_wiki_page('format/images', tor=tor)
Beispiel #2
0
def populate_domain_lists(tor, config):
    """
    Loads the approved content domains into the config object from the
    wiki page.

    :return: None.
    """

    config.video_domains = []
    config.image_domains = []
    config.audio_domains = []

    domains = get_wiki_page('domains', tor=tor)
    domains = ''.join(domains.splitlines()).split('---')

    for domainset in domains:
        domain_list = domainset[domainset.index('['):].strip('[]').split(', ')
        current_domain_list = []
        if domainset.startswith('video'):
            current_domain_list = config.video_domains
        elif domainset.startswith('audio'):
            current_domain_list = config.audio_domains
        elif domainset.startswith('images'):
            current_domain_list = config.image_domains
        [current_domain_list.append(x) for x in domain_list]
        logging.debug('Domain list populated: {}'.format(current_domain_list))
Beispiel #3
0
def populate_subreddit_lists(tor, config):
    """
    Gets the list of subreddits to monitor and loads it into memory.

    :return: None.
    """

    config.subreddits_to_check = []
    config.upvote_filter_subs = {}
    config.no_link_header_subs = []

    config.subreddits_to_check = get_wiki_page('subreddits', tor=tor).split('\r\n')
    config.subreddits_to_check = clean_list(config.subreddits_to_check)
    logging.debug(
        'Created list of subreddits from wiki: {}'.format(
            config.subreddits_to_check
        )
    )

    for line in get_wiki_page(
        'subreddits/upvote-filtered', tor=tor
    ).splitlines():
        if ',' in line:
            sub, threshold = line.split(',')
            config.upvote_filter_subs[sub] = int(threshold)

    logging.debug(
        'Retrieved subreddits subject to the upvote filter: {}'.format(
            config.upvote_filter_subs
        )
    )

    config.no_link_header_subs = get_wiki_page(
        'subreddits/no-link-header', tor=tor
    ).split('\r\n')
    config.no_link_header_subs = clean_list(config.no_link_header_subs)
    logging.debug(
        'Retrieved subreddits subject to the upvote filter: {}'.format(
            config.no_link_header_subs
        )
    )
Beispiel #4
0
def process_claim(post, r, tor, config):
    """
    Handles comment replies containing the word 'claim' and routes
    based on a basic decision tree.

    :param post: The Comment object containing the claim.
    :param r: Active Reddit object.
    :param tor: the TranscribersOfReddit Subreddit helper object.
    :param config: the global config dict.
    :return: None.
    """
    top_parent = get_parent_post_id(post, r)

    # WAIT! Do we actually own this post?
    if top_parent.author.name != 'transcribersofreddit':
        logging.debug('Received `claim` on post we do not own. Ignoring.')
        return

    if not coc_accepted(post, config):
        # do not cache this page. We want to get it every time.
        post.reply(
            _(please_accept_coc.format(get_wiki_page('codeofconduct', tor))))
        return

    if top_parent.link_flair_text is None:
        # There exists the very small possibility that the post was malformed
        # and doesn't actually have flair on it. In that case, let's set
        # something so the next part doesn't crash.
        flair_post(top_parent, flair.unclaimed)

    if flair.unclaimed in top_parent.link_flair_text:
        # need to get that "Summoned - Unclaimed" in there too
        post.reply(_(claim_success))
        flair_post(top_parent, flair.in_progress)
        logging.info('Claim on ID {} by {} successful'.format(
            top_parent.fullname, post.author))
    # can't claim something that's already claimed
    elif top_parent.link_flair_text == flair.in_progress:
        post.reply(_(already_claimed))
    elif top_parent.link_flair_text == flair.completed:
        post.reply(_(claim_already_complete))
Beispiel #5
0
def populate_header(tor, config):
    config.header = ''
    config.header = get_wiki_page('format/header', tor=tor)
Beispiel #6
0
def populate_gifs(tor, config):
    # zero it out so we can load more
    config.no_gifs = []
    config.no_gifs = get_wiki_page('usefulgifs/no', tor=tor).split('\r\n')