diff options
author | 2023-01-27 22:22:06 +0200 | |
---|---|---|
committer | 2023-01-27 22:57:51 +0200 | |
commit | 963d9368b8e07d8aab04662f27bf47087f5b574c (patch) | |
tree | 72ea3b5e60babe27b169b8816a4d39853d180742 /pydis_site/apps/api/models/bot | |
parent | Update tests (diff) | |
parent | Merge pull request #860 from python-discord/official-tutorial-resource (diff) |
Merge branch 'main' into new-filter-schema
Diffstat (limited to 'pydis_site/apps/api/models/bot')
-rw-r--r-- | pydis_site/apps/api/models/bot/metricity.py | 28 | ||||
-rw-r--r-- | pydis_site/apps/api/models/bot/nomination.py | 4 |
2 files changed, 32 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 diff --git a/pydis_site/apps/api/models/bot/nomination.py b/pydis_site/apps/api/models/bot/nomination.py index 221d8534..58e70a83 100644 --- a/pydis_site/apps/api/models/bot/nomination.py +++ b/pydis_site/apps/api/models/bot/nomination.py @@ -35,6 +35,10 @@ class Nomination(ModelReprMixin, models.Model): default=False, help_text="Whether a review was made." ) + thread_id = models.BigIntegerField( + help_text="The nomination vote's thread id.", + null=True, + ) def __str__(self): """Representation that makes the target and state of the nomination immediately evident.""" |