Esempio n. 1
0
File: cog.py Progetto: scragly/Eevee
    async def guild(self, ctx, *, guild: Guild):
        """Lookup Guild info"""
        if guild:
            if guild.unavailable:
                embed = make_embed(msg_type='error',
                                   title='Guild found, but unavailable!')
            else:
                embed = make_embed(msg_type='info',
                                   thumbnail=guild.icon_url_as(format='png'))
                date_created = datetime.strftime(guild.created_at,
                                                 "UTC %Y/%m/%d %H:%M")
                basic_info = (f"ID: {guild.id}\n"
                              f"Owner: {guild.owner}\n"
                              f"Created: {date_created}\n"
                              f"Region: {guild.region}\n")
                embed.add_field(name=guild.name,
                                value=basic_info,
                                inline=False)
                stats_info = (f"Members: {guild.member_count}\n"
                              f"Roles: {len(guild.roles)}\n"
                              f"Text Channels: {len(guild.text_channels)}\n"
                              f"Channel Categories: {len(guild.categories)}")
                embed.add_field(name='Stats', value=stats_info, inline=False)

                guild_perms = guild.me.guild_permissions
                req_perms = ctx.bot.req_perms
                perms_compare = guild_perms >= req_perms
                core_dir = ctx.bot.core_dir
                data_dir = os.path.join(core_dir, '..', 'data')
                data_file = 'permissions.json'
                perms_info = f"Value: {guild_perms.value}\n"
                perms_info += f"Meets Requirements: {perms_compare}\n"
                with open(os.path.join(data_dir, data_file), "r") as perm_json:
                    perm_dict = json.load(perm_json)

                for perm, bitshift in perm_dict.items():
                    if bool((req_perms.value >> bitshift) & 1):
                        if bool((guild_perms.value >> bitshift) & 1):
                            perms_info += ":white_small_square:  {}\n".format(
                                perm)
                        else:
                            perms_info += ":black_small_square:  {}\n".format(
                                perm)
                embed.add_field(name='Permissions',
                                value=perms_info,
                                inline=False)

                bot_list = [m for m in guild.members if m.bot]
                bot_info = f"Bots: {len(bot_list)}\n"
                if 1 <= len(bot_list) <= 20:
                    for bot in bot_list:
                        online = bot.status == discord.Status.online
                        status = "\U000025ab" if online else "\U000025aa"
                        bot_info += f"{status} {bot}\n"
                embed.add_field(name='Bots', value=bot_info, inline=False)

        else:
            embed = make_embed(msg_type='error', title='Guild not found')
        await ctx.send(embed=embed)
Esempio n. 2
0
File: cog.py Progetto: scragly/Eevee
    async def check_perms(
        self,
        ctx,
        member_or_role: Multi(discord.Member, discord.Role),
        guild_or_channel: Multi(discord.Guild, discord.TextChannel,
                                discord.VoiceChannel) = None):
        """Show permissions of a member or role for the guild and channel."""
        if guild_or_channel:
            if isinstance(guild_or_channel, discord.Guild):
                guild_perms = ctx.guild.me.guild_permissions
        else:
            guild_perms = ctx.guild.me.guild_permissions
            if isinstance(member_or_role, discord.Member):
                chan_perms = ctx.channel.permissions_for(member_or_role)
            else:
                return await ctx.send("Role Permissions aren't done yet.")

        req_perms = ctx.bot.req_perms
        g_perms_compare = guild_perms >= req_perms
        c_perms_compare = chan_perms >= req_perms
        core_dir = ctx.bot.core_dir
        data_dir = os.path.join(core_dir, '..', 'data')
        data_file = 'permissions.json'
        msg = f"**Guild:**\n{ctx.guild}\nID {ctx.guild.id}\n"
        msg += f"**Channel:**\n{ctx.channel}\nID {ctx.channel.id}\n"
        msg += "```py\nGuild     | Channel\n"
        msg += "----------|----------\n"
        msg += "{} | {}\n".format(guild_perms.value, chan_perms.value)
        msg += "{0:9} | {1}```".format(str(g_perms_compare),
                                       str(c_perms_compare))
        y_emj = ":white_small_square:"
        n_emj = ":black_small_square:"

        with open(os.path.join(data_dir, data_file), "r") as perm_json:
            perm_dict = json.load(perm_json)

        for perm, bitshift in perm_dict.items():
            if bool((req_perms.value >> bitshift) & 1):
                guild_bool = bool((guild_perms.value >> bitshift) & 1)
                channel_bool = bool((chan_perms.value >> bitshift) & 1)
                guild_e = y_emj if guild_bool else n_emj
                channel_e = y_emj if channel_bool else n_emj
                msg += f"{guild_e} {channel_e}  {perm}\n"

        try:
            if chan_perms.embed_links:
                embed = make_embed(msg_type='info',
                                   title=f'Permissions for {member_or_role}',
                                   content=msg)
                await ctx.send(embed=embed)
            else:
                await ctx.send(msg)
        except discord.errors.Forbidden:
            embed = make_embed(msg_type='info',
                               title=f'Permissions for {member_or_role}',
                               content=msg)
            await ctx.author.send(embed=embed)
