Example #1
0
async def get_response(bot, context):
    response = Response()
    use_plugin = configurations.get(bot, __name__, key='enable')
    if not use_plugin:
        response.content = (
            "The GDQ plugin is currently disabled. (GDQ is probably over or hasn't started yet)")
        return response

    embed_template = discord.Embed(
        title='Games Done Quick', url='https://gamesdonequick.com/',
        colour=discord.Colour(0x00aff0),
        description='\[ [Stream]({}) ] \[ [Schedule]({}) ] \[ [Donate]({}) ]'.format(
            configurations.get(bot, __name__, 'stream_url'),
            configurations.get(bot, __name__, 'schedule_url'),
            configurations.get(bot, __name__, 'donate_url')))
    embed_template.set_thumbnail(url='http://i.imgur.com/GcdqhUR.png')
    guild_id = context.guild.id if context.guild else None
    if context.index == 0:
        embed_template.add_field(name='Donation stats', value='Loading...', inline=False)
        response.game_index = data.get(bot, __name__, 'current_index', volatile=True, default=0)
        schedule_data = data.get(bot, __name__, 'schedule', volatile=True)
        games_list = schedule_data[response.game_index:response.game_index + 5]
        game_data = _embed_games_information(bot, games_list, guild_id)
        value = '\n\n'.join('**{}**\n{}'.format(*it) for it in game_data)
        embed_template.add_field(name='Schedule', value=value, inline=False)
        response.update_stats = True
        response.update_task = None
        response.message_type = MessageTypes.INTERACTIVE
        response.extra_function = gdq_menu
        response.extra = {'buttons': ['⬅', '⏺', '➡']}

    elif context.index == 1:  # About
        embed_template.add_field(name='About', value=(
            "Games Done Quick (GDQ) is a week-long charity gaming marathon that "
            "brings together speedrunners from around the globe to raise money on a "
            "livestream. They are currently supporting {0}, and all donations go "
            "directly to the charity.\n\nCheck out the links above for the Twitch "
            "stream, games schedule, and the donation portal!").format(
                configurations.get(bot, __name__, 'charity')))

    elif context.index == 2:  # Status
        status_text = await _get_status(bot)
        embed_template.add_field(name='Status', value=status_text, inline=False)

    elif context.index == 3:  # Current game
        embed_data = _get_current_game(bot, guild_id)[0]
        embed_template.add_field(name=embed_data[0], value=embed_data[1], inline=False)

    elif context.index == 4:  # Next game(s)
        embed_data = _get_next_games(bot, context.arguments[0], guild_id)
        for name, value in embed_data:
            embed_template.add_field(name=name, value=value, inline=False)

    elif context.index == 5:  # Search
        embed_data = _search_games(bot, context.arguments[0], guild_id=guild_id)
        embed_template.add_field(name=embed_data[0], value=embed_data[1], inline=False)

    elif context.index == 6:  # Notify
        game = _search_games(bot, context.arguments[0], return_game=True)
        response.content = _toggle_notification(
            bot, game, context, use_channel='channel' in context.options)
        embed_template = None

    response.embed = embed_template
    return response
