Esempio n. 1
0
 async def botowners(self, ctx):
     """
     Usage: {0}botowners
     Alias: {0}owners
     Output:
         An embed of the bot's owners
     """
     our_list = []
     for user_id in self.bot.constants.owners:
         user = self.bot.get_user(user_id)
         our_list.append({
             "name": f"**{str(user)}**",
             "value": f"ID: `{user.id}`"
         })
     p = pagination.MainMenu(
         pagination.FieldPageSource(
             entries=[("{}. {}".format(y + 1, x["name"]), x["value"])
                      for y, x in enumerate(our_list)],
             title="My Owners ({:,} total)".format(
                 len(self.bot.constants.owners)),
             per_page=15,
         ))
     try:
         await p.start(ctx)
     except menus.MenuError as e:
         await ctx.send_or_reply(e)
Esempio n. 2
0
    async def socket(self, ctx):
        """
        Usage: {0}socket
        Alias: {0}socketstats
        Output:
            Fetch information on the socket
            events received from Discord.
        """
        running_s = (datetime.datetime.utcnow() -
                     self.socket_since).total_seconds()

        per_s = self.socket_event_total / running_s

        width = len(max(self.bot.socket_events, key=lambda x: len(str(x))))

        line = "\n".join(
            "{0:<{1}} : {2:>{3}}".format(str(event_type), width, count,
                                         len(max(str(count))))
            for event_type, count in self.bot.socket_events.most_common())

        header = (
            "**Receiving {0:0.2f} socket events per second** | **Total: {1}**\n"
            .format(per_s, self.socket_event_total))

        m = pagination.MainMenu(
            pagination.TextPageSource(line, prefix="```yaml", max_size=500))
        await ctx.send_or_reply(header)
        try:

            await m.start(ctx)
        except menus.MenuError as e:
            await ctx.send_or_reply(e)
Esempio n. 3
0
 async def todo(self, ctx):
     """
     Usage: {0}todo <method>
     Alias: {0}to-do
     Methods:
         no subcommand: shows the todo list
         add: Adds an entry to the todo list
         remove|rm|rem: Removes an entry from the todo list
     """
     if ctx.invoked_subcommand is None:
         try:
             with open(self.todo) as fp:
                 data = fp.readlines()
         except FileNotFoundError:
             return await ctx.send_or_reply(
                 f"{self.bot.emote_dict['exclamation']} No current todos.")
         if data is None or data == "":
             return await ctx.send_or_reply(
                 f"{self.bot.emote_dict['exclamation']} No current todos.")
         msg = ""
         for index, line in enumerate(data, start=1):
             msg += f"{index}. {line}\n"
         p = pagination.MainMenu(
             pagination.TextPageSource(msg, prefix="```prolog\n"))
         try:
             await p.start(ctx)
         except menus.MenuError as e:
             await ctx.send_or_reply(e)
Esempio n. 4
0
    async def bottomservers(self, ctx):
        """
        Usage: -bottomservers
        Output: The servers with the least memebers
        """
        our_list = []
        for guild in self.bot.guilds:
            our_list.append({
                "name":
                guild.name,
                "value":
                "{:,} member{}".format(len(guild.members),
                                       "" if len(guild.members) == 1 else "s"),
                "users":
                len(guild.members),
            })
        our_list = sorted(our_list, key=lambda x: x["users"])
        p = pagination.MainMenu(
            pagination.FieldPageSource(
                entries=[("{}. {}".format(y + 1, x["name"]), x["value"])
                         for y, x in enumerate(our_list)],
                title="Bottom Servers By Population ({:,} total)".format(
                    len(self.bot.guilds)),
                per_page=15,
            ))

        try:
            await p.start(ctx)
        except menus.MenuError as e:
            await ctx.send_or_reply(e)
