Ejemplo n.º 1
0
 async def unload(self, ctx, *cogs: str):
     """unload a cog"""
     try:
         for cog in cogs:
             self.bot.unload_extension('cogs.' + cog.replace('cogs.', '').replace('.py', ''))
             await ctx.send(f"unloaded {cog}")
     except:
         for p in pagify(traceback.format_exc()):
             await ctx.send(f"```py\n{p}\n```")
Ejemplo n.º 2
0
    async def addemoji(self, ctx, emoji: typing.Union[int, str] = None):
        """Add an emoji from our list!"""
        data = json_mngr().read('./data/emojis.json')
        if emoji:
            for name in data.keys():
                if isinstance(emoji, int) and emoji == data[name]['id']:
                    te = discord.utils.get(self.bot.emojis, id=emoji)
                    if te is None:
                        raise GetError(
                            code=1,
                            reason='This emoji is unavailable (NotFound)')
                    await self.addemoji_method(ctx, emoji=te, data=data)
                else:
                    tea = discord.utils.get(self.bot.emojis, name=emoji)
                    for te in tea:
                        if isinstance(te, discord.Emoji):
                            steven = await ctx.send(
                                f"Is this the correct emoji? [y/n]\nPreview: {te}"
                            )
                            try:

                                def check(m):
                                    return (m.author, m.channel) == (
                                        ctx.author, ctx.channel) and (
                                            'y' in m.content.lower()
                                            or 'y' in m.content.lower())

                                bob = await self.bot.wait_for('message',
                                                              check=check,
                                                              timeout=120)
                            except asyncio.TimeoutError:
                                return await steven.edit(content="Timed out.")
                            if bob.content.lower().startswith('n'):
                                await bob.edit(content="Finding another one.")
                                continue
                            elif bob.content.lower().startswith('y'):
                                return await self.addemoji_method(ctx,
                                                                  data=data,
                                                                  emoji=te)
                        else:
                            return await ctx.send(
                                "An unknown error caused this emoji to go unavailable\n"
                                "Error code #0002")
                    else:
                        raise GetError(code=3, reason="Emoji not found")
        else:
            topag = ""
            for emoji in data.keys():
                topag += f"Emoji name: {emoji}\nSource guild: {emoji['guild']}\nPreview: <{emoji['url']}>\n\n"
            if len(topag) > 1900:
                for page in pagify(topag, escape_stuff=True, page_length=1900):
                    await ctx.send(page, delete_after=30)
            else:
                return await ctx.send(
                    discord.utils.escape_markdown(
                        discord.utils.escape_mentions(topag)))
Ejemplo n.º 3
0
async def r(ctx, cog):
    """reload a cog."""
    bot.loaded_c0gs = 9999999
    cog = cog.replace('cogs.', '').replace('.py', '')
    s = time.time()
    try:
        bot.reload_extension(f'cogs.{cog}')
        e = time.time()
        ot = round(e - s, 2)
        await ctx.send(f'\U0001f44c reloaded {cog} in {ot} seconds.')
    except commands.ExtensionNotLoaded:
        bot.load_extension(f'cogs.{cog}')
        e = time.time()
        ot = round(e - s, 2)
        await ctx.send(f'\U0001f44c loaded {cog} in {ot} seconds.')
    except commands.ExtensionNotFound:
        await ctx.send(f'\U0000270b {cog} was not found!')
    except Exception as e:
        for page in pagify(e, page_length=1800):
            await ctx.send(f'```py\n{page}\n```')
Ejemplo n.º 4
0
    async def source(self, ctx, *, command: str):
        """Get the source code of a command!"""
        self.bot.owner = discord.utils.get(self.bot.users,
                                           id=self.bot.owner_id)
        eek = self.bot.owner

        async def _c(msg):
            def check(r):
                return r.author in [
                    ctx.author, eek
                ] and r.channel == ctx.channel and r.content.lower(
                ) == 'delete'

            r = await self.bot.wait_for('message', check=check)
            await msg.delete()

        async def do_mass(msg: list):
            def check(r):
                return r.author == ctx.author and r.channel == ctx.channel and r.content.lower(
                ) == 'delete'

            r = await self.bot.wait_for('message', check=check)
            for m in msg:
                await m.delete()

        command = self.bot.get_command(command)
        if command is None:
            return await ctx.send('no command found')
        source = getsource(command.callback).replace('`', '\u200B`\u200B')
        if len(source) < 1750:
            msg = await ctx.send("```py\n" + source + "\n```")  #1
            await _c(msg)
        else:
            messages = []
            async with ctx.channel.typing():
                for page in pagify(source, page_length=1750):
                    X = await ctx.send(f"```py\n{page}\n```")  # 2
                    await asyncio.sleep(1)
                    messages.append(X)
            await do_mass(messages)
