Skip to content

Commit 7fd0994

Browse files
committed
Info rewrite
1 parent 3393a2c commit 7fd0994

File tree

1 file changed

+97
-10
lines changed

1 file changed

+97
-10
lines changed

lib/cogs/Info.py

+97-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
from discord.ext.commands import Cog
2-
from discord.ext.commands import slash_command
1+
import os
2+
3+
import discord
4+
import psutil
35
from discord.commands import SlashCommandGroup
46
from discord.embeds import Embed
7+
from discord.ext.commands import Cog
8+
from discord.guild import Guild
59

610
from lib.bot import Bot
711
from lib.context import CustomContext
@@ -11,18 +15,101 @@ class Info(Cog):
1115
def __init__(self, bot: Bot):
1216
self.bot: Bot = bot
1317

14-
one = SlashCommandGroup('one')
15-
two = one.create_subgroup('two')
18+
bot = SlashCommandGroup('bot')
19+
server = SlashCommandGroup('server')
1620

17-
@slash_command(name="status", description="Get the current status of the bot")
21+
@bot.command(name="status", description="Get the current status of the bot")
1822
async def status(self, ctx: CustomContext):
19-
embed: Embed = Embed(title="Bot status")
20-
embed.add_field(name='Shard latency', value=f"{self.bot.get_shard(ctx.guild.shard_id).latency}")
23+
await ctx.response.defer()
24+
embed: Embed = Embed()
25+
nickname = (await ctx.guild.fetch_member(self.bot.user.id)).nick
26+
python_process = psutil.Process(os.getpid())
27+
owner = await self.bot.fetch_user(self.bot.owner_id)
28+
# embed.set_author(name=f"{nickname if nickname else self.bot.user.display_name}#{self.bot.user.discriminator}",
29+
# icon_url="https://i.imgur.com/QMykWjw.png")
30+
embed.description = f"""
31+
**SHARD**: `{ctx.guild.shard_id + 1}/{self.bot.shard_count}` **LATENCY**: `{round(self.bot.get_shard(ctx.guild.shard_id).latency, 2)}`
32+
**RAM**: `{round(python_process.memory_info()[0] / 2. ** 30, 2)} Gb` **CPU**: `{await self.bot.cpu_percent(1)}%`
33+
**OWNER**: `{owner.display_name}#{owner.discriminator}`
34+
"""
35+
# embed.add_field(name='Total commands', value=f"`{len(self.bot.application_commands)}`", inline=False)
36+
2137
await ctx.respond(embed=embed)
2238

23-
@two.command(name='test')
24-
async def two_layer_test(self, ctx: CustomContext):
25-
await ctx.respond("Hello!")
39+
@server.command(name='info', description='Get the info of the current server')
40+
async def server_info(self, ctx: CustomContext):
41+
await ctx.response.defer()
42+
guild: Guild = ctx.guild
43+
embed: Embed = Embed()
44+
45+
# Get Emoji Info
46+
regular = 0
47+
animated = 0
48+
for emoji in guild.emojis:
49+
if emoji.animated:
50+
animated += 1
51+
else:
52+
regular += 1
53+
# Get Role Info
54+
roles_list = [role.mention for role in guild.roles if not role.is_bot_managed() and role.is_assignable()]
55+
roles = ' '.join(roles_list)
56+
roles_count = len(roles_list)
57+
58+
# Get boost information
59+
boost_tier = guild.premium_tier
60+
filesize_limit = 100 if boost_tier == 3 else 50 if boost_tier == 2 else 8
61+
62+
embed.add_field(name='___About___', value=f"""
63+
**Name:** `{guild.name}`
64+
**ID:** `{guild.id}`
65+
**Owner:** `{guild.owner.display_name}#{guild.owner.discriminator} ({guild.owner_id})`
66+
**Created At:** `<t:{round(guild.created_at.timestamp())}:R>`
67+
**Members:** `{len([member for member in guild.members if not member.bot])}`
68+
**Bots:** `{len([member for member in guild.members if member.bot])}`
69+
**Banned:** `{len(await guild.bans().flatten())}`
70+
""", inline=False)
71+
embed.add_field(name='___Description___', value=guild.description if guild.description else 'None', inline=False)
72+
# embed.add_field(name='___Extras___', value=f"""
73+
# **Verification Level:** {str(guild.verification_level).title()}
74+
# **Upload Limit:** {filesize_limit} MB
75+
# **Inactive Channel:** {guild.afk_channel.mention if guild.afk_channel else 'None'}
76+
# **Inactive Timeout:** {guild.afk_timeout/60} minutes
77+
# **System Messages Channel:** {guild.system_channel.mention if guild.system_channel else 'None'}
78+
# **System Welcome Messages:** {"✅" if guild.system_channel_flags.join_notifications else ':x:'}
79+
# **System Boost Messages:** {"✅" if guild.system_channel_flags.premium_subscriptions else ':x:'}
80+
# **Default Notifications:** {"All Messages" if "all" in str(guild.default_notifications) else "Only Mentions"}
81+
# **Explicit Media Content Filter:** {' '.join(str(guild.explicit_content_filter).split("_")).title()}
82+
# **2FA Requirement:** {"✅" if guild.mfa_level else ":x:"}
83+
# **Boost Bar** {"✅" if guild.premium_progress_bar_enabled else ":x:"}
84+
# """, inline=False)
85+
embed.add_field(name='___Channels___', value=f"""
86+
**Total:** `{len(guild.channels)}`
87+
**Text:** `{len(guild.text_channels)}`
88+
**Voice:** `{len(guild.voice_channels)}`
89+
**Rules Channel:** `{guild.rules_channel.mention if guild.rules_channel else 'None'}`
90+
""")
91+
embed.add_field(name='___Emojis___', value=f"""
92+
**Regular:** `{regular}/{guild.emoji_limit}`
93+
**Animated:** `{animated}/{guild.emoji_limit}`
94+
**Total:** `{len(guild.emojis)}/{guild.emoji_limit}`
95+
""")
96+
embed.add_field(name='___Boost___', value=f"""
97+
**Level:** `{boost_tier}`
98+
**Total:** `{guild.premium_subscription_count}`
99+
**Boost Bar:** `{"✅" if guild.premium_progress_bar_enabled else ":x:"}`
100+
**Role:** `{guild.premium_subscriber_role.mention if guild.premium_subscriber_role else 'None'}`
101+
""")
102+
embed.add_field(name=f'___Roles___ [{roles_count}]', value=f"""
103+
{'None' if not roles_count else roles if len(roles) <=1024 else 'Too many to show'}
104+
""", inline=False)
105+
106+
# Add banner and icon if available
107+
if guild.banner:
108+
embed.set_image(url=guild.banner.url)
109+
if guild.icon:
110+
embed.set_thumbnail(url=guild.icon.url)
111+
112+
await ctx.respond(embed=embed)
26113

27114

28115
def setup(bot):

0 commit comments

Comments
 (0)