Beispiel #1
0
def send_competition_notification_pm(username, message_body):
    """ Sends a new competition notification PM to the specified user. """

    if IS_DEVO:
        return

    send_PM_to_user_with_title_and_body(username, NEW_COMP_TITLE, message_body)
def send_gift_code_winner_approval_pm(comp_id):
    """ Chooses a random participant from the competition provided, and builds a
    WeeklyCodeRecipientConfirmDeny record. Sends a PM to the configured admin user to approve or
    deny that user. """

    winner = get_random_reddit_participant_for_competition(comp_id)
    competition = get_competition(comp_id)
    gift_code = get_unused_gift_code()

    if not gift_code:
        msg = __NO_CODES_LEFT_TEMPLATE.format(
            comp_title=competition.title,
            code_refill_url=__CODE_REFILL_ADMIN_URL)
        send_PM_to_user_with_title_and_body(__CODE_TOP_OFF_REDDIT_USER,
                                            __NO_CODES_LEFT_TITLE, msg)
        send_gift_code_winner_approval_pm.schedule(
            (comp_id, ), delay=__GIFT_CODE_SELECTION_RETRY_DELAY)
        return

    confirm_deny_record = create_confirm_deny_record(gift_code.id, winner.id,
                                                     comp_id)

    msg = __CODE_CONFIRM_DENY_MSG_TEMPLATE.format(
        reddit_id=winner.reddit_id,
        comp_title=competition.title,
        user_profile_url=__USER_PROFILE_URL.format(username=winner.username),
        confirm_url=__CONFIRM_URL_TEMPLATE.format(
            confirm_code=confirm_deny_record.confirm_code),
        deny_url=__DENY_URL_TEMPLATE.format(
            deny_code=confirm_deny_record.deny_code),
        unused_codes_count=get_unused_gift_code_count())

    send_PM_to_user_with_title_and_body(__CODE_CONFIRM_REDDIT_USER,
                                        __CODE_CONFIRM_DENY_TITLE, msg)
Beispiel #3
0
def send_end_of_competition_message(user_id, comp_id, comp_title):
    """ Sends a report to the specified user with info about their participation in the
    competition. """

    user = get_user_by_id(user_id)
    all_results = get_all_complete_user_results_for_comp_and_user(
        comp_id, user_id, include_blacklisted=False)

    total_solves = 0
    events_with_pbs = list()
    events_with_podium = list()
    total_events_participated_in = len(all_results)

    for event_results in all_results:
        if event_results.was_bronze_medal:
            medal_desc = "{} (bronze)".format(
                event_results.CompetitionEvent.Event.name)
            events_with_podium.append(medal_desc)
        if event_results.was_silver_medal:
            medal_desc = "{} (silver)".format(
                event_results.CompetitionEvent.Event.name)
            events_with_podium.append(medal_desc)
        if event_results.was_gold_medal:
            medal_desc = "{} (gold)".format(
                event_results.CompetitionEvent.Event.name)
            events_with_podium.append(medal_desc)
        if event_results.was_pb_average or event_results.was_pb_single:
            events_with_pbs.append(event_results.CompetitionEvent.Event.name)
        total_solves += len(event_results.solves)

    podium_info = ''
    if events_with_podium:
        events_medal_list = naturally_join(events_with_podium)
        podium_info = PODIUM_INFO_TEMPLATE.format(
            events_medal_list=events_medal_list)

    pb_info = ''
    if events_with_pbs:
        maybe_pluralized_pbs = "some PBs" if len(
            events_with_pbs) > 1 else "a PB"
        pb_events_list = naturally_join(events_with_pbs)
        pb_info = PB_INFO_TEMPLATE.format(
            pb_events_list=pb_events_list,
            maybe_pluralized_pbs=maybe_pluralized_pbs)

    message_body = END_OF_COMP_BODY_TEMPLATE.format(
        username=user.username,
        comp_title=comp_title,
        event_count=total_events_participated_in,
        solves_count=total_solves,
        pb_info=pb_info,
        podium_info=podium_info,
        opt_out_info=OPT_OUT_INFO)

    message_title = END_OF_COMP_TITLE_TEMPLATE.format(comp_title=comp_title)

    send_PM_to_user_with_title_and_body(user.username, message_title,
                                        message_body)
def check_gift_code_pool():
    """ Periodically checks the available gift code count and if it's too low, send a PM to a
    configurable user to top it off. """

    available_code_count = get_unused_gift_code_count()
    if available_code_count < __CODE_TOP_OFF_THRESHOLD:
        msg = __CODES_REFILL_TEMPLATE.format(
            codes_left=available_code_count,
            code_refill_url=__CODE_REFILL_ADMIN_URL)
        send_PM_to_user_with_title_and_body(__CODE_TOP_OFF_REDDIT_USER,
                                            __CODES_REFILL_TITLE, msg)
def send_gift_code_to_winner(user_id: int, gift_code_id: int,
                             comp_id: int) -> None:
    """ Sends a PM to recipient of a weekly SCS gift code. """

    user = get_user_by_id(user_id)
    msg = __GIFT_CODE_RECIPIENT_TEMPLATE.format(
        username=user.reddit_id,
        gift_code=get_gift_code_by_id(gift_code_id).gift_code,
        comp_title=get_competition(comp_id).title)

    send_PM_to_user_with_title_and_body(user.reddit_id,
                                        __GIFT_CODE_RECIPIENT_TITLE, msg)