aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2021-11-22 18:14:43 +0000
committerGravatar Chris Lovering <[email protected]>2021-11-22 18:18:01 +0000
commit1872bb12766bf3c56284ef614b5ab22166b488e5 (patch)
tree9431058d20052fb2196895573a2dc3b942ac40c7
parentMerge pull request #1959 from python-discord/allow-reply-in-remind (diff)
Deal with activity_blocks not being returned by site
We are planning to change metricity endpoints on site so that activcity_blocks are not returned if the user has more than 1000 messages. This is because the query to calculate those blocks can get expensive at a high message count. To deal with this, both places activity_blocks are used has been changed to reflect this planned behaviour.
-rw-r--r--bot/exts/info/information.py7
-rw-r--r--bot/exts/moderation/voice_gate.py6
2 files changed, 11 insertions, 2 deletions
diff --git a/bot/exts/info/information.py b/bot/exts/info/information.py
index dab2dbb6c..5b48495dc 100644
--- a/bot/exts/info/information.py
+++ b/bot/exts/info/information.py
@@ -422,7 +422,12 @@ class Information(Cog):
activity_output = "No activity"
else:
activity_output.append(user_activity["total_messages"] or "No messages")
- activity_output.append(user_activity["activity_blocks"] or "No activity")
+
+ if (activity_blocks := user_activity.get("activity_blocks")) is not None:
+ # activity_blocks is not included in the response if the user has a lot of messages
+ activity_output.append(activity_blocks or "No activity") # Special case when activity_blocks is 0.
+ else:
+ activity_output.append("Too many to count!")
activity_output = "\n".join(
f"{name}: {metric}" for name, metric in zip(["Messages", "Activity blocks"], activity_output)
diff --git a/bot/exts/moderation/voice_gate.py b/bot/exts/moderation/voice_gate.py
index 31799ec73..ae55a03a0 100644
--- a/bot/exts/moderation/voice_gate.py
+++ b/bot/exts/moderation/voice_gate.py
@@ -171,8 +171,12 @@ class VoiceGate(Cog):
),
"total_messages": data["total_messages"] < GateConf.minimum_messages,
"voice_banned": data["voice_banned"],
- "activity_blocks": data["activity_blocks"] < GateConf.minimum_activity_blocks
}
+ if activity_blocks := data.get("activity_blocks"):
+ # activity_blocks is not included in the response if the user has a lot of messages.
+ # Only check if the user has enough activity blocks if it is included.
+ checks["activity_blocks"] = activity_blocks < GateConf.minimum_activity_blocks
+
failed = any(checks.values())
failed_reasons = [MESSAGE_FIELD_MAP[key] for key, value in checks.items() if value is True]
[self.bot.stats.incr(f"voice_gate.failed.{key}") for key, value in checks.items() if value is True]