예제 #1
0
    async def wrapped(*args):
        turn_context, poll, *_ = args

        if poll.isStarted:
            notification_msg = create_message_activity(
                f'The poll is already started')
            await send_chat_message(turn_context, notification_msg)
            return

        return await func(*args)
예제 #2
0
    async def wrapped(*args):
        turn_context, poll, *_ = args

        if not poll.isStarted:
            notification_msg = create_message_activity(
                f'The poll is not started yet. Use disco command to rock it, baby!!!'
            )
            await send_chat_message(turn_context, notification_msg)
            return
        return await func(*args)
예제 #3
0
async def handle_poll_status_command(turn_context: TurnContext, poll: Poll):
    """ Show the status of the poll. """
    status_msgs = [
        'Poll status:',
        f"Poll is started: {poll.isStarted}",
        f"Uploading files enabled: {poll.isSongUploaded}"
    ]

    msg = create_message_activity('\n\n'.join(status_msgs))
    sender_id = get_request_sender_id(turn_context)
    await send_private_message(turn_context, sender_id, msg)
예제 #4
0
async def handle_settings_command(turn_context: TurnContext, poll: Poll, args: list):
    """ 
    Update settings for the current poll. 
    * mp3 <on/off> -- enable/disable uploading music
    """
    option, signal = _parse_settings_args(args)

    sender_id = get_request_sender_id(turn_context)

    if option == 'common':
        commands_msgs = [
            'List of valid commands:',
            '1. settings mp3 <on/off>'
        ]
        await send_private_message(
            turn_context,
            sender_id,
            create_message_activity('\n\n'.join(commands_msgs))
        )
    elif option == 'mp3':
        if signal == 'on' or signal == 'off':
            if signal == 'on':
                poll.isSongUploaded = True
                await send_private_message(
                    turn_context,
                    sender_id,
                    create_message_activity('Uploading music: ON')
                )
            else:
                poll.isSongUploaded = False
                await send_private_message(
                    turn_context,
                    sender_id,
                    create_message_activity('Uploading music: OFF')
                )
        else:
            await send_private_message(
                turn_context,
                sender_id,
                create_message_activity('mp3 <on/off> - it will on/off uploading music to chat functionality.')
            )
예제 #5
0
    async def wrapped(*args):
        turn_context, poll, *_ = args
        sender_id = get_request_sender_id(turn_context)

        if poll.owner_id != sender_id:
            notification_msg = create_message_activity(
                f"You can not use this command. You are not the owner of the poll."
            )
            await send_chat_message(turn_context, notification_msg)
            return

        return await func(*args)
예제 #6
0
async def _is_current_poll(turn_context: TurnContext, poll: Poll, value: dict):
    """ Check if the poll, user is been voting is the valid one. """
    current_poll_id = value.get('poll_id')
    if poll.id != current_poll_id:
        msg_activity = create_message_activity(
            f"Selected song is in the finished poll. Please start new poll, if it is not started yet."
        )
        await send_private_message(turn_context,
                                   turn_context.activity.from_property.id,
                                   msg_activity)
        return False
    return True
예제 #7
0
async def handle_top_command(turn_context: TurnContext, poll: Poll, args: list):
    """ Get top N songs that have max number of votes. """
    number_of_songs = _parse_song_number_arg(args, DEFAULT_TOP_COMMAND_SONGS)

    top_songs = list(poll.storage.sort_songs())[:number_of_songs]

    song_msgs = [f'Top {number_of_songs}:']
    for song in top_songs:
        song_msgs.append(f'{song.title} --- {song.author} --- {song.mark} votes')

    msg = create_message_activity('\n\n'.join(song_msgs))

    sender_id = get_request_sender_id(turn_context)
    await send_private_message(turn_context, sender_id, msg)
예제 #8
0
async def handle_lightsoff_command(turn_context: TurnContext, poll: Poll):
    """ Finish the poll. Send results. """
    winner = poll.finish()

    winner_msgs = [f"The winner is {winner.title} with {winner.mark} votes!!!"]

    if poll.isSongUploaded:
        winner_msgs.append(f"Download link: {winner.link}")

    winner_msg = create_message_activity(
        '\n\n'.join(winner_msgs)
    )
    clear_state('files/saved_state.json')
    await send_chat_message(turn_context, winner_msg)
예제 #9
0
async def handle_poptop_command(turn_context: TurnContext, poll: Poll, args: list):
    """ 
    Get N winning song details. If enabled -- get the download link. 
    Poptop song votes are going to be reseted. 
    """
    song_number = _parse_song_number_arg(args, DEFAULT_POPTOP_COMMAND_SONGS)

    poptop_song = list(poll.storage.sort_songs())[song_number-1]

    poptop_msgs = [
        f'Poptop song #{song_number}',
        f'{poptop_song.title} --- {poptop_song.author} --- {poptop_song.mark} votes'
    ]

    if poll.isSongUploaded:
        poptop_msgs.append(f"Download link: {poptop_song.link}")

    msg = create_message_activity('\n\n'.join(poptop_msgs))

    poll.storage.nullify_song_votes(poptop_song)

    await send_chat_message(turn_context, msg)