Add commands for state monitoring
This commit is contained in:
parent
bce9abd10a
commit
e041913d5b
25
cogs/BotManagment.py
Normal file
25
cogs/BotManagment.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from formatting import format_table
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
|
||||
|
||||
class BotManagement(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.is_owner()
|
||||
@commands.command('listServers')
|
||||
async def list_servers(self, ctx: Context):
|
||||
text_table = format_table(((server.name, str(server.id)) for server in self.bot.guilds), ('name', 'id'))
|
||||
await ctx.channel.send(text_table)
|
||||
|
||||
@commands.is_owner()
|
||||
@commands.command('listVoice')
|
||||
async def list_voice_connections(self, ctx: Context):
|
||||
text_table = format_table(((it.guild.name,) for it in self.bot.voice_clients))
|
||||
await ctx.channel.send(text_table)
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(BotManagement(bot))
|
18
formatting.py
Normal file
18
formatting.py
Normal file
@ -0,0 +1,18 @@
|
||||
from typing import Iterable
|
||||
|
||||
|
||||
class MISSING:
|
||||
pass
|
||||
|
||||
|
||||
def format_table(data: Iterable[Iterable[str]], header: Iterable[str] = MISSING) -> str:
|
||||
if header != MISSING:
|
||||
data = (header, *data)
|
||||
|
||||
result = '```\n'
|
||||
for row in data:
|
||||
row = [item.replace('`', '\\`') for item in row]
|
||||
result += '\t'.join(row) + '\n'
|
||||
|
||||
result += '```'
|
||||
return result
|
Loading…
x
Reference in New Issue
Block a user