Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[General] Add toggle to [p]serverinfo that shows more details #2382

Merged
merged 28 commits into from Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0861d56
Improvements of "serverinfo" command
PredaaA Jan 20, 2019
054b5be
Black formatting for serverinfo
PredaaA Jan 20, 2019
224ea85
Black formatting fix and Sinbad suggestions
PredaaA Jan 20, 2019
fd4549d
Fix the discord.errors.NotFound on server command
PredaaA Feb 1, 2019
d371bde
Update core_commands.py
PredaaA Feb 1, 2019
3a57ac4
Delete core_commands.py
PredaaA Feb 1, 2019
d429b83
Create core_commands.py
PredaaA Feb 1, 2019
419f2c0
Update core_commands.py
PredaaA Feb 1, 2019
f8679c7
Update core_commands.py
PredaaA Feb 1, 2019
4e8c5f7
Merge pull request #1 from PredaaA/PredaaA-patch-1
PredaaA Feb 1, 2019
3c5abc4
Delete core_commands.py
PredaaA Feb 3, 2019
88f6296
Create core_commands.py
PredaaA Feb 3, 2019
becca9f
Update core_commands.py
PredaaA Feb 3, 2019
bf8743b
Update core_commands.py
PredaaA Feb 3, 2019
004833b
Little changes on serverinfo command
PredaaA Feb 6, 2019
4538768
Black style fix
PredaaA Feb 6, 2019
6ae98fd
Add verbose for serverinfo and disable lurkers
PredaaA Mar 2, 2019
930de33
Add of India region
PredaaA May 4, 2019
49cb977
Code cleanup
PredaaA May 12, 2019
7b35c1e
Emojis are not needed to be translated
PredaaA May 14, 2019
2ce457d
Merge branch 'V3/develop' into V3/develop
Tobotimus Aug 17, 2019
c7c87ba
Update serverinfo
PredaaA Feb 8, 2020
65a799c
Changelog.
PredaaA Feb 8, 2020
3e6fa5d
Merge branch 'V3/develop' into V3/develop
PredaaA Feb 8, 2020
0e711db
Update 2382.enhancement.rst
PredaaA Feb 8, 2020
fedcb15
Adress Jack's requests changes.
PredaaA Mar 15, 2020
132ca8c
oops
PredaaA Mar 15, 2020
49f5ad9
Put guild description first + few last nitpicks
Jackenmen Mar 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/general/2382.enhancement.rst
@@ -0,0 +1 @@
Show more details in [p]serverinfo command when using a toggle.
228 changes: 203 additions & 25 deletions redbot/cogs/general/general.py
Expand Up @@ -8,7 +8,13 @@
from redbot.core import commands
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
from redbot.core.utils.chat_formatting import escape, italics, humanize_number
from redbot.core.utils.chat_formatting import (
bold,
escape,
italics,
humanize_number,
humanize_timedelta,
)

_ = T_ = Translator("General", __file__)

Expand Down Expand Up @@ -234,38 +240,210 @@ async def hug(self, ctx, user: discord.Member, intensity: int = 1):

@commands.command()
@commands.guild_only()
async def serverinfo(self, ctx):
"""Show server information."""
@commands.bot_has_permissions(embed_links=True)
async def serverinfo(self, ctx, details: bool = False):
"""
Show server information.

`details`: Toggle it to `True` to show more informations about this server.
PredaaA marked this conversation as resolved.
Show resolved Hide resolved
Default to False.
"""
guild = ctx.guild
passed = (ctx.message.created_at - guild.created_at).days
created_at = _("Since {date}. That's over {num} days ago!").format(
PredaaA marked this conversation as resolved.
Show resolved Hide resolved
date=guild.created_at.strftime("%d %b %Y %H:%M"), num=humanize_number(passed),
)
online = humanize_number(
len([m.status for m in guild.members if m.status != discord.Status.offline])
)
total_users = humanize_number(len(guild.members))
total_users = humanize_number(guild.member_count)
text_channels = humanize_number(len(guild.text_channels))
voice_channels = humanize_number(len(guild.voice_channels))
passed = (ctx.message.created_at - guild.created_at).days
created_at = _("Since {date}. That's over {num} days ago!").format(
date=guild.created_at.strftime("%d %b %Y %H:%M"), num=passed
)
data = discord.Embed(description=created_at, colour=(await ctx.embed_colour()))
data.add_field(name=_("Region"), value=str(guild.region))
data.add_field(name=_("Users"), value=f"{online}/{total_users}")
data.add_field(name=_("Text Channels"), value=text_channels)
data.add_field(name=_("Voice Channels"), value=voice_channels)
data.add_field(name=_("Roles"), value=humanize_number(len(guild.roles)))
data.add_field(name=_("Owner"), value=str(guild.owner))
data.set_footer(text=_("Server ID: ") + str(guild.id))

