aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-05-30 12:54:22 -0700
committerGravatar MarkKoz <[email protected]>2020-05-30 12:54:22 -0700
commit8c6219cd668c814f945418000c6df896de581dc1 (patch)
tree14b3d6b59817e02dae08edf421b533caa9bf1f54
parentSimplify counting of staff channels and improve efficiency (diff)
Move counting of channels to a separate method
This de-clutters the main `server_info` function and improves its readability.
-rw-r--r--bot/cogs/information.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/bot/cogs/information.py b/bot/cogs/information.py
index 887c7c127..7c39dce5f 100644
--- a/bot/cogs/information.py
+++ b/bot/cogs/information.py
@@ -60,6 +60,18 @@ class Information(Cog):
return len(channel_ids)
+ @staticmethod
+ def get_channel_type_counts(guild: Guild) -> str:
+ """Return the total amounts of the various types of channels in `guild`."""
+ channel_counter = Counter(c.type for c in guild.channels)
+ channel_type_list = []
+ for channel in channel_counter:
+ channel_type = str(channel).title()
+ channel_type_list.append(f"{channel_type} channels: {channel_counter[channel]}")
+
+ channel_type_list = sorted(channel_type_list)
+ return "\n".join(channel_type_list).strip()
+
@with_role(*constants.MODERATION_ROLES)
@command(name="roles")
async def roles_info(self, ctx: Context) -> None:
@@ -136,16 +148,7 @@ class Information(Cog):
roles = len(ctx.guild.roles)
member_count = ctx.guild.member_count
-
- # How many of each type of channel?
- channel_counter = Counter(c.type for c in ctx.guild.channels)
- channel_type_list = []
- for channel in channel_counter:
- channel_type = str(channel).title()
- channel_type_list.append(f"{channel_type} channels: {channel_counter[channel]}")
-
- channel_type_list = sorted(channel_type_list)
- channel_counts = "\n".join(channel_type_list).strip()
+ channel_counts = self.get_channel_type_counts(ctx.guild)
# How many of each user status?
statuses = Counter(member.status for member in ctx.guild.members)