示例#1
0
 async def list_rockets(self, channel, tz):
     report_channel = ReportChannel(self.bot, channel)
     data = await report_channel.get_all_rockets()
     if not data:
         return await channel.send("No Team GO Rocket Invasions reported!")
     wild_list = []
     for wild_id in data:
         wild = Rocket.instances.get(wild_id)
         if not wild:
             continue
         wild_list.append(await wild.summary_str(tz))
     number = len(wild_list)
     page_size = 10
     pages = ceil(number / page_size)
     ins = list(range(0, number, page_size))
     color = channel.guild.me.color
     for i in range(pages):
         if pages == 1:
             title = "Current Team GO Rocket Invasions"
         else:
             title = f"Current Team GO Rocket Invasions (Page {i+1} of {pages})"
         content = "\n\n".join(wild_list[ins[i]:ins[i] + page_size])
         embed = formatters.make_embed(title=title,
                                       content=content,
                                       msg_colour=color)
         await channel.send(embed=embed)
示例#2
0
 async def from_mod(cls, mod: Rocket):
     name = mod.name
     if isinstance(mod.location, Pokestop):
         directions_url = await mod.location.url()
         directions_text = await mod.location._name()
     else:
         directions_url = mod.location.url
         directions_text = mod.location._name + " (Unknown Location)"
     fields = {}
     if hasattr(mod, 'pokemon'):
         pkmn = [Pokemon(mod.bot, x) for x in mod.pokemon]
         pkmn_names = [await x.name() for x in pkmn]
         fields['Pokemon'] = "\n".join(pkmn_names)
     fields['Location'] = f'[{directions_text}]({directions_url})'
     img_url = mod.img_url()
     reporter = mod.guild.get_member(mod.reporter_id)
     if not reporter:
         reporter = await mod.guild.fetch_member(mod.reporter_id)
     reporter = reporter.display_name
     footer = f"Reported by {reporter}"
     reportdt = datetime.fromtimestamp(mod.created)
     color = mod.guild.me.color
     embed = formatters.make_embed(title=f"{name} Report",
                                   msg_colour=color,
                                   thumbnail=img_url,
                                   fields=fields,
                                   footer=footer)
     embed.timestamp = reportdt
     return cls(embed)
示例#3
0
文件: map_cog.py 项目: Baviaan/Meowth
 async def whereis(self, ctx, *, location: POI):
     """Returns a Google Maps link to a Gym or Pokestop."""
     if not isinstance(location, POI):
         return await ctx.error('Location not found')
     display_str = await location.display_str()
     url = await location.url()
     content = f"{display_str}\n[Directions]({url})"
     if isinstance(location, Gym):
         thumbnail = (
             "https://raw.githubusercontent.com/"
             "FoglyOgly/Meowth/new-core/meowth/images/misc/gym.png")
         if await location._exraid():
             title = "EX Raid Gym"
         else:
             title = "Gym"
     elif isinstance(location, Pokestop):
         title = "Pokestop"
         thumbnail = (
             "https://raw.githubusercontent.com/"
             "FoglyOgly/Meowth/new-core/meowth/images/misc/pokestop.png")
     color = ctx.guild.me.color
     embed = formatters.make_embed(title=title,
                                   content=content,
                                   thumbnail=thumbnail,
                                   msg_colour=color)
     await ctx.send(embed=embed)
示例#4
0
 async def from_trade(cls, trade):
     want_list = []
     want_emoji = formatters.mc_emoji(len(trade.wanted_pkmn))
     for i in range(len(trade.wanted_pkmn)):
         if isinstance(trade.wanted_pkmn[i], Pokemon):
             want_str = f'{want_emoji[i]}: {await trade.wanted_pkmn[i].trade_display_str()}'
         elif trade.wanted_pkmn[i] == 'any':
             want_str = f'{want_emoji[i]}: Any Pokemon'
         elif trade.wanted_pkmn[i] == 'obo':
             want_str = f'{want_emoji[i]}: Other Pokemon'
         want_list.append(want_str)
     offer_list = []
     for i in range(len(trade.offered_pkmn)):
         offer_str = await trade.offered_pkmn[i].trade_display_str()
         offer_list.append(offer_str)
     title = "Pokemon Trade"
     footer = trade.lister_name
     footer_url = trade.lister_avy
     fields = {
         'Wants': "\n".join(want_list),
         'Offers': "\n".join(offer_list)
     }
     if len(offer_list) == 1:
         thumbnail = await trade.offered_pkmn[0].sprite_url()
     else:
         thumbnail = None
     color = trade.guild.me.color
     embed = formatters.make_embed(title=title,
                                   footer=footer,
                                   footer_icon=footer_url,
                                   icon=Trade.icon_url,
                                   fields=fields,
                                   thumbnail=thumbnail,
                                   msg_colour=color)
     return cls(embed)
