示例#1
0
    async def leaderboard(self, ctx):
        """Prints a leaderboard of everyone in the server's battling record

        EXAMPLE: !leaderboard
        RESULT: A leaderboard of this server's battle records"""

        query = """
SELECT
    id, battle_rating
FROM
    users
WHERE
    id = any($1::bigint[])
ORDER BY
    battle_rating DESC
"""

        results = await ctx.bot.db.fetch(query,
                                         [m.id for m in ctx.guild.members])

        if results is None or len(results) == 0:
            await ctx.send("No one has battled on this server!")
        else:

            output = []
            for row in results:
                member = ctx.guild.get_member(row['id'])
                output.append(
                    f"{member.display_name} (Rating: {row['battle_rating']})")

            try:
                pages = utils.Pages(ctx, entries=output)
                await pages.paginate()
            except utils.CannotPaginate as e:
                await ctx.send(str(e))
示例#2
0
    async def restrictions(self, ctx):
        """Used to list all the current restrictions set

        EXAMPLE: !restrictions
        RESULT: All the current restrictions"""
        restrictions = await ctx.bot.db.fetch(
            "SELECT source, destination, from_to FROM restrictions WHERE guild=$1",
            ctx.guild.id)

        entries = []
        for restriction in restrictions:
            # Check whether it's from or to to change what the format looks like
            dest = restriction["destination"]
            if dest != "everyone":
                dest = await utils.convert(ctx, restriction["destination"])
            # If it doesn't exist, don't add it
            if dest:
                entries.append(
                    f"{restriction['source']} {'from' if restriction['from_to'] == 'from' else 'to'} {dest}"
                )

        if entries:
            # Then paginate
            try:
                pages = utils.Pages(ctx, entries=entries)
                await pages.paginate()
            except utils.CannotPaginate as e:
                await ctx.send(str(e))
        else:
            await ctx.send("There are no restrictions!")
示例#3
0
    async def urban(self, ctx, *, msg: str):
        """Pulls the top urbandictionary.com definition for a term

        EXAMPLE: !urban a normal phrase
        RESULT: Probably something lewd; this is urban dictionary we're talking about"""
        if utils.channel_is_nsfw(ctx.message.channel):
            url = "http://api.urbandictionary.com/v0/define"
            params = {"term": msg}
            try:
                data = await utils.request(url, payload=params)
                if data is None:
                    await ctx.send("Sorry but I failed to connect to urban dictionary!")
                    return

                # List is the list of definitions found, if it's empty then nothing was found
                if len(data['list']) == 0:
                    await ctx.send("No result with that term!")
                # If the list is not empty, use the first result and print it's defintion
                else:
                    entries = [x['definition'] for x in data['list']]
                    try:
                        pages = utils.Pages(ctx, entries=entries[:5], per_page=1)
                        await pages.paginate()
                    except utils.CannotPaginate as e:
                        await ctx.send(str(e))
            # Urban dictionary has some long definitions, some might not be able to be sent
            except discord.HTTPException:
                await ctx.send('```\nError: Definition is too long for me to send```')
            except KeyError:
                await ctx.send("Sorry but I failed to connect to urban dictionary!")
        else:
            await ctx.send("This command is limited to nsfw channels")
示例#4
0
    async def _handle_show_custom_hugs(self, ctx, opt):
        result = await ctx.bot.db.fetchrow(
            "SELECT custom_hugs FROM guilds WHERE id = $1", ctx.guild.id)

        if result and result["custom_hugs"]:
            try:
                pages = utils.Pages(ctx, entries=result["custom_hugs"])
                await pages.paginate()
            except utils.CannotPaginate as e:
                await ctx.send(str(e))
        else:
            return "This server has no custom hugs"
示例#5
0
    async def role(self, ctx, *, role: discord.Role = None):
        """This command can be used to modify the roles on the server.
        Pass no subcommands and this will print the roles currently available on this server
        If you give a role as the argument then it will give some information about that role

        EXAMPLE: !role
        RESULT: A list of all your roles"""

        if role:
            # Create the embed object
            opts = {
                "title": role.name,
                "colour": role.colour,
            }
            if role.managed:
                opts[
                    "description"] = "This role is managed by a third party service"
            embed = discord.Embed(**opts)
            # Add details to it
            embed.add_field(name="Created", value=role.created_at.date())
            embed.add_field(name="Mentionable",
                            value="Yes" if role.mentionable else "No")
            total_members = len(role.members)
            embed.add_field(name="Total members", value=str(total_members))
            # If there are only a few members in this role, display them
            if 5 >= total_members > 0:
                embed.add_field(
                    name="Members",
                    value="\n".join(m.display_name for m in role.members),
                )
            await ctx.send(embed=embed)
        else:
            # Don't include the colour roles
            colour_role = re.compile("Bonfire #.+")
            # Simply get a list of all roles in this server and send them
            entries = [
                r.name for r in ctx.guild.roles[1:]
                if not colour_role.match(r.name)
            ]
            if len(entries) == 0:
                await ctx.send(
                    "You do not have any roles setup on this server, other than the default role!"
                )
                return

            try:
                pages = utils.Pages(ctx, entries=entries)
                await pages.paginate()
            except utils.CannotPaginate as e:
                await ctx.send(str(e))
