From 77c8d471e43188d8f591666d1bf7ee1b8593c5e8 Mon Sep 17 00:00:00 2001 From: klemek Date: Thu, 14 Jan 2021 11:12:47 +0100 Subject: [PATCH] fix presence message --- src/data_types/presence.py | 19 +++++++++++++------ src/scanners/presence_scanner.py | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/data_types/presence.py b/src/data_types/presence.py index 6dd2c84..e48de75 100644 --- a/src/data_types/presence.py +++ b/src/data_types/presence.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Optional from collections import defaultdict @@ -20,13 +20,20 @@ class Presence: msg_count: int, total_msg: int, *, + chan_count: Optional[int], show_top_channel: bool, member_specific: bool, ) -> List[str]: ret = [] + if chan_count is None: + type = "server's" + elif chan_count == 1: + type = "channel's" + else: + type = "channels'" if member_specific: ret += [ - f"- **messages**: {msg_count:,} ({percent(msg_count/total_msg)} of server's)" + f"- **messages**: {msg_count:,} ({percent(msg_count/total_msg)} of {type})" ] if show_top_channel: top_channel = top_key(self.channel_usage) @@ -40,14 +47,14 @@ class Presence: ] if member_specific: ret += [ - f"- **most contributed channel**: {channel_mention(found_in)} ({self.channel_usage[found_in]:,} msg, {percent(self.channel_usage[found_in]/self.channel_total[found_in])} of channel's)" + f"- **most contributed channel**: {channel_mention(found_in)} ({self.channel_usage[found_in]:,} msg, {percent(self.channel_usage[found_in]/self.channel_total[found_in])} of {type})" ] if member_specific: if len(self.mentions) > 0: top_mention = top_key(self.mentions) mention_sum = sum(self.mentions.values()) ret += [ - f"- **was mentioned**: {plural(mention_sum, 'time')} ({percent(mention_sum/self.mention_count)} of server's)", + f"- **was mentioned**: {plural(mention_sum, 'time')} ({percent(mention_sum/self.mention_count)} of {type})", f"- **mostly mentioned by**: {mention(top_mention)} ({plural(self.mentions[top_mention], 'time')}, {percent(self.mentions[top_mention]/mention_sum)})", ] if len(self.mention_others) > 0: @@ -55,7 +62,7 @@ class Presence: mention_sum = sum(self.mention_others.values()) if member_specific: ret += [ - f"- **mentioned others**: {plural(mention_sum, 'time')} ({percent(mention_sum/self.mention_count)} of server's)", + f"- **mentioned others**: {plural(mention_sum, 'time')} ({percent(mention_sum/self.mention_count)} of {type})", f"- **mostly mentioned**: {mention(top_mention)} ({plural(self.mention_others[top_mention], 'time')}, {percent(self.mention_others[top_mention]/mention_sum)})", ] else: @@ -74,5 +81,5 @@ class Presence: if member_specific: ret[ -2 - ] += f" ({percent(total_used/self.used_reaction_total)} of server's)" + ] += f" ({percent(total_used/self.used_reaction_total)} of {type})" return ret diff --git a/src/scanners/presence_scanner.py b/src/scanners/presence_scanner.py index 765b64b..168eadd 100644 --- a/src/scanners/presence_scanner.py +++ b/src/scanners/presence_scanner.py @@ -43,6 +43,7 @@ class PresenceScanner(Scanner): res += self.pres.to_string( self.msg_count, self.total_msg, + chan_count=len(self.channels) if not self.full else None, show_top_channel=(len(self.channels) > 1), member_specific=self.member_specific, )