Esempio n. 1
0
 def get_syntax_error(e):
     """Format a syntax error to send to the user.
     Returns a string representation of the error formatted as a codeblock.
     """
     if e.text is None:
         return box('{0.__class__.__name__}: {0}'.format(e), lang="py")
     return box('{0.text}{1:>{0.offset}}\n{2}: {0}'
                ''.format(e, '\n^',
                          type(e).__name__),
                lang="py")
Esempio n. 2
0
async def tc(ctx, idnum=None):
    owner = ctx.message.author
    if idnum:
        server = discord.utils.get(bot.servers, id=idnum)
        if server:
            await _get_texts_channels(server, owner, ctx)
        else:
            await ctx.bot.say(
                "**Invalid server ID or i am not in that server :)**")
    else:
        msg = ""
        servers = sorted(bot.servers, key=lambda s: s.name)
        for i, server in enumerate(servers, 1):
            msg += "{}: {}\n{}\n".format(i, server.name, server.id)
        msg += "\nchoose a server for get all texts channels."
        for page in pagify(msg, delims=["\n"]):
            await ctx.bot.say(box(page))
            await asyncio.sleep(1.0)
        msg = await ctx.bot.wait_for_message(author=owner, timeout=30)
        if msg is not None:
            try:
                msg = int(msg.content.strip())
                server = servers[msg - 1]
            except ValueError:
                await ctx.bot.say("**You must enter a number.**")
            except IndexError:
                await ctx.bot.say("**Index out of range.**")
            else:
                try:
                    await _get_texts_channels(server, owner, ctx)
                except discord.Forbidden:
                    await ctx.bot.say("**Errors**".format(server.id))
        else:
            await ctx.bot.say("Response timed out.")
Esempio n. 3
0
async def vm(ctx, idnum=None):
    owner = ctx.message.author
    if idnum:
        server = discord.utils.get(bot.servers, id=idnum)
        if server:
            await _voice_members(server, owner, ctx)
        else:
            await ctx.bot.say("I'm not in that server")
    else:
        msg = ""
        servers = sorted(bot.servers, key=lambda s: s.name)
        for i, server in enumerate(servers, 1):
            msg += "{}: {}\n{}\n".format(i, server.name, server.id)
        msg += "\nchoose a server for list Voice_Members , just type its number."
        for page in pagify(msg, delims=["\n"]):
            await ctx.bot.say(box(page))
            await asyncio.sleep(1.5)
        msg = await ctx.bot.wait_for_message(author=owner, timeout=30)
        if msg is not None:
            try:
                msg = int(msg.content.strip())
                server = servers[msg - 1]
            except ValueError:
                await ctx.bot.say("**You must enter a number.**")
            except IndexError:
                await ctx.bot.say("**Index out of range.**")
            else:
                try:
                    await _voice_members(server, owner, ctx)
                except discord.Forbidden:
                    await ctx.bot.say(
                        "**Sorry , there is an error , check your log please"
                        " for {}**".format(server.id))
        else:
            await ctx.bot.say("Response timed out.")
Esempio n. 4
0
    async def rolecount(self, ctx):
        """Shows server role count."""

        list = len([
            x.name for x in ctx.message.server.role_hierarchy
            if x.name != "@everyone"
        ])
        await self.bot.say(box(list, "Prolog"))
Esempio n. 5
0
    async def voicechannels(self, ctx):
        """Lists only servers voice channels."""

        list = "\n".join([
            c.name for c in ctx.message.server.channels
            if c.type == discord.ChannelType.voice
        ])
        for page in pagify(list, ["\n"], shorten_by=7, page_length=2000):
            await self.bot.say(box(page))
Esempio n. 6
0
    async def roles(self, ctx):
        """Lists all servers roles."""

        list = "\n".join([
            x.name for x in ctx.message.server.role_hierarchy
            if x.name != "@everyone"
        ])
        for page in pagify(list, ["\n"], shorten_by=7, page_length=2000):
            await self.bot.say(box(page))
Esempio n. 7
0
    async def on_message(self, message):

        if message.channel.id in self.sessions:


            if not self.prefix:
                check_folder()
                check_file()

            if message.content.startswith(self.prefix) and message.author.id == ownerid:

            if message.content.startswith(self.prefix) and message.author.id == owner:

                command = message.content.split(self.prefix)[1]

                if not command:
                    return

                if command == 'exit()' or command == 'quit':
                    await self.bot.send_message(message.channel, 'Exiting.')
                    self.sessions.remove(message.channel.id)
                    return

                if command.lower().find("apt-get install") != -1 and command.lower().find("-y") == -1:
                    command = "{} -y".format(command)

                try:
                    output = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT).communicate()[0]
                    error = False
                except CalledProcessError as e:
                    output = e.output
                    error = True

                shell = output.decode('utf_8')

                if shell == "" and not error:
                    return

                shell = sub('/bin/sh: .: ', '', shell)
                if "\n" in shell[:-2]:
                    shell = '\n' + shell

                user = "******".format(getuser(), uname()[1], getcwd().replace('/home/' + getuser(), "~"))

                for page in pagify(user + shell, shorten_by=12):
                    await self.bot.send_message(message.channel, box(page, 'Bash'))
Esempio n. 8
0
    async def _show_cogs(self, ctx):
        """
            {command_prefix}cogs

        Shows loaded/unloaded cogs.
        """
        loaded = [c.__module__.split(".")[1] for c in self.bot.cogs.values()]
        unloaded = [c for c in _list_cogs() if c not in loaded]

        if not unloaded:
            unloaded = ["None"]

        msg = ("+ Loaded\n"
               "{}\n\n"
               "- Unloaded\n"
               "{}"
               "".format(", ".join(sorted(loaded)),
                         ", ".join(sorted(unloaded))))
        for page in pagify(msg, [" "], shorten_by=16):
            await ctx.send(box(page.lstrip(" "), lang="diff"))
Esempio n. 9
0
    async def usercount(self, ctx):
        """Shows server member count."""

        list = len([m.name for m in ctx.message.server.members if not m.bot])
        await self.bot.say(box(list, "Prolog"))
Esempio n. 10
0
    async def botlist(self, ctx):
        """Lists all bots in the server."""

        list = "\n".join([m.name for m in ctx.message.server.members if m.bot])
        for page in pagify(list, ["\n"], shorten_by=7, page_length=2000):
            await self.bot.say(box(page))
Esempio n. 11
0
    async def channels(self, ctx):
        """Lists all servers channels."""

        list = "\n".join([c.name for c in ctx.message.server.channels])
        for page in pagify(list, ["\n"], shorten_by=7, page_length=2000):
            await self.bot.say(box(page))