Example #2
0
async def get_response(bot, context):
    """Gets a response given the parsed input.

    context attributes:
    bot -- A reference to the bot itself.
    message -- The discord.message object obtained from on_message.
    base -- The base command name that immediately follows the invoker.
    subcommand -- The subcommand that matched the parameters.
    index -- The index of the found subcommand.
    options -- A dictionary representing the options and potential positional
        arguments that are attached to them.
    arguments -- A list of strings that follow the syntax of the blueprint
        index for arguments following the options.
    keywords -- Another list of strings that holds all option keywords. These
        can be used to prevent database conflicts with user commands.
    cleaned_content -- Simply the message content without the invoker.
    """

    # This is what the bot will say when it returns from this function.
    # The response object can be manipulated in many ways. The attributes of
    #   the response will be passed into the send function.
    response = Response()
    response.content = ''  # Default

    # Set to True if you want your message read with /tts (not recommended).
    response.tts = False  # Default

    # The message type dictates how the bot handles your returned message.
    #
    # NORMAL - Normal. The issuing command can be edited.
    # PERMANENT - Message is not added to the edit dictionary.
    # REPLACE - Deletes the issuing command after 'extra' seconds. Defaults
    #   to 0 seconds if 'extra' is not given.
    # ACTIVE - The message reference is passed back to the function defined
    #   with 'extra_function'. If 'extra_function' is not defined, it will call
    #   plugin.handle_active_message.
    # INTERACTIVE - Assembles reaction buttons given by extra['buttons'] and
    #   calls 'extra_function' whenever one is pressed.
    # WAIT - Wait for event. Calls 'extra_function' with the result, or None
    #   if the wait timed out.
    #
    # Only the NORMAL message type can be edited.
    response.message_type = MessageTypes.NORMAL  # Default

    # The extra variable is used for some message types.
    response.extra = None  # Default

    # Initially, check to make sure that you've matched the proper command.
    # If there is only one command specified, this may not be necessary.
    index, options, arguments = context.index, context.options, context.arguments
    if context.base == 'mycommand':

        # Then, the subcommand index will tell you which command syntax was
        #   satisfied. The order is the same as was specified initially.
        if index == 0:  # myoption
            response.content = "You called the first subcommand!"
            # Do other stuff...

        elif index == 1:  # custom/attached
            # To see if an optional option was included in the command, use:
            if 'custom' in options:
                response.content += "You included the \"custom\" flag!\n"
                # Do stuff relevant to this flag here...

            # To get the parameter attached to an option, simply access it from
            #   the options dictionary.
            if 'attached' in options:
                response.content += "The attached parmeter: {}\n".format(
                    options['attached'])

            # In case somebody was looking for the help...
            if len(options) == 0:
                invoker = utilities.get_invoker(bot, guild=context.guild)
                response.content += (
                    "You didn't use either flag...\n"
                    "For help, try `{}help mycommand`".format(invoker))

        elif index == 2:  # trailing arguments
            # If arguments are specified as trailing, they will be in a list.
            response.content += "The list of trailing arguments: {}".format(
                arguments)

        elif index == 3:  # grouped arguments
            # All arguments are grouped together as the first element
            response.message_type = MessageTypes.PERMANENT
            response.content = ("You can't edit your command here.\n"
                                "Single grouped argument: {}").format(
                                    arguments[0])

        elif index == 4:  # complex
            # This mixes elements of both examples seen above.
            response.content = ("The argument attached to the complex "
                                "option: {}").format(options['complex'])
            if 'other' in options:
                response.content += "\nThe other option has attached: {}".format(
                    options['other'])
            response.content += "\nLastly, the trailing arguments: {}".format(
                arguments)

        elif index == 5:  # (Very slow) marquee
            # This demonstrates the active message type.
            # Check active_marquee to see how it works.
            response.message_type = MessageTypes.ACTIVE
            response.extra_function = active_marquee  # The function to call
            response.extra = arguments[0]  # The text to use
            response.content = "Setting up marquee..."  # This will be shown first

    # Here's another command base.
    elif context.base == 'myothercommand':

        if index == 0:  # keyword checker
            text = arguments[0]
            if not text:
                response.content = "You didn't say anything...\n"
            else:
                response.content = "This is your input: {}\n".format(text)
                if text in context.keywords:
                    response.content += "Your input was in the list of keywords!\n"
                else:
                    response.content += (
                        "Your input was not in the list of keywords. "
                        "They are: {}\n").format(context.keywords)
            response.message_type = MessageTypes.PERMANENT
            response.delete_after = 15
            response.content += "This message will self destruct in 15 seconds."

        else:  # impossible command???
            raise CBException(
                "This is a bug! You should never see this message.")

    elif context.base == 'wait':
        response.message_type = MessageTypes.WAIT
        # The extra attribute should consist of a dictionary containing the
        #   event and any other kwargs. Most notably, you will likely want to
        #   define the check used in wait_for.
        response.extra_function = custom_interaction
        response.extra = {
            'event': 'message',
            'kwargs': {
                'timeout': 30,  # Default 300
                'check': lambda m: m.author == context.author,
            }
        }
        response.content = "Say something, {}.".format(context.author)

    return response