Esempio n. 5
0
    async def sss(self, ctx, user: converters.DiscordUser = None):
        """
        Usage: {0}sss [user]
        Output:
            Servers that the user shares
            with the bot.
        Notes:
            This supplies a more verbose
            output than the public ss command.
            Will default to you if no user is
            specified.
        """
        if user is None:
            user = ctx.author

        shared = []
        for guild in self.bot.guilds:
            for member in guild.members:
                if member.id == user.id:
                    shared.append((guild.id, guild.name))

        width = max([len(str(x[0])) for x in shared])
        formatted = "\n".join(
            [f"{str(x[0]).ljust(width)} : {x[1]}" for x in shared])
        p = pagination.MainMenu(
            pagination.TextPageSource(formatted, prefix="```fix",
                                      max_size=500))
        await ctx.send_or_reply(
            f"** I share {len(shared)} servers with `{user}`**")
        try:
            await p.start(ctx)
        except menus.MenuError as e:
            await ctx.send_or_reply(e)
Esempio n. 6
0
    async def listservers(self, ctx):
        """
        Usage: -listservers
        Alias: -servers, -serverlist
        Output: Lists the servers I'm connected to.
        """
        our_list = []
        for guild in self.bot.guilds:
            our_list.append({
                "name":
                guild.name,
                "value":
                "{:,} member{}\nID: `{}`".format(
                    len(guild.members),
                    "" if len(guild.members) == 1 else "s",
                    guild.id,
                ),
                "users":
                len(guild.members),
            })
        p = pagination.MainMenu(
            pagination.FieldPageSource(
                entries=[("{}. {}".format(y + 1, x["name"]), x["value"])
                         for y, x in enumerate(our_list)],
                title="Server's I'm Connected To ({:,} total)".format(
                    len(self.bot.guilds)),
                per_page=15,
            ))

        try:
            await p.start(ctx)
        except menus.MenuError as e:
            await ctx.send_or_reply(e)
Esempio n. 7
0
    async def inv(self, ctx, server: converters.BotServer = None):
        """
        Usage: {0}inv <server>
        Output: Invite for that server (if bot could create it)
        """
        if server is None:
            server = ctx.guild
        if isinstance(server, list):
            if len(server) > 1:
                msg = ""
                for x in server:
                    guild = self.bot.get_guild(int(x))
                    msg += f"ID: {guild.id} Name: {guild.name}\n"
                await ctx.send_or_reply(
                    content=
                    f"Multiple results. Please use the server ID instead", )
                t = pagination.MainMenu(
                    pagination.TextPageSource(text=msg, max_size=500))
                try:
                    return await t.start(ctx)
                except menus.MenuError as e:
                    await ctx.send_or_reply(e)
            else:
                try:
                    server = self.bot.get_guild(int(server[0]))
                except IndexError:
                    return await ctx.send_or_reply(
                        content=f"Couldn't find that server.", )

        s = random.choice(server.text_channels)
        try:
            inv = await s.create_invite()
        except Exception as e:
            return await ctx.send_or_reply(e)
        await ctx.send_or_reply(inv)
Esempio n. 8
0
 async def changelog(self, ctx):
     """
     Usage: -changelog
     Alias: -updates
     Output: My changelog
     """
     with open("./data/txts/changelog.txt", "r", encoding="utf-8") as fp:
         changelog = fp.read()
     await ctx.send_or_reply(
         content=f"**{self.bot.user.name}'s Changelog**", )
     p = pagination.MainMenu(
         pagination.TextPageSource(changelog, prefix="```prolog"))
     try:
         await p.start(ctx)
     except menus.MenuError as e:
         await ctx.send_or_reply(e)