示例#6
0
    async def _handle_show_followed_picarto_channels(self, ctx, opt):
        result = await ctx.bot.db.fetchrow(
            "SELECT followed_picarto_channels FROM guilds WHERE id = $1",
            ctx.guild.id)

        if result and result["followed_picarto_channels"]:
            try:
                pages = utils.Pages(
                    ctx, entries=result["followed_picarto_channels"])
                await pages.paginate()
            except utils.CannotPaginate as e:
                await ctx.send(str(e))
        else:
            return "This server is not following any picarto channels"
示例#7
0
    async def tags(self, ctx):
        """Prints all the custom tags that this server currently has

        EXAMPLE: !tags
        RESULT: All tags setup on this server"""
        tags = await ctx.bot.db.fetch(
            "SELECT trigger FROM tags WHERE guild=$1", ctx.guild.id
        )

        if len(tags) > 0:
            entries = [t["trigger"] for t in tags]
            pages = utils.Pages(ctx, entries=entries)
            await pages.paginate()
        else:
            await ctx.send("There are no tags setup on this server!")
示例#8
0
    async def _handle_show_assignable_roles(self, ctx, opt):
        result = await ctx.bot.db.fetchrow(
            "SELECT assignable_roles FROM guilds WHERE id = $1", ctx.guild.id)

        if result and result["assignable_roles"]:
            try:
                entries = [
                    ctx.guild.get_role(r).name
                    for r in result["assignable_roles"]
                    if ctx.guild.get_role(r) is not None
                ]
                pages = utils.Pages(ctx, entries=entries)
                await pages.paginate()
            except utils.CannotPaginate as e:
                await ctx.send(str(e))
        else:
            return "This server has no assignable roles"
示例#9
0
    async def _handle_show_ignored_members(self, ctx, opt):
        result = await ctx.bot.db.fetchrow(
            "SELECT ignored_members FROM guilds WHERE id = $1", ctx.guild.id)

        if result and result["ignored_members"]:
            try:
                entries = [
                    ctx.guild.get_member(m).display_name
                    for m in result["ignored_members"]
                    if ctx.guild.get_member(m) is not None
                ]
                pages = utils.Pages(ctx, entries=entries)
                await pages.paginate()
            except utils.CannotPaginate as e:
                await ctx.send(str(e))
        else:
            return "This server is not ignoring any members"
示例#10
0
    async def mytags(self, ctx):
        """Prints all the custom tags that this server that you own

        EXAMPLE: !mytags
        RESULT: All your tags setup on this server"""
        tags = await ctx.bot.db.fetch(
            "SELECT trigger FROM tags WHERE guild=$1 AND creator=$2",
            ctx.guild.id,
            ctx.author.id,
        )

        if len(tags) > 0:
            entries = [t["trigger"] for t in tags]
            pages = utils.Pages(ctx, entries=entries)
            await pages.paginate()
        else:
            await ctx.send("You have no tags on this server!")
示例#11
0
    async def birthday(self, ctx, *, member: discord.Member = None):
        """A command used to view the birthdays on this server; or a specific member's birthday

        EXAMPLE: !birthdays
        RESULT: A printout of the birthdays from everyone on this server"""
        if member:
            date = await ctx.bot.db.fetchrow(
                "SELECT birthday FROM users WHERE id=$1", member.id)
            if date is None or date["birthday"] is None:
                await ctx.send(
                    f"I do not have {member.display_name}'s birthday saved!")
            else:
                date = date['birthday']
                await ctx.send(
                    f"{member.display_name}'s birthday is {calendar.month_name[date.month]} {date.day}"
                )
        else:
            # Get this server's birthdays
            bds = await self.get_birthdays_for_server(ctx.guild)
            # Create entries based on the user's display name and their birthday
            entries = [
                f"{ctx.guild.get_member(bd['id']).display_name} ({bd['birthday'].strftime('%B %-d')})"
                for bd in bds if bd['birthday']
            ]
            if not entries:
                await ctx.send("I don't know anyone's birthday in this server!"
                               )
                return

            # Create our pages object
            try:
                pages = utils.Pages(ctx, entries=entries, per_page=5)
                pages.title = f"Birthdays for {ctx.guild.name}"
                await pages.paginate()
            except utils.CannotPaginate as e:
                await ctx.send(str(e))