Example #3
0
async def get_response(bot, context):
    response = Response()
    use_plugin = configurations.get(bot, __name__, key='enable')
    if not use_plugin:
        response.content = (
            "The GDQ plugin is currently disabled. (GDQ is probably over or hasn't started yet)"
        )
        return response

    embed_template = discord.Embed(
        title='Games Done Quick',
        url='https://gamesdonequick.com/',
        colour=discord.Colour(0x00aff0),
        description='\[ [Stream]({}) ] \[ [Schedule]({}) ] \[ [Donate]({}) ]'.
        format(configurations.get(bot, __name__, 'stream_url'),
               configurations.get(bot, __name__, 'schedule_url'),
               configurations.get(bot, __name__, 'donate_url')))
    embed_template.set_thumbnail(url='http://i.imgur.com/GcdqhUR.png')
    guild_id = context.guild.id if context.guild else None
    if context.index == 0:
        embed_template.add_field(name='Donation stats',
                                 value='Loading...',
                                 inline=False)
        response.game_index = data.get(bot,
                                       __name__,
                                       'current_index',
                                       volatile=True,
                                       default=0)
        schedule_data = data.get(bot, __name__, 'schedule', volatile=True)
        games_list = schedule_data[response.game_index:response.game_index + 5]
        game_data = _embed_games_information(bot, games_list, guild_id)
        value = '\n\n'.join('**{}**\n{}'.format(*it) for it in game_data)
        embed_template.add_field(name='Schedule', value=value, inline=False)
        response.update_stats = True
        response.update_task = None
        response.message_type = MessageTypes.INTERACTIVE
        response.extra_function = gdq_menu
        response.extra = {'buttons': ['⬅', '⏺', '➡']}

    elif context.index == 1:  # About
        embed_template.add_field(
            name='About',
            value=
            ("Games Done Quick (GDQ) is a week-long charity gaming marathon that "
             "brings together speedrunners from around the globe to raise money on a "
             "livestream. They are currently supporting {0}, and all donations go "
             "directly to the charity.\n\nCheck out the links above for the Twitch "
             "stream, games schedule, and the donation portal!").format(
                 configurations.get(bot, __name__, 'charity')))

    elif context.index == 2:  # Status
        status_text = await _get_status(bot)
        embed_template.add_field(name='Status',
                                 value=status_text,
                                 inline=False)

    elif context.index == 3:  # Current game
        embed_data = _get_current_game(bot, guild_id)[0]
        embed_template.add_field(name=embed_data[0],
                                 value=embed_data[1],
                                 inline=False)

    elif context.index == 4:  # Next game(s)
        embed_data = _get_next_games(bot, context.arguments[0], guild_id)
        for name, value in embed_data:
            embed_template.add_field(name=name, value=value, inline=False)

    elif context.index == 5:  # Search
        embed_data = _search_games(bot,
                                   context.arguments[0],
                                   guild_id=guild_id)
        embed_template.add_field(name=embed_data[0],
                                 value=embed_data[1],
                                 inline=False)

    elif context.index == 6:  # Notify
        game = _search_games(bot, context.arguments[0], return_game=True)
        response.content = _toggle_notification(bot,
                                                game,
                                                context,
                                                use_channel='channel'
                                                in context.options)
        embed_template = None

    response.embed = embed_template
    return response