if guild.icon_url:
data.set_author(name=guild.name, url=guild.icon_url)
data.set_thumbnail(url=guild.icon_url)
if not details:
data = discord.Embed(description=created_at, colour=await ctx.embed_colour())
data.add_field(name=_("Region"), value=str(guild.region))
data.add_field(name=_("Users"), value=f"{online}/{total_users}")
data.add_field(name=_("Text Channels"), value=text_channels)
data.add_field(name=_("Voice Channels"), value=voice_channels)
data.add_field(name=_("Roles"), value=humanize_number(len(guild.roles)))
data.add_field(name=_("Owner"), value=str(guild.owner))
data.set_footer(text=_("Server ID: ") + str(guild.id))
if guild.icon_url:
data.set_author(name=guild.name, url=guild.icon_url)
data.set_thumbnail(url=guild.icon_url)
else:
data.set_author(name=guild.name)
else:
data.set_author(name=guild.name)

try:
await ctx.send(embed=data)
except discord.Forbidden:
await ctx.send(_("I need the `Embed links` permission to send this."))
def _size(num: int):
for unit in ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB"]:
if abs(num) < 1024.0:
return "{0:.1f}{1}".format(num, unit)
num /= 1024.0
return "{0:.1f}{1}".format(num, "YB")

def _bitsize(num: int):
for unit in ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB"]:
if abs(num) < 1000.0:
return "{0:.1f}{1}".format(num, unit)
num /= 1000.0
return "{0:.1f}{1}".format(num, "YB")

# Logic from: https://github.com/TrustyJAID/Trusty-cogs/blob/master/serverstats/serverstats.py#L159
online_stats = {
_("Humans: "): lambda x: not x.bot,
_(" • Bots: "): lambda x: x.bot,
"📗": lambda x: x.status == discord.Status.online,
"📙": lambda x: x.status == discord.Status.idle,
"📕": lambda x: x.status == discord.Status.idle,
"📓": lambda x: x.status == discord.Status.offline,
"🎥": lambda x: x.activity == discord.Streaming,
"📱": lambda x: x.is_on_mobile(),
PredaaA marked this conversation as resolved.
Show resolved Hide resolved
}
member_msg = _("Total Users: {}\n").format(bold(f"{online}/{total_users}"))
PredaaA marked this conversation as resolved.
Show resolved Hide resolved
count = 1
for emoji, value in online_stats.items():
try:
num = len([m for m in guild.members if value(m)])
except Exception as error:
print(error)
continue
else:
member_msg += f"{emoji} {bold(humanize_number(num))} " + (
"\n" if count % 2 == 0 else ""
)
count += 1

vc_regions = {
"vip-us-east": _("__VIP__ US East ") + "\U0001F1FA\U0001F1F8",
"vip-us-west": _("__VIP__ US West ") + "\U0001F1FA\U0001F1F8",
"vip-amsterdam": _("__VIP__ Amsterdam ") + "\U0001F1F3\U0001F1F1",
"eu-west": _("EU West ") + "\U0001F1EA\U0001F1FA",
"eu-central": _("EU Central ") + "\U0001F1EA\U0001F1FA",
"europe": _("Europe ") + "\U0001F1EA\U0001F1FA",
"london": _("London ") + "\U0001F1EC\U0001F1E7",
"frankfurt": _("Frankfurt ") + "\U0001F1E9\U0001F1EA",
"amsterdam": _("Amsterdam ") + "\U0001F1F3\U0001F1F1",
"us-west": _("US West ") + "\U0001F1FA\U0001F1F8",
"us-east": _("US East ") + "\U0001F1FA\U0001F1F8",
"us-south": _("US South ") + "\U0001F1FA\U0001F1F8",
"us-central": _("US Central ") + "\U0001F1FA\U0001F1F8",
"singapore": _("Singapore ") + "\U0001F1F8\U0001F1EC",
"sydney": _("Sydney ") + "\U0001F1E6\U0001F1FA",
"brazil": _("Brazil ") + "\U0001F1E7\U0001F1F7",
"hongkong": _("Hong Kong ") + "\U0001F1ED\U0001F1F0",
"russia": _("Russia ") + "\U0001F1F7\U0001F1FA",
"japan": _("Japan ") + "\U0001F1EF\U0001F1F5",
"southafrica": _("South Africa ") + "\U0001F1FF\U0001F1E6",
"india": _("India ") + "\U0001F1EE\U0001F1F3",
"dubai": _("Dubai ") + "\U0001F1E6\U0001F1EA",
"south-korea": _("South Korea ") + "\U0001f1f0\U0001f1f7",
}
verif = {
"none": _("0 - None"),
"low": _("1 - Low"),
"medium": _("2 - Medium"),
"high": _("3 - Hard"),
PredaaA marked this conversation as resolved.
Show resolved Hide resolved
"extreme": _("4 - Extreme"),
}

