Example #1
0
def open_init_text(message, poll):
    """Open the initial poll creation message."""
    keyboard = get_init_keyboard(poll)
    message.edit_text(
        get_init_text(poll),
        parse_mode='markdown',
        reply_markup=keyboard,
    )
Example #2
0
def change_poll_type(session, context, poll):
    """Change the vote type."""
    if poll.created:
        return i18n.t('callback.poll_created', locale=context.user.locale)

    poll.poll_type = PollType(context.action).name

    keyboard = get_init_keyboard(poll)
    context.query.message.edit_text(get_init_text(poll),
                                    parse_mode='markdown',
                                    reply_markup=keyboard)
Example #3
0
def toggle_results_visible(session, context, poll):
    """Change the results visible settings of a poll."""
    if poll.created:
        return i18n.t('callback.poll_already_created',
                      locale=context.user.locale)

    poll.results_visible = not poll.results_visible

    keyboard = get_init_keyboard(poll)
    context.query.message.edit_text(get_init_text(poll),
                                    parse_mode='markdown',
                                    reply_markup=keyboard)
    return i18n.t('callback.visibility_changed', locale=context.user.locale)
Example #4
0
def toggle_anonymity(session, context, poll):
    """Change the anonymity settings of a poll."""
    if poll.created:
        return i18n.t('callback.poll_already_created',
                      locale=context.user.locale)

    poll.anonymous = not poll.anonymous

    keyboard = get_init_keyboard(poll)
    context.query.message.edit_text(get_init_text(poll),
                                    parse_mode='markdown',
                                    reply_markup=keyboard)

    return i18n.t('callback.anonymity_changed', locale=context.user.locale)
Example #5
0
def open_init_text(message, poll: Poll):
    """Open the initial poll creation message."""
    if poll.created_from_native:
        keyboard = get_native_poll_merged_keyboard(poll)
        message.edit_text(
            get_native_poll_merged_text(poll),
            parse_mode="markdown",
            reply_markup=keyboard,
        )
    else:
        keyboard = get_init_keyboard(poll)
        message.edit_text(
            get_init_text(poll), parse_mode="markdown", reply_markup=keyboard
        )
Example #6
0
def create_poll(bot, update, session, user):
    """Create a new poll."""
    # The previous unfinished poll will be removed
    user.started = True
    if user.current_poll is not None and not user.current_poll.created:
        update.message.chat.send_message(
            i18n.t('creation.already_creating', locale=user.locale),
            reply_markup=get_cancel_creation_keyboard(user.current_poll))
        return

    poll = Poll.create(user, session)
    text = get_init_text(poll)
    keyboard = get_init_keyboard(poll)

    update.message.chat.send_message(
        text,
        parse_mode='markdown',
        reply_markup=keyboard,
        disable_web_page_preview=True,
    )
def create_poll(bot, update, session, user):
    """Create a new poll."""
    # The previous unfinished poll will be removed
    if user.current_poll is not None and not user.current_poll.created:
        update.message.chat.send_message(
            i18n.t('creation.already_creating', locale=user.locale),
            reply_markup=get_cancel_creation_keyboard(user.current_poll))
        return

    poll = Poll(user)
    poll.european_date_format = user.european_date_format
    poll.locale = user.locale
    user.current_poll = poll
    user.expected_input = ExpectedInput.name.name
    session.add(poll)
    session.commit()

    text = get_init_text(poll)
    keyboard = get_init_keyboard(poll)

    update.message.chat.send_message(text, parse_mode='markdown', reply_markup=keyboard)
Example #8
0
def init_poll(session, context):
    """Start the creation of a new poll."""
    user = context.user
    chat = context.query.message.chat
    if user.current_poll is not None and not user.current_poll.created:
        chat.send_message(
            i18n.t("creation.already_creating", locale=user.locale),
            reply_markup=get_cancel_creation_keyboard(user.current_poll),
        )
        return

    poll = Poll.create(user, session)
    text = get_init_text(poll)
    keyboard = get_init_keyboard(poll)

    chat.send_message(
        text,
        parse_mode="markdown",
        reply_markup=keyboard,
        disable_web_page_preview=True,
    )