Example #4
0
async def get_response(bot, context):
    """Gets a response given the parsed input.

    context attributes:
    bot -- A reference to the bot itself.
    message -- The discord.message object obtained from on_message.
    base -- The base command name that immediately follows the invoker.
    subcommand -- The subcommand that matched the parameters.
    index -- The index of the found subcommand.
    options -- A dictionary representing the options and potential positional
        arguments that are attached to them.
    arguments -- A list of strings that follow the syntax of the blueprint
        index for arguments following the options.
    keywords -- Another list of strings that holds all option keywords. These
        can be used to prevent database conflicts with user commands.
    cleaned_content -- Simply the message content without the invoker.
    """

    # This is what the bot will say when it returns from this function.
    # The response object can be manipulated in many ways. The attributes of
    #   the response will be passed into the send function.
    response = Response()
    response.content = ''  # Default

    # Set to True if you want your message read with /tts (not recommended).
    response.tts = False  # Default

    # The message type dictates how the bot handles your returned message.
    #
    # NORMAL - Normal. The issuing command can be edited.
    # PERMANENT - Message is not added to the edit dictionary.
    # REPLACE - Deletes the issuing command after 'extra' seconds. Defaults
    #   to 0 seconds if 'extra' is not given.
    # ACTIVE - The message reference is passed back to the function defined
    #   with 'extra_function'. If 'extra_function' is not defined, it will call
    #   plugin.handle_active_message.
    # INTERACTIVE - Assembles reaction buttons given by extra['buttons'] and
    #   calls 'extra_function' whenever one is pressed.
    # WAIT - Wait for event. Calls 'extra_function' with the result, or None
    #   if the wait timed out.
    #
    # Only the NORMAL message type can be edited.
    response.message_type = MessageTypes.NORMAL  # Default

    # The extra variable is used for some message types.
    response.extra = None  # Default

    # Initially, check to make sure that you've matched the proper command.
    # If there is only one command specified, this may not be necessary.
    index, options, arguments = context.index, context.options, context.arguments
    if context.base == 'mycommand':

        # Then, the subcommand index will tell you which command syntax was
        #   satisfied. The order is the same as was specified initially.
        if index == 0:  # myoption
            response.content = "You called the first subcommand!"
            # Do other stuff...

        elif index == 1:  # custom/attached
            # To see if an optional option was included in the command, use:
            if 'custom' in options:
                response.content += "You included the \"custom\" flag!\n"
                # Do stuff relevant to this flag here...

            # To get the parameter attached to an option, simply access it from
            #   the options dictionary.
            if 'attached' in options:
                response.content += "The attached parmeter: {}\n".format(options['attached'])

            # In case somebody was looking for the help...
            if len(options) == 0:
                invoker = utilities.get_invoker(bot, guild=context.guild)
                response.content += ("You didn't use either flag...\n"
                                     "For help, try `{}help mycommand`".format(invoker))

        elif index == 2:  # trailing arguments
            # If arguments are specified as trailing, they will be in a list.
            response.content += "The list of trailing arguments: {}".format(arguments)

        elif index == 3:  # grouped arguments
            # All arguments are grouped together as the first element
            response.message_type = MessageTypes.PERMANENT
            response.content = ("You can't edit your command here.\n"
                                "Single grouped argument: {}").format(arguments[0])

        elif index == 4:  # complex
            # This mixes elements of both examples seen above.
            response.content = ("The argument attached to the complex "
                                "option: {}").format(options['complex'])
            if 'other' in options:
                response.content += "\nThe other option has attached: {}".format(options['other'])
            response.content += "\nLastly, the trailing arguments: {}".format(arguments)

        elif index == 5:  # (Very slow) marquee
            # This demonstrates the active message type.
            # Check active_marquee to see how it works.
            response.message_type = MessageTypes.ACTIVE
            response.extra_function = active_marquee  # The function to call
            response.extra = arguments[0]  # The text to use
            response.content = "Setting up marquee..."  # This will be shown first

    # Here's another command base.
    elif context.base == 'myothercommand':

        if index == 0:  # keyword checker
            text = arguments[0]
            if not text:
                response.content = "You didn't say anything...\n"
            else:
                response.content = "This is your input: {}\n".format(text)
                if text in context.keywords:
                    response.content += "Your input was in the list of keywords!\n"
                else:
                    response.content += ("Your input was not in the list of keywords. "
                                         "They are: {}\n").format(context.keywords)
            response.message_type = MessageTypes.PERMANENT
            response.delete_after = 15
            response.content += "This message will self destruct in 15 seconds."

        else:  # impossible command???
            raise CBException("This is a bug! You should never see this message.")

    elif context.base == 'wait':
        response.message_type = MessageTypes.WAIT
        # The extra attribute should consist of a dictionary containing the
        #   event and any other kwargs. Most notably, you will likely want to
        #   define the check used in wait_for.
        response.extra_function = custom_interaction
        response.extra = {
            'event': 'message',
            'kwargs': {
                'timeout': 30,  # Default 300
                'check': lambda m: m.author == context.author,
            }
        }
        response.content = "Say something, {}.".format(context.author)

    return response