示例#5
0
 async def dex_embed(self):
     num = await self._num()
     description = await self.description()
     category = await self.category()
     height = await self._HeightM()
     weight = await self._WeightKg()
     weaks = await self.weaknesses_emoji()
     resists = await self.resistances_emoji()
     pkmn_name = await self.name()
     if await self._shiny_available():
         pkmn_name += " :sparkles:"
     type_emoji = await self.type_emoji()
     sprite_url = await self.sprite_url()
     # color = await self.color()
     fast_moves = await self.fast_moves()
     fast_move_names = []
     legacy_fast_move_names = []
     for x in fast_moves:
         move = Move(self.bot, x)
         name = await move.name()
         emoji = await move.emoji()
         if await move.is_legacy(self.id):
             legacy_fast_move_names.append(name + '* ' + emoji)
         else:
             fast_move_names.append(name + ' ' + emoji)
     fast_move_names.extend(legacy_fast_move_names)
     fast_moves_str = "\n".join(fast_move_names)
     charge_moves = await self.charge_moves()
     charge_move_names = []
     legacy_charge_move_names = []
     for x in charge_moves:
         move = Move(self.bot, x)
         name = await move.name()
         emoji = await move.emoji()
         if await move.is_legacy(self.id):
             legacy_charge_move_names.append(name + '* ' + emoji)
         else:
             charge_move_names.append(name + ' ' + emoji)
     charge_move_names.extend(legacy_charge_move_names)
     charge_moves_str = "\n".join(charge_move_names)
     embed_desc = f"#{num} {pkmn_name} - {category}\n```{description}```"
     weather_str = await self.weather_str()
     # author_icon = type icon TODO
     fields = {
         "Height/Weight": f"{height} m/{weight} kg",
         "Boosted in:": weather_str,
         "Weaknesses": weaks,
         "Resistances": resists,
         "Fast Moves": fast_moves_str,
         "Charge Moves": charge_moves_str
     }
     embed = formatters.make_embed(
         # icon = author_icon,
         title="Pokedex Entry",
         content=embed_desc,
         # msg_colour = color,
         thumbnail=sprite_url,
         fields=fields,
         footer='* denotes legacy move')
     return embed
示例#6
0
    async def get_additional_info(self, channel, user):
        content = "Specify information about the wild spawn! You can give as many of the below options as you like."
        info_options = """
            Set CP to #### -
            Set IVs Atk/Def/Sta -
            Set Level to ## - 
            Set Moveset to MOVENAME -
            Set Gender - 
            """
        info_strings = """
            `cp####`
            `iv##/##/##`
            `lvl##`
            `@movename`
            `male` or `female`
            """
        fields = {'Options': info_options, '\u200b': info_strings}
        embed = formatters.make_embed(content=content, fields=fields)
        msg = await channel.send(embed=embed)

        def check(m):
            return m.author == user and m.channel == channel

        try:
            reply = await self.bot.wait_for('message', check=check, timeout=60)
        except asyncio.TimeoutError:
            return await msg.delete()
        else:
            args = reply.content.lower().split()
            for arg in args:
                await self.pkmn.get_info_from_arg(self.bot, arg)
            weather = await self.weather()
            if weather == 'NO_WEATHER':
                weather = None
            pkmn = await self.pkmn.validate('wild', weather=weather)
            self.pkmn = pkmn
            new_embed = (await WildEmbed.from_wild(self)).embed
            try:
                await reply.delete()
            except:
                pass
            try:
                await msg.delete()
            except:
                pass
            for idstring in self.message_ids:
                chn, msg = await ChannelMessage.from_id_string(
                    self.bot, idstring)
                if not msg:
                    continue
                old_embed = msg.embeds[0]
                old_fields = old_embed.to_dict()['fields']
                new_fields = new_embed.to_dict()['fields']
                if old_fields == new_fields:
                    badmsg = await channel.send(
                        'No valid arguments were received!')
                    await asyncio.sleep(10)
                    return await badmsg.delete()
                await msg.edit(embed=new_embed)
