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)
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)
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)
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)
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)
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", )
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)