Esempio n. 3
0
    async def cleanup(self, ctx, after_msg_id: int, channel_id: int = None):
        after_msg = await ctx.get.message(after_msg_id)
        channel = ctx.channel
        if channel_id:
            channel = ctx.get.channel(channel_id)

        def is_eevee(msg):
            return msg.author == ctx.bot.user

        try:
            deleted = await channel.purge(after=after_msg,
                                          check=is_eevee,
                                          bulk=True)
        except discord.Forbidden:
            deleted = await channel.purge(after=after_msg,
                                          check=is_eevee,
                                          bulk=False)

        del_count = len(deleted)

        embed = utils.make_embed(
            msg_type='success',
            title=f"Deleted {del_count} message{'s' if del_count > 1 else ''}")

        result_msg = await ctx.send(embed=embed)
        await asyncio.sleep(3)
        await result_msg.delete()
Esempio n. 4
0
File: cog.py Progetto: scragly/Eevee
 async def runas(self, ctx, member: discord.Member, *, new_cmd):
     """Run a command as a different member."""
     if await ctx.bot.is_owner(member):
         await ctx.send(embed=make_embed(
             msg_type='error', title='No, you may not run as owner.'))
         return
     ctx.message.content = new_cmd
     ctx.message.author = member
     await ctx.bot.process_commands(ctx.message)
Esempio n. 5
0
File: bot.py Progetto: scragly/Eevee
    async def on_ready(self):
        intro = "Eevee - Pokemon Go Bot for Discord"
        intro_deco = "{0}\n{1}\n{0}".format('=' * len(intro), intro)
        if not self.launch_time:
            self.launch_time = datetime.utcnow()
        if not self.launcher:
            print(intro_deco)
        if self.from_restart:
            print("We're back!\n")
        else:
            print("We're on!\n")
        print(f"Eevee Version: {self.version}\n")
        if self.debug:
            print(f"Python Version: {self.py_version}")
            print(f"Discord.py Version: {self.dpy_version}")
            print(f"Platform: {self.platform}\n")
        guilds = len(self.guilds)
        users = sum([g.member_count for g in self.guilds])
        if guilds:
            print(f"Servers: {guilds}")
            print(f"Members: {users}")
        else:
            print("I'm not in any server yet, so be sure to invite me!")
        if self.invite_url:
            print(f"\nInvite URL: {self.invite_url}\n")

        if self.from_restart:
            table = self.dbi.table('restart_savedata')
            table.query.order_by(table['restart_snowflake'], asc=False)
            table.query.limit(1)
            last_restart = (await table.query.get())[0]

            embed = make_embed(title='Restart Complete.', msg_type='success')

            guild = self.get_guild(last_restart['restart_guild'])

            if guild:
                channel = guild.get_channel(last_restart['restart_channel'])

                if channel:
                    original_message = await channel.get_message(
                        last_restart['restart_message'])
                    return await original_message.edit(embed=embed)

            else:
                channel = self.get_user(last_restart['restart_by'])

            if not channel:
                channel = self.get_user(self.owner)
                if not channel:
                    return self.logger.error('Bot owner not found.')

            return await channel.send(embed=embed)
Esempio n. 6
0
    def embed(self, entries=6):
        if not self.results:
            return None

        top = [r.details for r in self.results[:3]]
        rest = [
            "\n\n**Other Results:**",
        ]
        rest.extend([r.title_only for r in self.results[3:entries]])

        return make_embed(
            title=f'Google Search for "{self.query}"',
            title_url=self.URL_FORMAT.format(quote(self.query)),
            content='\n\n'.join(top) + '\n'.join(rest),
            icon="https://image.flaticon.com/teams/slug/google.jpg")