示例#7
0
    async def from_research(cls, research):
        bot = research.bot
        task = research.task
        location = research.location
        reward = research.reward

        if isinstance(task, Task):
            task = task.id
        else:
            task = task.id.split('/', 1)[1]

        if '/' in reward:
            reward = ItemReward(research.bot, reward)
            desc = await reward.description()
            thumbnail = reward.img_url
        elif reward == 'unknown_encounter':
            desc = "Unknown Encounter"
            thumbnail = ("https://raw.githubusercontent.com/"
                "FoglyOgly/Meowth/new-core/meowth/images/misc/unknown_encounter.png")
        else:
            pkmn = Pokemon(bot, reward)
            desc = await pkmn.name()
            if await pkmn._shiny_available():
                desc += " :sparkles:"
            type_emoji = await pkmn.type_emoji()
            desc += f" {type_emoji}"
            thumbnail = await pkmn.sprite_url()

        if isinstance(location, POI):
            directions_url = await location.url()
            directions_text = await location._name()
        else:
            directions_url = location.url
            directions_text = location._name + " (Unknown Pokestop)"
        
        title = "Field Research Report"
        fields = {
            'Pokestop': f"[{directions_text}]({directions_url})",
            'Task': task,
            'Reward': desc + "\n<:silph:548259248442703895>Research tasks and rewards provided by [The Silph Road](https://thesilphroad.com/research-tasks)"
        }
        reporter = research.guild.get_member(research.reporter_id)
        if not reporter:
            reporter = await research.guild.fetch_member(research.reporter_id)
        color = research.guild.me.color
        reporter_name = reporter.display_name
        reporter_avy = reporter.avatar_url
        footer = f"Reported by {reporter_name} • Expires"
        icon_url = ("https://raw.githubusercontent.com/"
                "FoglyOgly/Meowth/new-core/meowth/images/misc/field-research.png")
        embed = formatters.make_embed(title=title, thumbnail=thumbnail,
            fields=fields, footer=footer, footer_icon=reporter_avy, icon=icon_url, msg_colour=color)
        embed.timestamp = datetime.utcfromtimestamp(research.expires_at)
        return cls(embed)
示例#8
0
 async def expire_research(self):
     if self.completed_by:
         research_score = 1 + len(self.completed_by)
     else:
         research_score = 1
     score_table = self.bot.dbi.table('scoreboard')
     query = score_table.query
     query.where(guild_id=self.guild_id)
     query.where(user_id=self.reporter_id)
     old_data = await query.get()
     if not old_data:
         d = {
             'guild_id': self.guild_id,
             'user_id': self.reporter_id,
             'raid': 0,
             'wild': 0,
             'trade': 0,
             'research': 0,
             'service': 0
         }
     else:
         d = dict(old_data[0])
     d['research'] += research_score
     insert = score_table.insert
     insert.row(**d)
     await insert.commit(do_update=True)
     expire_embed = formatters.make_embed(title='This Research Task has expired!')
     for msgid in self.message_ids:
         chn, msg = await ChannelMessage.from_id_string(self.bot, msgid)
         try:
             await msg.edit(embed=expire_embed)
             await msg.clear_reactions()
         except:
             pass
         try:
             del Research.by_message[msgid]
         except:
             pass
     data = self._data
     await data.delete()
     try:
         del Research.instances[self.id]
     except:
         pass
示例#9
0
def make_research_list_embeds(research_list, color, page_size=8):
    number = len(research_list)
    pages = ceil(number/page_size)
    embeds = []
    for i in range(pages):
        if pages == 1:
            title = "Current Research"
        else:
            title = f'Current Research (Page {i+1} of {pages})'
        if len(research_list) > page_size:
            content = "\n\n".join(research_list[:page_size])
            research_list = research_list[page_size:]
        else:
            content = "\n\n".join(research_list)
        embed = formatters.make_embed(title=title, content=content, msg_colour=color)
        embeds.append(embed)
    if len(max(embeds, key=len)) > 2048 and page_size > 2:
        embeds = make_research_list_embeds(research_list, color, page_size=page_size-2)
    return embeds
