示例#1
0
文件: information.py 项目: PgBiel/sbt
    async def _information_bot(self, ctx: commands.Context):
        """
        display sbt's information
        """

        user = ctx.bot.user
        authors = ctx.bot.__authors__
        authors = ", ".join([n for (n, u) in authors])
        maintainers = ctx.bot.__maintainers__
        maintainers = ", ".join([n for (n, u) in maintainers])
        version = ctx.bot.__version__

        color = ctx.me.color if ctx.guild else discord.Color.blurple()
        e = discord.Embed(color=color, title="Bot Information")

        changes = await self._commits(count=3)
        if (changes):
            e.add_field(name="Recent Changes", value=changes, inline=False)

        e.add_field(name="User", value="{0} ({0.id})".format(user), inline=False)
        e.add_field(name="Authors", value=authors)
        e.add_field(name="Maintainers", value=maintainers)
        e.add_field(name="Version", value=version)
        e.set_footer(
            text = "{0} | {1}".format(
                ctx.author,
                format.humanize_datetime()
            ),
            icon_url=ctx.author.avatar_url
        )

        await ctx.send(embed=e)
示例#2
0
文件: information.py 项目: PgBiel/sbt
    async def _now(self, ctx: commands.Context):
        """
        display the current time in utc
        """

        time = format.humanize_datetime()
        await ctx.send(time)
示例#3
0
文件: information.py 项目: PgBiel/sbt
    async def _information_message(self, ctx: commands.Context, message: int):
        """
        display message information
        """

        try:
            message = await ctx.channel.fetch_message(message)
        except (discord.errors.NotFound) as e:
            await ctx.bot.send_help(ctx)
            return

        mentions = list()
        
        if (message.mention_everyone):
            mentions.append("@everyone")

        for (member) in message.mentions:
            mentions.append(member.mention)

        for (role) in message.role_mentions:
            mentions.append(role.mention)

        for (channel) in message.channel_mentions:
            mentions.append(channel.mention)

        color = ctx.me.color if ctx.guild else discord.Color.blurple()
        e = discord.Embed(color=color, title="Message Information")
        e.add_field(name="Content", value=message.content, inline=False)
        e.add_field(name="ID", value="{0.id}".format(message))
        e.add_field(name="Author", value="{0.name} ({0.id})".format(message.author))
        e.add_field(name="Timestamp", value=format.humanize_datetime(message.created_at), inline=False)
        e.add_field(name="TTS", value=message.tts)
        e.add_field(name="Type", value=message.type)

        if (mentions):
            e.add_field(name="Mentions [{0}]".format(len(mentions)), value=", ".join(mentions))

        e.set_footer(
            text = "{0} | {1}".format(
                ctx.author,
                format.humanize_datetime()
            ),
            icon_url=ctx.author.avatar_url
        )

        await ctx.send(embed=e)
示例#4
0
文件: beta.py 项目: PgBiel/sbt
    async def _parse_date(self, ctx: commands.Context, *, date: str):
        """
        date parser
        """

        try:
            date = parse.Date.parse(date)
        except (error.ParserError) as e:
            await ctx.message.add_reaction("\U0000274e")
            await ctx.send(format.inline(e.original))
        else:
            await ctx.message.add_reaction("\U00002705")
            await ctx.send(format.inline(format.humanize_datetime(date)))
示例#5
0
    def _command_embedinator(self, ctx, command: commands.command) -> list:
        color = ctx.me.color if ctx.guild else discord.Color.blurple()
        e = discord.Embed(color=color)
        e.set_author(name=self._format_signature(ctx, command))

        if (command.help):
            e.description = command.help

        e.set_footer(
            text="{0} | {1}".format(
                ctx.author,
                format.humanize_datetime(),
            ),
            icon_url=ctx.author.avatar_url,
        )

        return [e]
示例#6
0
文件: information.py 项目: PgBiel/sbt
    async def _since(self, ctx: commands.Context, date: parse.PastDate):
        """
        display distance between today and a date

        examples:
            `>since 01/01/19`
        """

        now = datetime.datetime.utcnow()
        today = datetime.date(now.year, now.month, now.day)
        days = -(date - today).days

        message = "{0} since {1}".format(
            format.humanize_seconds(days * 86400),
            format.humanize_datetime(date)
        )

        await ctx.send(message)
