async def blacklist(self, ctx): blacklist = await ctx.db.table("users").filter({ "blacklist": { "state": True } }).run(ctx.db.con) table = PrettyTable() table.field_names = ["User", "Reason", "Admin", "Timestamp"] while (await blacklist.fetch_next()): entry = await blacklist.next() try: user = await self.bot.get_user_info(int(entry["id"])) admin = await self.bot.get_user_info( int(entry["blacklist"]["admin"])) except: continue table.add_row([ f"{user} ({entry['id']})", entry["blacklist"]["reason"], f"{admin} ({entry['blacklist']['admin']})", helpers.datetime_to_string(entry["blacklist"]["timestamp"]) ]) pages = formatter.paginate(str(table)) for page in pages: await ctx.send(f"```diff\n{page}```")
async def shards(self, ctx): """Show shard stats""" table = PrettyTable() table.field_names = ["Shard-Id", "Latency", "Guilds", "Members"] shards = { shard_id: { "latency": latency, "guilds": 0, "members": 0 } for shard_id, latency in self.bot.latencies } for guild in self.bot.guilds: shards[guild.shard_id]["guilds"] += 1 shards[guild.shard_id]["members"] += guild.member_count for shard_id, values in shards.items(): table.add_row([ shard_id, f"{round(values['latency'] * 1000, 1)} ms", values["guilds"], values["members"] ]) pages = formatter.paginate(str(table)) for page in pages: await ctx.send(f"```diff\n{page}```")
async def shards(self, ctx): """Show information about the virtual shards in this physical shard""" table = PrettyTable() table.field_names = ["Shard-Id", "Latency", "Guilds", "Users"] shards = await self.bot.get_shard_stats() for shard_id, values in shards.items(): prefix = '> ' if str(shard_id) == str(ctx.guild.shard_id) else '' table.add_row([prefix + str(shard_id), f"{round(values['latency'] * 1000, 1)} ms", helpers.format_number(values["guilds"]), helpers.format_number(values["users"])]) pages = formatter.paginate(str(table)) for page in pages: await ctx.send(f"```diff\n{page}```")
async def shards(self, ctx): """Show information about the virtual shards in this physical shard""" table = PrettyTable() table.field_names = ["Shard-Id", "Latency", "Guilds", "Users"] shards = await self.bot.get_shards() for shard in shards: latency = f"{round(shard['latency'] * 1000, 1)} ms" if (datetime.utcnow() - shard["seen"]) > timedelta(minutes=3): latency = "offline?" table.add_row([str(shard["id"]), latency, helpers.format_number(shard["guilds"]), helpers.format_number(shard["users"])]) pages = formatter.paginate(str(table)) for page in pages: await ctx.send(f"```diff\n{page}```")
async def query(self, ctx, timeout: float = 0.5, *, expression: str): """ Evaluate a single expression on all shards and return the results __Arguments__ **expressions**: The expression """ results = await self.bot.query(expression, timeout=timeout) table = PrettyTable() table.field_names = ["Shard-Id", "Result"] for shards, result in sorted(results, key=lambda r: sum(r[0])): table.add_row([", ".join([str(s) for s in shards]), result]) pages = formatter.paginate(str(table)) for page in pages: await ctx.send(f"```diff\n{page}```")
async def blacklist(self, ctx): table = PrettyTable() table.field_names = ["User", "Reason", "Admin", "Timestamp"] blacklist = ctx.db.users.find({"blacklist.state": True}) async for entry in blacklist: user = await self.bot.fetch_user(entry["_id"]) admin = await self.bot.fetch_user(entry["blacklist"]["admin"]) table.add_row([ f"{user} ({user.id})", entry["blacklist"]["reason"], f"{admin} ({entry['blacklist']['admin']})", helpers.datetime_to_string(entry["blacklist"]["timestamp"]) ]) pages = formatter.paginate(str(table)) for page in pages: await ctx.send(f"```diff\n{page}```")