diff options
-rw-r--r-- | postgres/init.sql | 7 | ||||
-rw-r--r-- | pydis_site/apps/api/models/bot/metricity.py | 20 |
2 files changed, 22 insertions, 5 deletions
diff --git a/postgres/init.sql b/postgres/init.sql index 40538492..c77fec9e 100644 --- a/postgres/init.sql +++ b/postgres/init.sql @@ -18,6 +18,7 @@ CREATE TABLE messages ( author_id varchar references users(id), is_deleted boolean, created_at timestamp, + channel_id varchar, primary key(id) ); @@ -25,12 +26,14 @@ INSERT INTO messages VALUES( 0, 0, false, - now() + now(), + '267659945086812160' ); INSERT INTO messages VALUES( 1, 0, false, - now() + INTERVAL '10 minutes' + now() + INTERVAL '10 minutes,', + '1234' ); diff --git a/pydis_site/apps/api/models/bot/metricity.py b/pydis_site/apps/api/models/bot/metricity.py index 379b0757..29d03d8b 100644 --- a/pydis_site/apps/api/models/bot/metricity.py +++ b/pydis_site/apps/api/models/bot/metricity.py @@ -2,6 +2,11 @@ from django.db import connections BLOCK_INTERVAL = 10 * 60 # 10 minute blocks +EXCLUDE_CHANNELS = [ + "267659945086812160", # Bot commands + "607247579608121354" # SeasonalBot commands +] + class NotFound(Exception): """Raised when an entity cannot be found.""" @@ -36,8 +41,16 @@ class Metricity: def total_messages(self, user_id: str) -> int: """Query total number of messages for a user.""" self.cursor.execute( - "SELECT COUNT(*) FROM messages WHERE author_id = '%s' AND NOT is_deleted", - [user_id] + """ + SELECT + COUNT(*) + FROM messages + WHERE + author_id = '%s' + AND NOT is_deleted + AND NOT %s::varchar[] @> ARRAY[channel_id] + """, + [user_id, EXCLUDE_CHANNELS] ) values = self.cursor.fetchone() @@ -63,10 +76,11 @@ class Metricity: WHERE author_id='%s' AND NOT is_deleted + AND NOT %s::varchar[] @> ARRAY[channel_id] GROUP BY interval ) block_query; """, - [BLOCK_INTERVAL, BLOCK_INTERVAL, user_id] + [BLOCK_INTERVAL, BLOCK_INTERVAL, user_id, EXCLUDE_CHANNELS] ) values = self.cursor.fetchone() |