示例#7
0
文件: information.py 项目: PgBiel/sbt
    async def _until(self, ctx: commands.Context, date: parse.FutureDate):
        """
        display distance between today and a date

        examples:
            `>until 02-22-2050`
        """
        
        now = datetime.datetime.utcnow()
        today = datetime.date(now.year, now.month, now.day)
        days = (date - today).days

        message = "{0} until {1}".format(
            format.humanize_seconds(days * 86400),
            format.humanize_datetime(date)
        )

        await ctx.send(message)
示例#8
0
文件: information.py 项目: PgBiel/sbt
    async def _discriminator(self, ctx: commands.Context, discriminator: typing.Optional[str]):
        """
        display all users with a discriminator

        defaults to your own

        examples:
            `>discriminator`      :: display all users with your discriminator
            `>discriminator 0001` :: display all users with the `0001` discriminator
        """

        if (not discriminator):
            discriminator = ctx.author.discriminator

        if ((not len(discriminator) == 4) or (not discriminator.isdigit())):
            await ctx.bot.send_help(ctx)
            return

        members = list()
        for (guild) in ctx.bot.guilds:
            for (member) in guild.members:
                if (member.discriminator == discriminator):
                    members.append(member)

        if (not members):
            await ctx.send("no results")
            return

        message = ""
        for (member) in members:
            message += "{0}\n".format(member)

        color = ctx.me.color if ctx.guild else discord.Color.blurple()
        e = discord.Embed(color=color)
        e.add_field(name="Members", value=message)
        e.set_footer(
            text="{0} | {1}".format(
                ctx.author,
                format.humanize_datetime()
            ),
            icon_url=ctx.author.avatar_url
        )

        await ctx.send(embed=e)
示例#9
0
文件: moderation.py 项目: PgBiel/sbt
    async def _role_members(self, ctx: commands.Context, role: discord.Role):
        """
        display a role's members
        """

        if (not role.members):
            await ctx.send("none.")
            return

        members = [m.mention for m in role.members]

        e = discord.Embed(color=role.color)
        e.set_author(name=role.name)
        e.add_field(name="Members", value="\n".join(members))
        e.set_footer(text="{0} | {1}".format(ctx.author,
                                             format.humanize_datetime()),
                     icon_url=ctx.author.avatar_url)

        await ctx.send(embed=e)
示例#10
0
文件: information.py 项目: PgBiel/sbt
    async def _version(self, ctx: commands.Context):
        """
        display sbt's version
        """

        sbt_version = format._version(ctx.bot.__version__)
        dpy_version = format._version(discord.__version__)

        color = ctx.me.color if ctx.guild else discord.Color.blurple()
        e = discord.Embed(color=color)
        e.add_field(name="SBT Version", value=sbt_version)
        e.add_field(name="discord.py Version", value=dpy_version)
        e.set_footer(
            text = "{0} | {1}".format(
                ctx.author,
                format.humanize_datetime()
            ),
            icon_url=ctx.author.avatar_url
        )

        await ctx.send(embed=e)
示例#11
0
文件: information.py 项目: PgBiel/sbt
    async def _invite(self, ctx: commands.Context):
        """
        display sbt's invite links
        """

        sbt_guild = "not yet"
        sbt_oauth = ctx.bot._settings.oauth

        color = ctx.me.color if ctx.guild else discord.Color.blurple()
        e = discord.Embed(color=color)
        e.add_field(name="SBT Support Guild", value=sbt_guild)
        e.add_field(name="SBT OAuth Invite", value=sbt_oauth)
        e.set_footer(
            text = "{0} | {1}".format(
                ctx.author,
                format.humanize_datetime()
            ),
            icon_url=ctx.author.avatar_url
        )

        await ctx.send(embed=e)
