Exemple #1
0
def claim_email_announcement(update: Update, context: CallbackContext):
    mwelog.info("Sending claim email announcement to champions")
    user = get_user_from_update(update)
    if user.id == mwexpress_config.moderator or user.id == 1065263859:
        for user in get_all_users():
            if user.became_champion:
                try:
                    mwelog.info(
                        f"Sending claim email message to {user.username}")
                    context.bot.send_sticker(user.id, EXCITED_STICKER)
                    context.bot.send_message(
                        user.id, user.language.get(Token.CHAMP_BUT_NO_EMAIL))
                    time.sleep(0.5)
                except Exception as ex:
                    mwelog.exception(str(ex))
Exemple #2
0
def send_game_started_again_with_awards(update: Update,
                                        context: CallbackContext):
    mwelog.info("Sending game started again message to all users")
    user = get_user_from_update(update)
    if user.id == mwexpress_config.moderator or user.id == 1065263859:
        for user in get_all_users():
            try:
                mwelog.info(
                    f"Sending game started again message to {user.username}")
                context.bot.send_sticker(user.id, EXCITED_STICKER)
                send_message_to_user(
                    context.bot, user,
                    user.language.get(Token.GAME_STARTED_AGAIN_ANNOUNCEMENT))
                time.sleep(0.5)
            except Exception as ex:
                mwelog.exception(str(ex))
Exemple #3
0
def start(update: Update, context: CallbackContext):
    user = get_user_from_update(update)

    mwelog.info("User {user_name} started using Mwexpress",
                user_name=user.username,
                user_id=user.id)

    clear_state(context)

    context.bot.send_sticker(update.effective_chat.id, TIPS_FEDORA_STICKER)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_1),
             Keyboard.remove())
    time.sleep(2)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_2),
             Keyboard.remove())
    time.sleep(5)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_3),
             Keyboard.remove())
    time.sleep(3)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_4),
             Keyboard.remove())
    time.sleep(2)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_5),
             Keyboard.remove())
    time.sleep(5)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_6),
             Keyboard.remove())
    time.sleep(10)
    update.message.reply_text(text=user.language.get(Token.WELCOME_MESSAGE_7),
                              parse_mode=ParseMode.HTML,
                              reply_markup=Keyboard.remove())
    time.sleep(5)
    context.bot.send_photo(user.id, open("assets/keyboard_button.png", "rb"))
    time.sleep(0.5)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_8))
    time.sleep(5)
    reply_to(user, update, user.language.get(Token.DISCLAIMER),
             Keyboard.main(user))
Exemple #4
0
def send_i_need_x_examples(update: Update, context: CallbackContext):
    user = get_user_from_update(update)
    if user.id == 1065263859 or user.id == 1036601606:
        notification_manager.send_i_need_x_examples(context)
Exemple #5
0
def review_happy_hour(update: Update, context: CallbackContext):
    user = get_user_from_update(update)
    if user.id == 1065263859 or user.id == 1036601606:
        notification_manager.send_review_worth_more(context)
        submission_scores.start_review_happy_hour()
Exemple #6
0
def email_handler(update: Update, context: CallbackContext):
    user = get_user_from_update(update)
    main_email_handler(user, update, context)
Exemple #7
0
def message(update: Update, context: CallbackContext):
    user = get_user_from_update(update)
    try:
        mwelog.info("New message from {user_name}: {message}",
                    user_name=user.username,
                    message=update.message.text)

        if user.banned:
            update.message.reply_text(
                user.language.get(Token.USER_IS_BANNED_MESSAGE))
            return

        if update.message.text.startswith("/flag"):
            flag_submission(user, int(update.message.text.replace("/flag",
                                                                  "")),
                            context)
            return
        if update.message.text.startswith("/ban"):
            ban_user(user, int(update.message.text.replace("/ban", "")),
                     context)
            return

        if mwexpress_config.game_stopped:
            update.message.reply_sticker(COFFEE_STICKER)
            update.message.reply_text(
                user.language.get(Token.GAME_TEMPORARILY_STOPPED))
            update.message.reply_text(user.language.get(Token.SURVEY_MESSAGE))
            return

        if get_state(context) != State.NONE:
            state = get_state(context)
            mwelog.info("Current state for {user_name}: {state}",
                        user_name=user.username,
                        state=str(state))
            if state == State.SUBMISSION:
                main_submit_handler(user, update, context)
            elif state == State.CHANGING_LANGUAGE:
                language_update_handler(user, update, context)
            elif state == State.REVIEWING:
                main_review_handler(user, update, context)
            elif state == State.ADDING_EMAIL:
                main_email_handler(user, update, context)
        else:
            if update.message.text == user.language.get(Token.TODAYS_MWE):
                todays_mwe_handler(user, update)
            elif update.message.text == user.language.get(Token.SUBMIT):
                main_submit_handler(user, update, context)
            elif update.message.text == user.language.get(
                    Token.CHANGE_LANGUAGE):
                language_change_handler(user, update, context)
            elif update.message.text == user.language.get(Token.HELP):
                help_handler(user, update, context)
            elif update.message.text == user.language.get(Token.REVIEW):
                main_review_handler(user, update, context)
            elif update.message.text == user.language.get(Token.FEEDBACK):
                feedback_handler(user, update, context)
            elif update.message.text == user.language.get(
                    Token.SHOW_SCOREBOARD):
                scoreboard_handler(user, update, context)
            elif update.message.text == user.language.get(Token.ACHIEVEMENTS):
                achievements_handler(user, update, context)
            elif update.message.text == user.language.get(Token.ADD_EMAIL):
                main_email_handler(user, update, context)
            elif submission_contains_todays_mwe(user, update.message.text):
                context.user_data["sub_state"] = "typing_example"
                main_submit_handler(user, update, context)
            else:
                update.message.reply_text(user.language.get(
                    Token.ENTER_VALID_COMMAND),
                                          parse_mode=ParseMode.MARKDOWN,
                                          reply_markup=Keyboard.main(user))
                context.bot.send_photo(
                    user.id, open("assets/keyboard_button.png", "rb"))
                update.message.reply_text(user.language.get(
                    Token.WELCOME_MESSAGE_8),
                                          parse_mode=ParseMode.MARKDOWN,
                                          reply_markup=Keyboard.main(user))

    except Exception as ex:
        clear_state(context)
        unmute_user(user.id)
        _safe_delete_context_data(context, "sub_state")
        _safe_delete_context_data(context, "parsed")
        _safe_delete_context_data(context, "submission")
        mwelog.error(
            f"erroneous message: {user.username}: {update.message.text}")
        mwelog.exception(str(ex))
        update.message.reply_text(user.language.get(Token.ERROR_OCCURRED),
                                  reply_markup=Keyboard.main(user))