Esempio n. 7
0
    def __init__(self, ctx, entries, *, per_page=12, show_entry_count=True,
                 title='Help', msg_type='help'):
        self.bot = ctx.bot
        self.entries = entries
        self.message = ctx.message
        self.channel = ctx.channel
        self.author = ctx.author
        self.per_page = per_page
        pages, left_over = divmod(len(self.entries), self.per_page)
        if left_over:
            pages += 1
        self.maximum_pages = pages
        self._mention = re.compile(r'<@\!?([0-9]{1,19})>')
        self.embed = make_embed(title=title, msg_type=msg_type)
        self.default_icon = self.embed.author.icon_url
        self.paginating = len(entries) > per_page
        self.show_entry_count = show_entry_count
        self.total = len(entries)
        self.reaction_emojis = [
            ('\N{BLACK LEFT-POINTING DOUBLE TRIANGLE WITH VERTICAL BAR}',
             self.first_page),
            ('\N{BLACK LEFT-POINTING TRIANGLE}', self.previous_page),
            ('\N{BLACK RIGHT-POINTING TRIANGLE}', self.next_page),
            ('\N{BLACK RIGHT-POINTING DOUBLE TRIANGLE WITH VERTICAL BAR}',
             self.last_page),
            ('\N{BLACK SQUARE FOR STOP}', self.stop_pages),
            ('\N{LEDGER}', self.show_index),
        ]

        if ctx.guild is not None:
            self.permissions = self.channel.permissions_for(ctx.guild.me)
        else:
            self.permissions = self.channel.permissions_for(ctx.bot.user)

        if not self.permissions.embed_links:
            raise CannotPaginate('Bot does not have embed links permission.')

        if not self.permissions.send_messages:
            raise CannotPaginate('Bot cannot send messages.')

        if self.paginating:
            if not self.permissions.add_reactions:
                raise CannotPaginate(
                    'Bot does not have add reactions permission.')
            if not self.permissions.read_message_history:
                raise CannotPaginate(
                    'Bot does not have Read Message History permission.')
Esempio n. 8
0
File: cog.py Progetto: scragly/Eevee
    async def pd_pokemon(self, pokemon, only_type=False, only_raid=False):
        pkmn_no = str(pokemon.id).zfill(3)
        pkmn_url = ('https://raw.githubusercontent.com/FoglyOgly/'
                    f'Meowth/master/images/pkmn/{pkmn_no}_.png')
        pkmn_colour = await url_color(pkmn_url)
        embed = make_embed(image=pkmn_url, msg_colour=pkmn_colour)

        types_str = ' '.join(self.get_type_emoji(t) for t in pokemon.types)

        if only_type:
            header = (f'{types_str}\n#{pkmn_no} - {pokemon.name.capitalize()}'
                      ' - Type Effectiveness')
            description = self.pd_type_info(pokemon)
        elif only_raid:
            header = (f'{types_str}\n#{pkmn_no} - {pokemon.name.capitalize()}'
                      ' - Raid Info')
            if pokemon.is_raid:
                description = self.pd_raid_info(pokemon)
            else:
                description = "This Pokemon does not currently appear in raids."

        else:
            header = f'{types_str} #{pkmn_no} - {pokemon.name.capitalize()}'
            description = code(self.get_flavor(pokemon.id).replace('\n', ' '))

        embed.add_field(name=header, value=description, inline=False)

        if only_type or only_raid:
            return embed

        embed.add_field(name='TYPE EFFECTIVENESS',
                        value=self.pd_type_info(pokemon),
                        inline=False)

        if pokemon.is_raid:
            embed.add_field(name='RAID INFO',
                            value=self.pd_raid_info(pokemon),
                            inline=False)

        return embed
Esempio n. 9
0
File: cog.py Progetto: scragly/Eevee
    async def raid(self, ctx, *, arg: Multi(int, Pokemon)):
        """Return Raid Info"""
        if isinstance(arg, int):
            raid_level = arg
            raid_egg_url = ctx.bot.raid_eggs[f'{raid_level}']['img_url']
            raid_egg_colour = await url_color(raid_egg_url)
            pkmn_list = []
            for k, v in ctx.bot.raid_pokemon.items():
                level = v['level']
                if level == raid_level:
                    pkmn_list.append(k)
            embed = make_embed(msg_type='info',
                               title=f'Level {raid_level} Raid List',
                               msg_colour=raid_egg_colour,
                               content=', '.join(pkmn_list))
            await ctx.send(embed=embed)

        elif isinstance(arg, Pokemon):
            embed = await self.pd_pokemon(arg, only_raid=True)
            await ctx.send(embed=embed)

        elif isinstance(arg, str):
            await self.did_you_mean(ctx, arg)
Esempio n. 10
0
 def embed(self):
     return make_embed(title=self.title,
                       title_url=self.title_url,
                       content=self.info)
Esempio n. 11
0
 def embed(self):
     return make_embed(
         title=self.title,
         title_url=self.origin_url,
         image=self.url,
         icon="https://image.flaticon.com/teams/slug/google.jpg")
Esempio n. 12
0
 async def _help(self, ctx, title, content=None):
     embed = utils.make_embed(title=title, content=content, msg_type='help')
     await ctx.send(embed=embed)
Esempio n. 13
0
 async def _success(self, ctx, title, content=None):
     embed = utils.make_embed(title=title,
                              content=content,
                              msg_type='success')
     await ctx.send(embed=embed)
Esempio n. 14
0
 async def _warning(self, ctx, title, content=None):
     embed = utils.make_embed(title=title,
                              content=content,
                              msg_type='warning')
     await ctx.send(embed=embed)