示例#12
0
文件: owner.py 项目: PgBiel/sbt
    async def _contact(self, ctx: commands.Context, *, message: str):
        """
        contact sbt's support team

        example:
            `>contact there was an error when i used <command> :(`
        """

        channel = ctx.bot.get_channel(ctx.bot._channels.contact)

        e = discord.Embed(title="Contact #{0}".format(1),
                          description=message,
                          color=channel.guild.me.color)
        e.add_field(name="Guild", value=ctx.guild.id, inline=True)
        e.add_field(name="Channel", value=ctx.channel.id, inline=True)
        e.add_field(name="Author", value=ctx.author.id, inline=True)
        e.set_footer(text="{0} | {1}".format(ctx.author,
                                             format.humanize_datetime()),
                     icon_url=ctx.author.avatar_url)

        await channel.send(embed=e)
        await ctx.send("done.")
示例#13
0
文件: information.py 项目: PgBiel/sbt
    async def _statistics(self, ctx: commands.Context):
        """
        display sbt's statictics
        """

        uptime = (datetime.datetime.utcnow() - ctx.bot._uptime).total_seconds()
        uptime = format.humanize_seconds(uptime, long=False)
        latency = format.humanize_seconds(ctx.bot.latency, long=False)
        version = ctx.bot.__version__

        users = 0
        for (user) in ctx.bot.users:
            if (not user.bot):
                users += 1

        channels = 0
        for (channel) in ctx.bot.get_all_channels():
            if (not isinstance(channel, discord.CategoryChannel)):
                channels += 1

        guilds = len(ctx.bot.guilds)

        color = ctx.me.color if ctx.guild else discord.Color.blurple()
        e = discord.Embed(color=color, title="Statistics")
        e.add_field(name="Uptime", value=uptime)
        e.add_field(name="Latency", value=latency)
        e.add_field(name="Version", value=version)
        e.add_field(name="Users", value=users)
        e.add_field(name="Channels", value=channels)
        e.add_field(name="Guilds", value=guilds)
        e.set_footer(
            text = "{0} | {1}".format(
                ctx.author,
                format.humanize_datetime()
            ),
            icon_url=ctx.author.avatar_url
        )

        await ctx.send(embed=e)
示例#14
0
文件: information.py 项目: PgBiel/sbt
    async def _code(self, ctx: commands.Context):
        """
        files, lines, characters
        """

        files_ = [
            *glob.glob("*.py"),
            *glob.glob("utils\\*.py"),
            *glob.glob("modules\\*.py"),
        ]

        files = 0
        lines = 0
        characters = 0

        for (file) in files_:
            files += 1
            for (line) in open(file):
                lines += 1
                characters += len(line)

        color = ctx.me.color if ctx.guild else discord.Color.blurple()
        e = discord.Embed(color=color)
        e.set_author(name="Code")
        e.add_field(name="Files", value=str(files))
        e.add_field(name="Lines", value=str(lines))
        e.add_field(name="Characters", value=str(characters))
        e.set_footer(
            text = "{0} | {1}".format(
                ctx.author,
                format.humanize_datetime()
            ),
            icon_url=ctx.author.avatar_url
        )

        await ctx.send(embed=e)
示例#15
0
文件: information.py 项目: PgBiel/sbt
    async def _information_emoji(self, ctx: commands.Context, emoji: typing.Union[discord.Emoji, str]):
        """
        display emoji information

        if it is a unicode emoji it just invokes `>unicode`
        """

        if (isinstance(emoji, str)):
            await ctx.invoke(self._unicode, characters=emoji)
            return

        color = ctx.me.color if ctx.guild else discord.Color.blurple()
        e = discord.Embed(color=color, title="Emoji Information")
        e.add_field(name="Name", value=emoji.name)
        e.add_field(name="ID", value=emoji.id)
        e.add_field(name="Created", value=format.humanize_datetime(emoji.created_at), inline=False)
        e.add_field(name="Animated", value=emoji.animated)
        e.add_field(name="Managed", value=emoji.managed)
        
        if (emoji.roles):
            roles = [r.name for r in emoji.roles]
            e.add_field(name="Roles", value=", ".join(roles))

        await ctx.send(embed=e)