Exemple #8
0
def stats(update: Update, context: CallbackContext):
    user = get_user_from_update(update)
    mwelog.info(f"Stats requested by {user.username}")

    today = datetime.now().date()

    if len(context.args) == 3:
        day = int(context.args[0])
        month = int(context.args[1])
        year = int(context.args[2])
        today = datetime(year, month, day).date()

    update.message.reply_text(f'Stats for {today.strftime("%A, %B %d, %Y")}')

    session = database.get_session()
    all_users_count = session.query(User).filter(
        func.Date(User.created) <= today).count()
    new_users = session.query(User).filter(
        func.Date(User.created) == today).all()
    update.message.reply_text(
        f'{all_users_count} users (+{len(new_users)} new)')
    if len(new_users) > 0:
        update.message.reply_text(
            f'New users: {", ".join([x.username for x in new_users])}')

    all_submissions_count = session.query(Submission).filter(
        func.Date(Submission.created) <= today).count()
    new_submissions_count = session.query(Submission).filter(
        func.Date(Submission.created) == today).count()
    update.message.reply_text(
        f'{all_submissions_count} submissions (+{new_submissions_count} new)')

    all_reviews_count = session.query(Review).filter(
        func.Date(Review.created) <= today).count()
    new_reviews_count = session.query(Review).filter(
        func.Date(Review.created) == today).count()
    update.message.reply_text(
        f'{all_reviews_count} reviews (+{new_reviews_count} new)')

    all_subs = session.query(Submission).all()
    all_subs_today = session.query(Submission).filter(
        func.Date(Submission.created) == today).all()
    review_count_average = round(
        statistics.mean([x.review_count for x in all_subs]), 2)
    review_count_average_today = 0.0
    if len(all_subs_today) > 0:
        review_count_average_today = round(
            statistics.mean([x.review_count for x in all_subs_today]), 2)
    update.message.reply_text(
        f'Review count average: {review_count_average}({review_count_average_today} today)'
    )

    all_reviews_today = session.query(Review).filter(
        func.Date(Review.created) == today).all()
    all_submitted_users_today = set([x.user.id for x in all_subs_today])
    all_reviewed_users_today = set([x.user.id for x in all_reviews_today])

    update.message.reply_text(
        f'Users who only submitted: {len([x for x in all_submitted_users_today if x not in all_reviewed_users_today])}'
    )
    update.message.reply_text(
        f'Users who only reviewed: {len([x for x in all_reviewed_users_today if x not in all_submitted_users_today])}'
    )
    update.message.reply_text(
        f'Users who both submitted and reviewed: {len([x for x in all_submitted_users_today if x in all_reviewed_users_today])}'
    )

    positive_together_count = session.query(Submission)\
        .filter(Submission.category == SubmissionCategory.POSITIVE_TOGETHER)\
        .filter(func.Date(Submission.created) == today)\
        .count()
    positive_separated_count = session.query(Submission)\
        .filter(Submission.category == SubmissionCategory.POSITIVE_SEPARATED)\
        .filter(func.Date(Submission.created) == today)\
        .count()
    negative_together_count = session.query(Submission)\
        .filter(Submission.category == SubmissionCategory.NEGATIVE_TOGETHER)\
        .filter(func.Date(Submission.created) == today)\
        .count()
    negative_separated_count = session.query(Submission)\
        .filter(Submission.category == SubmissionCategory.NEGATIVE_SEPARATED)\
        .filter(func.Date(Submission.created) == today)\
        .count()
    update.message.reply_text(
        f"Submission categories:\nPositive together: {positive_together_count}\n"
        f"Positive separated: {positive_separated_count}\n"
        f"Negative together: {negative_together_count}\n"
        f"Negative separated: {negative_separated_count}")