aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/models/bot
diff options
context:
space:
mode:
authorGravatar Exenifix <[email protected]>2022-12-04 13:19:08 +0300
committerGravatar GitHub <[email protected]>2022-12-04 13:19:08 +0300
commit92a9669ee06ea6341082aaceb6f2d2ad5585d007 (patch)
treef45b37e10e0e59822a795d5a9a2e0bc403501a23 /pydis_site/apps/api/models/bot
parentUpdate pydis_site/apps/content/resources/guides/python-guides/docker-hosting-... (diff)
parentRename vps_services.md to vps-services.md (#808) (diff)
Merge branch 'python-discord:main' into main
Diffstat (limited to 'pydis_site/apps/api/models/bot')
-rw-r--r--pydis_site/apps/api/models/bot/metricity.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/pydis_site/apps/api/models/bot/metricity.py b/pydis_site/apps/api/models/bot/metricity.py
index abd25ef0..f53dd33c 100644
--- a/pydis_site/apps/api/models/bot/metricity.py
+++ b/pydis_site/apps/api/models/bot/metricity.py
@@ -130,3 +130,31 @@ class Metricity:
raise NotFoundError()
return values
+
+ def total_messages_in_past_n_days(
+ self,
+ user_ids: list[str],
+ days: int
+ ) -> list[tuple[str, int]]:
+ """
+ Query activity by a list of users in the past `days` days.
+
+ Returns a list of (user_id, message_count) tuples.
+ """
+ self.cursor.execute(
+ """
+ SELECT
+ author_id, COUNT(*)
+ FROM messages
+ WHERE
+ author_id IN %s
+ AND NOT is_deleted
+ AND channel_id NOT IN %s
+ AND created_at > now() - interval '%s days'
+ GROUP BY author_id
+ """,
+ [tuple(user_ids), EXCLUDE_CHANNELS, days]
+ )
+ values = self.cursor.fetchall()
+
+ return values