示例#16
0
文件: information.py 项目: PgBiel/sbt
    async def _color(self, ctx: commands.Context, *, code: typing.Optional[parse.Color]):
        """
        parse and display a color

        defaults to a random color

        examples:
            `>color`           :: random
            `>color 0xFF0000`  :: red
            `>color 255, 0, 0` :: red

        see source for regex patterns
        """

        if (not code):
            code = "".join([random.choice("0123456789ABCDEF") for (_) in range(6)])
            code = parse.Color.parse(code)

        int_, hex, rgb, cmyk = code

        rgb = "({0}, {1}, {2})".format(*rgb)
        cmyk = "({0}, {1}, {2}, {3})".format(*cmyk)

        e = discord.Embed(title="Color", color=int_)
        e.add_field(name="Hexadecimal", value="0x{0}".format(hex))
        e.add_field(name="Red, Green, Blue", value=rgb)
        e.add_field(name="Cyan, Magenta, Yellow, Key", value=cmyk)
        e.set_footer(
            text = "{0} | {1}".format(
                ctx.author,
                format.humanize_datetime()
            ),
            icon_url=ctx.author.avatar_url
        )

        await ctx.send(embed=e)
示例#17
0
    def _command_commands_embedinator(self, ctx, command: commands.Command,
                                      commands_: list) -> list:
        embeds = list()

        for (i,
             chunk) in enumerate(paginate._chunk(commands_, COMMANDS_PER_PAGE),
                                 1):
            color = ctx.me.color if ctx.guild else discord.Color.blurple()
            e = discord.Embed(color=color)
            e.set_author(name="{0} ({1}-{2} / {3})".format(
                self._format_signature(ctx, command), (i * COMMANDS_PER_PAGE) -
                (COMMANDS_PER_PAGE - 1),
                min([i *
                     COMMANDS_PER_PAGE, len(commands_)]), len(commands_)))

            if (command.help):
                e.description = command.help

            for (command_) in chunk:
                e.add_field(name=self._format_signature(ctx,
                                                        command_,
                                                        ignore_aliases=True),
                            value=command_.short_doc or "no description",
                            inline=False)

            e.set_footer(
                text="{0} | {1}".format(
                    ctx.author,
                    format.humanize_datetime(),
                ),
                icon_url=ctx.author.avatar_url,
            )

            embeds.append(e)

        return embeds