Ejemplo n.º 5
0
    async def charinfo(self,
                       ctx,
                       *,
                       characters: typing.Union[discord.Emoji,
                                                str] = '\u200B'):
        """Shows you information about a number of characters.
		no spam pls
		"""
        if isinstance(characters, discord.Emoji):
            cmd = self.bot.get_command('ei')
            return await ctx.invoke(cmd, emoji=characters)

        def to_string(c):
            digit = f'{ord(c):x}'
            name = unicodedata.name(c, 'Name not found.')
            return f'`\\U{digit:>08}`: {name} - {c}'

        msg = '\n'.join(map(to_string, characters))
        if len(msg) > 2000:
            for p in pagify(msg):
                await ctx.send(p)
            return
        await ctx.send(msg)
Ejemplo n.º 6
0
async def all(ctx):
    s = time.time()
    for cog in cogss:
        print(cog)
        if cog.lower() == 'cogs.an':
            continue
        try:
            bot.reload_extension(f'{cog}')
            e = time.time()
            ot = round(e - s, 2)
            await ctx.send(f'\U0001f44c reloaded {cog} in {ot} seconds.')
        except commands.ExtensionNotLoaded:
            bot.load_extension(f'{cog}')
            e = time.time()
            ot = round(e - s, 2)
            await ctx.send(f'\U0001f44c loaded {cog} in {ot} seconds.')

        except commands.ExtensionNotFound:
            await ctx.send(f'\U0000270b {cog} was not found!')
        except Exception as e:
            for page in pagify(e, page_length=1800):
                await ctx.send(f'```py\n{page}\n```')
        await asyncio.sleep(1)
Ejemplo n.º 7
0
 async def __raw(self, ctx):
     """Return the raw Snipes Data."""
     from utils.page import pagify
     stuff = str(self.snipes)
     for page in pagify(stuff):
         await ctx.send(page)
Ejemplo n.º 8
0
    async def _eval(self, ctx, *, body: str):
        """Evaluates a code"""
        await self.log(ctx, body)
        await ctx.message.add_reaction(self.loading)
        env = {
            'bot': self.bot,
            'ctx': ctx,
            'channel': ctx.channel,
            'author': ctx.author,
            'guild': ctx.guild,
            'message': ctx.message,
            'command': ctx.command,
            '_': self._last_result,
            'asyncio': asyncio,
            'discord': discord,
            'datetime': datetime,
            'os': os,
            'random': random,
            'time': time
        }

        env.update(globals())

        body = self.cleanup_code(body)
        stdout = io.StringIO()

        to_compile = f'async def func():\n{textwrap.indent(body, "  ")}'

        try:
            exec(to_compile, env)
        except Exception as e:
            await ctx.message.clear_reactions()
            await ctx.message.add_reaction(self.error)
            for page in pagify(f'{e.__class__.__name__}: {e}'.replace(
                    '`', '\u200b`')):
                await ctx.send(f'```py\n{page}\n```')
            return

        try:
            func = env['func']
        except:
            pass
        try:
            with redirect_stdout(stdout):
                ret = await func()
        except Exception as e:
            value = stdout.getvalue()
            try:
                await ctx.message.clear_reactions()
            except:
                pass
            await ctx.message.add_reaction(self.error)
            for p in pagify(f'{value}{traceback.format_exc()}'.replace(
                    '`', '\u200b`')):
                await ctx.send(f'```py\n{p}\n```')
        else:
            value = stdout.getvalue()
            try:
                await ctx.message.clear_reactions()
            except:
                pass
            try:
                await ctx.message.add_reaction(self.success)
            except:
                pass
            if ret is None:
                if value:
                    for p in pagify(value.replace('`', '\u200b`')):
                        await ctx.send(f'```py\n{p}\n```')
                else:
                    await ctx.send('No Value to return.', delete_after=2.5)
            else:
                self._last_result = ret
                for p in pagify(f'{value}{ret}'.replace('`', '\u200b`')):
                    await ctx.send(f'```py\n{p}\n```')