features = {
"PARTNERED": _("Partnered"),
"VERIFIED": _("Verified"),
"DISCOVERABLE": _("Server Discovery"),
"PUBLIC": _("Public"),
PredaaA marked this conversation as resolved.
Show resolved Hide resolved
"INVITE_SPLASH": _("Splash Invite"),
"VIP_REGIONS": _("VIP Voice Servers"),
"VANITY_URL": _("Vanity URL"),
"MORE_EMOJI": _("More Emojis"),
"COMMERCE": _("Commerce"),
"LURKABLE": _("Lurkable"),
PredaaA marked this conversation as resolved.
Show resolved Hide resolved
"NEWS": _("News Channels"),
"ANIMATED_ICON": _("Animated Icon"),
"BANNER": _("Banner Image"),
"MEMBER_LIST_DISABLED": _("Member list disabled"),
}
guild_features_list = [
f"✅ {name}" for feature, name in features.items() if feature in set(guild.features)
PredaaA marked this conversation as resolved.
Show resolved Hide resolved
]

joined_on = _(
"{bot_name} joined this server on {bot_join}. That's over {since_join} days ago!"
).format(
bot_name=ctx.bot.user.name,
bot_join=guild.me.joined_at.strftime("%d %b %Y %H:%M:%S"),
since_join=humanize_number((ctx.message.created_at - guild.me.joined_at).days),
)

data = discord.Embed(description=created_at, colour=await ctx.embed_colour())
data.set_author(
name=guild.name,
icon_url="https://cdn.discordapp.com/emojis/457879292152381443.png"
if "VERIFIED" in guild.features
else "https://cdn.discordapp.com/emojis/508929941610430464.png"
if "PARTNERED" in guild.features
else discord.Embed.Empty,
)
data.set_thumbnail(
url=guild.icon_url
if guild.icon_url
else "https://cdn.discordapp.com/embed/avatars/1.png"
)
PredaaA marked this conversation as resolved.
Show resolved Hide resolved
data.add_field(name=_("Members:"), value=member_msg)
data.add_field(
name=_("Channels:"),
value=_(
"\N{SPEECH BALLOON} Text: {text}\n"
"\N{SPEAKER WITH THREE SOUND WAVES} Voice: {voice}"
).format(text=bold(text_channels), voice=bold(voice_channels),),
)
data.add_field(
name=_("Utility:"),
value=_(
"Owner: {owner}\nRegion: {region}\nVerif. level: {verif}\nServer ID: {id}"
).format(
owner=bold(str(guild.owner)),
region=bold(vc_regions[str(guild.region)]),
PredaaA marked this conversation as resolved.
Show resolved Hide resolved
verif=bold(verif[str(guild.verification_level)]),
id=bold(str(guild.id)),
),
inline=False,
)
data.add_field(
name=_("Misc:"),
value=_(
"AFK channel: {afk_chan}\nAFK Timeout: {afk_timeout}\nCustom emojis: {emojis}\nRoles: {roles}"
).format(
afk_chan=bold(str(guild.afk_channel))
if guild.afk_channel
else bold(_("Not set")),
afk_timeout=bold(humanize_timedelta(seconds=guild.afk_timeout)),
emojis=bold(humanize_number(len(guild.emojis))),
roles=bold(humanize_number(len(guild.roles))),
PredaaA marked this conversation as resolved.
Show resolved Hide resolved
),
inline=False,
)
if guild_features_list:
data.add_field(name=_("Server features:"), value="\n".join(guild_features_list))
if guild.premium_tier != 0:
nitro_boost = _(
"Tier {boostlevel} with {nitroboosters} boosters\n"
"File size limit: {filelimit}\n"
"Emoji limit: {emojis_limit}\n"
"VCs max bitrate: {bitrate}"
).format(
boostlevel=bold(str(guild.premium_tier)),
nitroboosters=bold(humanize_number(guild.premium_subscription_count)),
filelimit=bold(_size(guild.filesize_limit)),
emojis_limit=bold(str(guild.emoji_limit)),
bitrate=bold(_bitsize(guild.bitrate_limit)),
)
data.add_field(name=_("Nitro Boost:"), value=nitro_boost)
if guild.splash:
data.set_image(url=guild.splash_url_as(format="png"))
data.set_footer(text=joined_on)

await ctx.send(embed=data)

@commands.command()
async def urban(self, ctx, *, word):
Expand Down