示例#18
0
文件: general.py 项目: PgBiel/sbt
    async def _urban(self, ctx: commands.Context, *, search: str):
        """
        search urban dictionary

        should be used in an nsfw-marked channel

        example:
            `>urban thing` :: search urban dictionary for "thing"
        """

        if (not ctx.channel.is_nsfw()):
            await ctx.send(
                "this command should be used in an nsfw-marked channel")
            ctx.command.reset_cooldown(ctx)
            return

        search = urllib.parse.quote_plus(search,
                                         encoding="utf-8",
                                         errors="replace")
        url = "http://api.urbandictionary.com/v0/define?term={0}".format(
            search)

        async with aiohttp.ClientSession() as session:
            async with session.get(url) as response:
                if (response.status != 200):
                    await ctx.send(response.status)
                    ctx.command.reset_cooldown(ctx)
                    return

                json_ = await response.json()

        results = json_["list"]

        if (not results):
            await ctx.send("no results")
            ctx.command.reset_cooldown(ctx)
            return

        color = ctx.guild.me.color if ctx.guild else None
        embeds = list()
        for (i, result) in enumerate(results, 1):
            title = "{0} {1}/{2}".format(result["word"], i, len(results))
            if (len(title) > 256):
                title = "{0}...".format(title[:253])

            description = re.sub(
                r"\[([a-zA-Z0-9\']+)\]",
                r"[\1](https://www.urbandictionary.com/define.php?term=\1)",
                result["definition"])
            if (len(description) > 2048):
                description = "{0}...".format(description[:2045])

            example = re.sub(
                r"\[([a-zA-Z0-9\']+)\]",
                r"[\1](https://www.urbandictionary.com/define.php?term=\1)",
                result["example"])
            if (not example):
                example = "no example"
            elif (len(example) > 1024):
                example = "{0}...".format(example[1021])

            e = format.embed(description=description,
                             color=color,
                             author=title,
                             author_url=result["permalink"],
                             fields=[("Example", example)],
                             footer="{0} | {1}".format(
                                 ctx.author, format.humanize_datetime()),
                             footer_icon_url=ctx.author.avatar_url)

            embeds.append(e)

        message = await ctx.send(embed=embeds[0])

        if (len(embeds) == 1):
            ctx.command.reset_cooldown(ctx)
            return

        current = 0

        reactions = [
            "\U000023ea",
            "\U00000023\U000020e3",
            "\U000023e9",
            "\U0001f5d1",
        ]

        for (reaction) in reactions:
            await message.add_reaction(reaction)

        while (True):

            def check(reaction: discord.Reaction, member: discord.Member):
                if (member == ctx.author):
                    if (reaction.message.id == message.id):
                        if (str(reaction.emoji) in reactions):
                            return True

            tasks = {
                asyncio.create_task(
                    ctx.bot.wait_for("reaction_add", check=check,
                                     timeout=120)),
                asyncio.create_task(
                    ctx.bot.wait_for("reaction_remove",
                                     check=check,
                                     timeout=120)),
            }

            done, pending = await asyncio.wait(
                tasks, return_when=asyncio.FIRST_COMPLETED)

            try:
                reaction, _ = done.pop().result()
            except (asyncio.TimeoutError) as e:
                await message.clear_reactions()
                return

            for (task) in pending:
                task.cancel()

            if (str(reaction.emoji) == reactions[0]):
                current -= 1
                if (current < 0):
                    current = len(embeds) - 1
            elif (str(reaction.emoji) == reactions[1]):

                def check(message: discord.Message):
                    if (message.author == ctx.author):
                        if (message.channel == ctx.channel):
                            if (message.content.isdigit()):
                                if (int(message.content) >= 1):
                                    if (int(message.content) <= len(embeds)):
                                        return True

                message_ = await ctx.send("choose a page (1-{0})".format(
                    len(embeds)))

                try:
                    page = await ctx.bot.wait_for("message",
                                                  check=check,
                                                  timeout=60)
                except (asyncio.TimeoutError) as e:
                    await message_.delete()
                    await message.remove_reaction(str(reaction.emoji),
                                                  ctx.author)
                    continue

                await message_.delete()
                await page.delete()

                if (current == (int(page.content) - 1)):
                    continue

                current = int(page.content) - 1
            elif (str(reaction.emoji) == reactions[2]):
                current += 1
                if (current > (len(embeds) - 1)):
                    current = 0
            elif (str(reaction.emoji) == reactions[3]):
                await message.clear_reactions()
                ctx.command.reset_cooldown(ctx)
                return

            await message.remove_reaction(str(reaction.emoji), ctx.author)
            await message.edit(embed=embeds[current])
示例#19
0
文件: information.py 项目: PgBiel/sbt
    async def _flags(self, ctx: commands.Context, member: typing.Optional[discord.Member]):
        """
        display a user's flags

        defaults to your own

        examples:
            `>flags`
            `>flags 310418322384748544`
        """

        author = ctx.author

        if (member):
            ctx = copy.copy(ctx)
            ctx.author = member

        flags = list()

        if (checks.is_owner_check(ctx)):
            flags.append("owner")

        if (checks.is_supervisor_check(ctx)):
            flags.append("supervisor")

        if (checks.is_support_check(ctx)):
            flags.append("support team")

        if (checks.is_alpha_check(ctx)):
            flags.append("alpha tester")

        if (checks.is_beta_check(ctx)):
            flags.append("beta tester")

        if (checks.is_dj_check(ctx)):
            flags.append("dj")

        if (ctx.author.id in ctx.bot._settings.whitelist):
            flags.append("whitelisted")

        if (ctx.author.id in ctx.bot._settings.blacklist):
            flags.append("blacklisted")

        if (not flags):
            await ctx.send("no results")
            return

        message = ", ".join(flags)

        color = ctx.me.color if ctx.guild else discord.Color.blurple()
        e = discord.Embed(color=color)
        e.add_field(name="Flags for {0}".format(ctx.author), value=message)
        e.set_footer(
            text = "{0} | {1}".format(
                author.name,
                format.humanize_datetime()
            ),
            icon_url=author.avatar_url
        )

        await ctx.send(embed=e)