Esempio n. 9
0
    async def recentservers(self, ctx):
        """
        Usage: {0}recentservers
        Alias: {0}lastservers
        Output: Lists the most recent servers joined
        """
        our_list = []
        for guild in self.bot.guilds:
            bot = guild.me
            our_list.append({
                "name":
                "{} ({} member{})".format(
                    guild.name,
                    len(guild.members),
                    "" if len(guild.members) == 1 else "s",
                ),
                "value":
                "{} UTC".format(
                    bot.joined_at.strftime("%Y-%m-%d %I:%M %p") if bot.
                    joined_at is not None else "Unknown"),
                "date":
                bot.joined_at,
            })
        our_list = sorted(
            our_list,
            key=lambda x: x["date"].timestamp()
            if x["date"] is not None else -1,
            reverse=True,
        )
        p = pagination.MainMenu(
            pagination.FieldPageSource(
                entries=[("{}. {}".format(y + 1, x["name"]), x["value"])
                         for y, x in enumerate(our_list)],
                title="Most Recent Servers I Joined ({:,} total)".format(
                    len(self.bot.guilds)),
                per_page=15,
            ))

        try:
            await p.start(ctx)
        except menus.MenuError as e:
            await ctx.send_or_reply(e)
Esempio n. 10
0
 async def members(self, ctx, *, argument=None):
     """
     Usage: {0}members
     Output: Lists the members of a passed server
     """
     if not argument:
         guild = ctx.guild
     options = await converters.BotServer().convert(ctx, argument)
     option_dict = dict()
     if isinstance(options, list):
         for x in options:
             option_dict[x.name] = x
         guild, message = await helpers.choose(ctx, argument, option_dict)
         if not guild:
             return
     else:
         guild = options
         message = None
     members = guild.members
     member_list = []
     for entity in members:
         member_list.append({
             "name":
             entity,
             "value":
             "Mention: {}\nID: `{}`\nNickname: {}".format(
                 entity.mention, entity.id, entity.display_name),
         })
     p = pagination.MainMenu(
         pagination.FieldPageSource(
             entries=[("{}. {}".format(y + 1, x["name"]), x["value"])
                      for y, x in enumerate(member_list)],
             per_page=10,
             title=
             f"Member list for **{guild.name}** ({len(members):,} total)",
         ))
     if message:
         await message.delete()
     try:
         await p.start(ctx)
     except menus.MenuError as e:
         await ctx.send_or_reply(e)
Esempio n. 11
0
 async def blacklist(
     self,
     ctx,
     _objects: commands.Greedy[typing.Union[
         discord.User, converters.DiscordGuild]] = None,
     *,
     reason: typing.Optional[str] = None,
 ):
     """
     Usage: {0}blacklist <object> [reason]
     """
     if _objects is None:
         p = pagination.MainMenu(
             pagination.TextPageSource(str(self.bot.blacklist),
                                       prefix="```json"))
         try:
             await p.start(ctx)
         except menus.MenuError as e:
             await ctx.send_or_reply(e)
         return
     blacklisted = []
     already_blacklisted = []
     for obj in _objects:
         if obj.id in self.bot.owner_ids:
             continue
         if obj.id in self.bot.blacklist:
             already_blacklisted.append(str(obj))
             continue
         self.bot.blacklist[str(obj.id)] = reason if reason else "No reason"
         blacklisted.append(str(obj))
     if blacklisted:
         await ctx.send_or_reply(
             content=
             f"{self.bot.emote_dict['success']} Blacklisted `{', '.join(blacklisted)}`",
         )
     if already_blacklisted:
         ternary = "was" if len(already_blacklisted) == 1 else "were"
         await ctx.send_or_reply(
             content=
             f"{self.bot.emote_dict['success']} `{', '.join(already_blacklisted)}` {ternary} already blacklisted",
         )
Esempio n. 12
0
    async def cachedcommands(self, ctx, limit=20):
        """
        Usage: -cachedcommands
        Output:
            Show the commands in the bot's cache
        """
        counter = self.bot.command_stats
        width = len(max(counter, key=len))
        total = sum(counter.values())

        if limit > 0:
            common = counter.most_common(limit)
        else:
            common = counter.most_common()[limit:]
        output = "\n".join("{0:<{1}} : {2}".format(k, width, c)
                           for k, c in common)

        p = pagination.MainMenu(
            pagination.TextPageSource(output, prefix="```yaml"))
        try:
            await p.start(ctx)
        except menus.MenuError as e:
            await ctx.send_or_reply(e)