示例#10
0
 async def make_offer_embed(trader, listed_pokemon, offer):
     if isinstance(listed_pokemon, Pokemon):
         listed_str = await listed_pokemon.trade_display_str()
     elif listed_pokemon == 'any':
         listed_str = "Any Pokemon"
     if isinstance(offer, Pokemon):
         offer_str = await offer.trade_display_str()
         offer_url = await offer.sprite_url()
     elif offer == 'any':
         offer_str = "Any Pokemon"
         offer_url = None
     return formatters.make_embed(title="Pokemon Trade Offer",
                                  icon=Trade.icon_url,
                                  fields={
                                      "You Offered": listed_str,
                                      "They Offer": offer_str
                                  },
                                  inline=True,
                                  footer=trader.display_name,
                                  footer_icon=trader.avatar_url_as(
                                      format='png', size=256),
                                  thumbnail=offer_url)
示例#11
0
 async def despawned_embed(self):
     name = self.name
     embed = formatters.make_embed(content=f"This {name} has ended!",
                                   footer="Ended")
     embed.timestamp = datetime.fromtimestamp(self.end)
     return embed
示例#12
0
 async def from_wild(cls, wild: Wild):
     name = await wild.pkmn.name()
     type_emoji = await wild.pkmn.type_emoji()
     shiny_available = await wild.pkmn._shiny_available()
     if shiny_available:
         name += ' :sparkles:'
     quick_move = Move(
         wild.bot, wild.pkmn.quickMoveid) if wild.pkmn.quickMoveid else None
     charge_move = Move(
         wild.bot,
         wild.pkmn.chargeMoveid) if wild.pkmn.chargeMoveid else None
     if quick_move:
         quick_name = await quick_move.name()
         quick_emoji = await quick_move.emoji()
     else:
         quick_name = "Unknown"
         quick_emoji = ""
     if charge_move:
         charge_name = await charge_move.name()
         charge_emoji = await charge_move.emoji()
     else:
         charge_name = "Unknown"
         charge_emoji = ""
     moveset = f"{quick_name} {quick_emoji}| {charge_name} {charge_emoji}"
     weather = await wild.weather()
     weather = Weather(wild.bot, weather)
     is_boosted = await wild.pkmn.is_boosted(weather.value)
     cp_str = str(wild.pkmn.cp) if wild.pkmn.cp else "Unknown"
     if is_boosted:
         cp_str += " (Boosted)"
     img_url = await wild.pkmn.sprite_url()
     lvlstr = str(wild.pkmn.lvl) if wild.pkmn.lvl else "?"
     attiv = str(wild.pkmn.attiv) if wild.pkmn.attiv is not None else "?"
     defiv = str(wild.pkmn.defiv) if wild.pkmn.defiv is not None else "?"
     staiv = str(wild.pkmn.staiv) if wild.pkmn.staiv is not None else "?"
     iv_str = f'{lvlstr}/{attiv}/{defiv}/{staiv}'
     if isinstance(wild.location, POI):
         directions_url = await wild.location.url()
         directions_text = await wild.location._name()
     else:
         directions_url = wild.location.url
         directions_text = wild.location._name + " (Unknown Location)"
     fields = {
         'Pokemon': f'{name} {type_emoji}',
         'Location': f'[{directions_text}]({directions_url})',
         'CP': cp_str,
         "Level/IVs: Lvl/Atk/Def/Sta": iv_str,
         'Moveset': moveset.strip(),
         'Gender':
         wild.pkmn.gender.title() if wild.pkmn.gender else "Unknown"
     }
     reporter = wild.guild.get_member(wild.reporter_id)
     if not reporter:
         reporter = await wild.guild.fetch_member(wild.reporter_id)
     reporter = reporter.display_name
     footer = f"Reported by {reporter}"
     reportdt = datetime.fromtimestamp(wild.created)
     color = wild.guild.me.color
     embed = formatters.make_embed(title="Wild Spawn Report",
                                   msg_colour=color,
                                   thumbnail=img_url,
                                   fields=fields,
                                   footer=footer)
     embed.timestamp = reportdt
     return cls(embed)
示例#13
0
 async def despawned_embed(self):
     name = await self.pkmn.name()
     embed = formatters.make_embed(content=f"This {name} has despawned!",
                                   footer="Despawned")
     embed.timestamp = datetime.fromtimestamp(self.end)
     return embed