async def convert(cls, ctx, arg): arg = arg.lower() choices = ['grunt', 'arlo', 'cliff', 'sierra', 'giovanni'] name = fuzzymatch.get_match(choices, arg) if name[0]: index = choices.index(name[0]) return cls(index) else: raise RocketNotFound
async def from_arg(cls, bot, arg): names = bot.dbi.table('move_names') name_list = await names.query('name').get_values() match = fuzzymatch.get_match(name_list, arg) if match[0]: match_id = await names.query('moveid').where(name=match[0] ).get_value() return cls(bot, match_id) else: raise MoveNotFound
async def convert(cls, ctx, arg): weather_names = ctx.bot.dbi.table('weather_names') day_names = await weather_names.query('name').get_values() night_names = await weather_names.query('night_name').get_values() names = day_names + night_names names = [x for x in names if x] match = fuzzymatch.get_match(names, arg) if match[0]: if match[0] in day_names: match_query = weather_names.query('weather').where(name=match[0]) elif match[0] in night_names: match_query = weather_names.query('weather').where(night_name=match[0]) matched_weather = await match_query.get_value() return cls(ctx.bot, matched_weather) else: raise
async def from_arg(cls, bot, command_name, chn, user_id, arg, coords=None): pokedex = bot.dbi.table('pokedex') form_names = bot.dbi.table('form_names') id_list = [] name_list = await pokedex.query('name').get_values() form_list = await form_names.query('name').get_values() form_list = [x.strip('()') for x in form_list] args = arg.lower().split() shiny = False form = None gender = None attiv = None defiv = None staiv = None lvl = None quickMoveid = None chargeMoveid = None chargeMove2id = None cp = None for arg in args: if arg.startswith('cp') and len(arg) > 2 and arg[2].isdigit(): cp = int(arg[2:]) elif arg.startswith('@'): arg = arg[1:] move = await Move.from_arg(bot, arg) if move: if await move._fast(): quickMoveid = move.id else: if not chargeMoveid: chargeMoveid = move.id else: chargeMove2id = move.id else: pass elif arg == 'shiny': shiny = True elif arg == 'male': gender = 'MALE' elif arg == 'female': gender = 'FEMALE' elif arg.startswith('iv') and len(arg) > 2 and arg[2].isdigit(): iv_arg = arg[2:] attiv, defiv, staiv = iv_arg.split('/', maxsplit=2) attiv = int(attiv) defiv = int(defiv) staiv = int(staiv) if attiv > 15: attiv = 15 elif attiv < 0: attiv = 0 if defiv > 15: defiv = 15 elif defiv < 0: defiv = 0 if staiv > 15: staiv = 15 elif staiv < 0: staiv = 0 elif arg.startswith('lvl') and len(arg) > 3 and arg[3].isdigit(): lvl = float(arg[3:]) double = lvl * 2 rounded = round(double) if rounded < 2: rounded = 2 elif rounded > 80: rounded = 80 valid_level = rounded / 2 lvl = valid_level else: id_set = set() form_name = fuzzymatch.get_match(form_list, arg) if form_name[0]: forms = bot.dbi.table('form_names').query('formid').where( name=f"({form_name[0]})") form = await forms.get_value() query = bot.dbi.table('forms').query('pokemonid').where( formid=form) ids = await query.get_values() id_set.update(ids) names = fuzzymatch.get_matches(name_list, arg, scorer='ratio') if names: names = [x[0] for x in names] query = bot.dbi.table('pokedex').query('pokemonid').where( pokedex['name'].in_(names)) ids = await query.get_values() id_set.update(ids) if not id_set: raise PokemonNotFound else: id_list.append(id_set) possible_ids = set.intersection(*id_list) if not possible_ids: raise PokemonNotFound else: mons = [(cls(bot, x)) for x in possible_ids] for x in mons: if await x._mega_available(): megas = await x.get_megas() mega_mons = [(cls(bot, x)) for x in megas] mons += mega_mons if command_name in [ 'raid', 'interested', 'coming', 'here', 'remote', 'invite' ]: possible_mons = [ x for x in mons if await x._raid_available(coords) ] elif command_name == 'wild': possible_mons = [x for x in mons if await x._wild_available()] elif command_name == 'rocket': possible_mons = [x for x in mons if x.form == 63] elif command_name == 'research': possible_mons = [ x for x in mons if await x._research_available() ] elif command_name == 'boss': possible_mons = [ x for x in mons if x.form != 63 and x.form != 64 ] elif command_name == 'trade': possible_mons = [x for x in mons if await x._trade_available()] else: possible_mons = mons impossible_mons = [x for x in mons if x not in possible_mons] if len(possible_mons) == 0: raise PokemonInvalidContext(impossible_mons) elif len(possible_mons) == 1: pkmn = possible_mons[0] else: length = len(possible_mons) possible_names = [(await mon.name()) for mon in possible_mons] react_list = formatters.mc_emoji(length) choice_dict = dict(zip(react_list, possible_mons)) display_dict = dict(zip(react_list, possible_names)) embed = formatters.mc_embed(display_dict) multi = await chn.send( 'Multiple possible Pokemon found! Please select from the following list.', embed=embed) payload = await formatters.ask(bot, [multi], user_list=[user_id], react_list=react_list) pkmn = choice_dict[str(payload.emoji)] await multi.delete() if form: query = bot.dbi.table('forms').query('formid').where( pokemonid=pkmn.id) possible_forms = await query.get_values() if form in possible_forms: pkmn.form = form pkmn.shiny = shiny pkmn.attiv = attiv pkmn.defiv = defiv pkmn.staiv = staiv pkmn.lvl = lvl pkmn.quickMoveid = quickMoveid pkmn.chargeMoveid = chargeMoveid pkmn.chargeMove2id = chargeMove2id pkmn.cp = cp pkmn.gender = gender return pkmn
async def lure(self, ctx, kind, *, location: Pokestop): """Report a lured Pokestop. **Arguments** *kind:* Glacial, Mossy or Magnetic *location:* The location of the lure. If *location* is the name of a known Pokestop, directions will be accurate. Otherwise Meowth just Googles the supplied *location* plus the name of the city. **Example:** `!lure glacial city park`""" word_list = ["glacial", "mossy", "magnetic"] result = fuzzymatch.get_match(word_list, kind) kind = result[0] if not kind: raise commands.BadArgument() mod_id = next(snowflake.create()) new_mod = Modifier(mod_id, self.bot, ctx.guild.id, ctx.author.id, location, kind) name = new_mod.name react_list = list(new_mod.react_list.values()) embed = (await ModEmbed.from_mod(new_mod)).embed want = Want(ctx.bot, kind, ctx.guild.id) mention = await want.mention() if mention: reportcontent = mention + " - " else: reportcontent = "" coming = '🚗' despawned = '💨' report_channels = [] report_channel = ReportChannel(ctx.bot, ctx.channel) if isinstance(location, Pokestop): loc_name = await location._name() loc_id = 'pokestop/' + str(location.id) channel_list = await location.get_all_channels('wild') report_channels.extend(channel_list) else: loc_name = location._name loc_id = f'{location.city}/{location.arg}' reportcontent += f'{name} reported at {loc_name}! Use {coming} if you are on the way and {despawned} if it has ended.' if report_channel not in report_channels: report_channels.append(report_channel) for channel in report_channels: try: reportmsg = await channel.channel.send(reportcontent, embed=embed) for react in react_list: if isinstance(react, int): react = self.bot.get_emoji(react) await reportmsg.add_reaction(react) new_mod.message_ids.append( f"{reportmsg.channel.id}/{reportmsg.id}") except: continue for idstring in new_mod.message_ids: Modifier.by_message[idstring] = new_mod await new_mod.upsert() self.bot.loop.create_task(new_mod.monitor_status())
def match(self, data_list, item): result = fuzzymatch.get_match(data_list, item)[0] if not result: return None return result