Esempio n. 1
0
 async def emoji(self, ctx, emoji):
     emoji_obj = ctx.get.emoji(emoji)
     if not emoji_obj:
         emojis = {e.name: e for e in ctx.bot.emojis}
         match = get_match(list(emojis.keys()), emoji, score_cutoff=80)[0]
         emoji_obj = emojis[match] if match else None
     if not emoji_obj:
         return await ctx.error('Emoji not found.')
     await ctx.send(f"{emoji_obj}")
     try:
         await ctx.message.delete()
     except discord.HTTPException:
         pass
Esempio n. 2
0
    async def convert(cls, ctx, argument):
        argument = argument.lower()

        team_names_table = ctx.bot.dbi.table('team_names')
        team_names_query = team_names_table.query.select('team_name')
        team_names = await team_names_query.get_values()
        match = get_match(team_names, argument, score_cutoff=80)[0]
        if match:
            query = team_names_table.query('team_id')
            query.where(team_name=match)
            team_id = await query.get_value()
        else:
            return

        return cls(ctx.bot, ctx.guild.id, team_id)
Esempio n. 3
0
    def get_pokemon(cls, bot, argument, guild=None):
        argument = argument.lower()
        if 'shiny' in argument:
            shiny = True
            argument = argument.replace('shiny', '').strip()
        else:
            shiny = False
        if 'alolan' in argument:
            alolan = True
            argument = argument.replace('alolan', '').strip()
        else:
            alolan = False

        form = None
        detected_forms = []
        form_check = None
        candidates = [f for f in Pokemon._form_list if f in argument]
        for c in candidates:
            detected_forms.append(c)
            argument = argument.replace(c, '').strip()

        # this logic will fail for pokemon with multiple word name (e.g. Tapu Koko et al)
        arg_split = argument.split()
        if len(arg_split) > 1:
            argument = arg_split[0]
            form_check = arg_split[1]

        p_obj = Pokemon.find_obj(argument)
        if not p_obj:
            pkmn_list = [p for p in Pokemon._pkmn_dict]
            match = utils.get_match(pkmn_list, argument, score_cutoff=80)[0]
        else:
            match = p_obj['name']

        if not match:
            return None

        form_list = Pokemon._form_dict.get(match, [])
        if form_check and form_check in form_list:
            detected_forms.append(form_check)
        forms = [d for d in detected_forms if d in form_list]
        if forms:
            form = ' '.join(forms)

        return cls(bot, str(match), guild, shiny=shiny, alolan=alolan, form=form)
Esempio n. 4
0
    def get_pokemon(cls, ctx, argument):
        argument = argument.lower()
        if 'shiny' in argument.lower():
            shiny = True
            argument = argument.replace('shiny', '').strip()
        else:
            shiny = False
        if 'alolan' in argument.lower():
            alolan = True
            argument = argument.replace('alolan', '').strip()
        else:
            alolan = False
        form_list = [
            'normal', 'sunny', 'rainy', 'snowy', 'sunglasses', 'ash', 'party',
            'witch', 'santa', 'summer', 'defense', 'normal', 'attack', 'speed',
            '1', '2', '3', '4', '5', '6', '7', '8', '!', '?'
        ]
        form_list.extend(' ' + c for c in ascii_lowercase)
        f = next((x for x in form_list if x in argument.lower()), None)
        if f:
            form = f.strip()
            argument = argument.replace(f, '').strip()
        else:
            form = None
        if argument.isdigit():
            try:
                match = ctx.bot.pkmn_info['pokemon_list'][int(argument) - 1]
            except IndexError:
                return None
        else:
            pkmn_list = ctx.bot.pkmn_info['pokemon_list']
            match = utils.get_match(pkmn_list, argument)[0]

        if not match:
            return None

        return cls(ctx.bot,
                   str(match),
                   ctx.guild,
                   shiny=shiny,
                   alolan=alolan,
                   form=form)
Esempio n. 5
0
    async def whois(self, ctx, ign):
        """Lookup player by in-game name."""

        user_table = ctx.bot.dbi.table('users')
        query = user_table.query('ign')
        ign_list = await query.get_values()
        ign_list = [x for x in ign_list if x]
        if not ign_list:
            return await ctx.send(f"No match for {ign}")
        match = get_match(ign_list, ign)[0]
        if match:
            meowthuser = await MeowthUser.from_ign(ctx.bot, match)
            member = ctx.guild.get_member(meowthuser.user.id)
            if not member:
                member = await ctx.guild.fetch_member(meowthuser.user.id)
            if member:
                name = member.display_name
            else:
                name = str(meowthuser.user)
            return await ctx.send(f'Closest match for {ign}: {name}')
        else:
            return await ctx.send(f"No match for {ign}")
Esempio n. 6
0
 def location_match(self, name, locations, threshold=75, isPartial=True, limit=None):
     match = utils.get_match([l.name for l in locations], name, threshold, isPartial, limit)
     if not isinstance(match, list):
         match = [match]
     return [(l, score) for l in locations for match_name, score in match if l.name == match_name]
Esempio n. 7
0
 def gym_match(self, gym_name, gyms):
     return utils.get_match(list(gyms.keys()), gym_name)
Esempio n. 8
0
    async def convert(cls, ctx, argument):
        """Returns a pokemon that matches the value
        of the argument that's being converted.

        It first will check if it's a valid ID, and if not, will perform
        a fuzzymatch against the list of Pokemon names.

        Returns
        --------
        :class:`Pokemon` or :class:`dict`
            If there was a close or exact match, it will return a valid
            :class:`Pokemon`.
            If the match is lower than 80% likeness, it will return a
            :class:`dict` with the following keys:
                * ``suggested`` - Next best guess based on likeness.
                * ``original`` - Original value of argument provided.

        Raises
        -------
        :exc:`discord.ext.commands.BadArgument`
            The argument didn't match a Pokemon ID or name.
        """
        argument = argument.lower()
        if 'shiny' in argument.lower():
            shiny = True
            argument = argument.replace('shiny', '').strip()
        else:
            shiny = False
        if 'alolan' in argument.lower():
            alolan = True
            argument = argument.replace('alolan', '').strip()
        else:
            alolan = False
        form_list = [
            'normal', 'sunny', 'rainy', 'snowy', 'sunglasses', 'ash', 'party',
            'witch', 'santa', 'summer', 'defense', 'normal', 'attack', 'speed',
            '1', '2', '3', '4', '5', '6', '7', '8', '!', '?'
        ]
        form_list.extend(' ' + c for c in ascii_lowercase)
        f = next((x for x in form_list if x in argument.lower()), None)
        if f:
            form = f.strip()
            argument = argument.replace(f, '').strip()
        else:
            form = None
        if argument.isdigit():
            try:
                match = ctx.bot.pkmn_info['pokemon_list'][int(argument) - 1]
                score = 100
            except IndexError:
                raise commands.errors.BadArgument(
                    'Pokemon ID "{}" not valid'.format(argument))
        else:
            pkmn_list = ctx.bot.pkmn_info['pokemon_list']
            match, score = utils.get_match(pkmn_list, argument)
        if match:
            if score >= 80:
                result = cls(ctx.bot,
                             str(match),
                             ctx.guild,
                             shiny=shiny,
                             alolan=alolan,
                             form=form)
            else:
                result = {'suggested': str(match), 'original': argument}

        if not result:
            raise commands.errors.BadArgument(
                'Pokemon "{}" not valid'.format(argument))

        return result