Пример #1
0
    def has_prefix_helper(self, config_prefix, actual_prefix, expected):
        self.prop.return_value = f'{actual_prefix}foo bar it'
        type(self.message).content = self.prop

        ret_val = botutils.has_prefix({'prefix': config_prefix}, self.message)
        self.assertEqual(ret_val, expected)
        self.prop.assert_called_once_with()
Пример #2
0
async def handle(client, config, message):
    if not has_prefix(config, message):
        return

    content = get_content_without_prefix(config, message)
    potential_roles = content.split()

    if potential_roles[0] != 'giveroles':
        return

    client.send_typing(message.channel)

    if len(message.author.roles) > 1:
        await client.send_message(message.channel, 'You already have a role.')
        return

    roles = [x.lower() for x in potential_roles[1:]]

    role_objects = __get_valid_roles(config, message, roles)
    if len(role_objects) > 0:
        await client.add_roles(message.author, *role_objects)
        await client.send_message(
            message.channel,
            'Roles added: %s' % ', '.join(map(lambda x: x.name, role_objects)))
    else:
        await client.send_message(message.channel, 'No valid roles specified')
Пример #3
0
async def handle(client, config, message):
    if not has_prefix(config, message):
        return

    content = get_content_without_prefix(config, message)
    args = content.split()

    if args[0] != 'spoiler':
        return
    if len(args) > 1:
        await __handle_spoiler(client, message, content[len(args[0]) + 1:])
Пример #4
0
async def handle(client, config, message):
    if message.author.top_role.name not in __VALID_ROLES:
        return

    if not has_prefix(config, message):
        return

    content = get_content_without_prefix(config, message)
    args = content.split()

    if args[0] == 'clear':
        await __handle_clear(client, message, args)
Пример #5
0
async def handle(client, config, message):
    if not has_prefix(config, message):
        return

    content = get_content_without_prefix(config, message)
    args = content.split()

    if args[0] != 'fortnite':
        return
    if len(args) < 2:
        await client.send_message(
            message.channel,
            'Usage: !fortnite [epic games name] <platform:optional pc, xbl or psn>'
        )
        return

    platform = 'pc'
    num_args = len(args)
    username = '******'.join(args[1:])
    if num_args > 2 and args[-1] in ['pc', 'xbl', 'psn']:
        platform = args[-1]
        username = '******'.join(args[1:-1])

    # p2 -> solo
    # p10 -> duo
    # p9 -> squad
    url = f'https://api.fortnitetracker.com/v1/profile/{platform}/{username}'
    request = requests.get(
        url, headers={'TRN-Api-Key': config['fortnite_tracker_apikey']})

    if not request.ok:
        await client.send_message(message.channel,
                                  "Error: A request error returned.")
        return

    r_result = json.loads(request.content)

    error = r_result.get('error')
    if error is not None:
        await client.send_message(message.channel, f"Error: {error}")
    else:
        await client.send_message(message.channel,
                                  embed=__create_embed_from_result(
                                      r_result, platform))