1
1
import typing
2
2
from collections import OrderedDict
3
3
4
- from django .core . exceptions import ObjectDoesNotExist
4
+ from django .db . models import Q
5
5
from rest_framework import status
6
6
from rest_framework .decorators import action
7
7
from rest_framework .pagination import PageNumberPagination
@@ -261,12 +261,10 @@ def metricity_data(self, request: Request, pk: str = None) -> Response:
261
261
"""Request handler for metricity_data endpoint."""
262
262
user = self .get_object ()
263
263
264
- try :
265
- Infraction .objects .get (user__id = user .id , active = True , type = "voice_ban" )
266
- except ObjectDoesNotExist :
267
- voice_banned = False
268
- else :
269
- voice_banned = True
264
+ has_voice_infraction = Infraction .objects .filter (
265
+ Q (user__id = user .id , active = True ),
266
+ Q (type = "voice_ban" ) | Q (type = "voice_mute" )
267
+ ).exists ()
270
268
271
269
with Metricity () as metricity :
272
270
try :
@@ -275,7 +273,7 @@ def metricity_data(self, request: Request, pk: str = None) -> Response:
275
273
data ["total_messages" ] = metricity .total_messages (user .id )
276
274
data ["activity_blocks" ] = metricity .total_message_blocks (user .id )
277
275
278
- data ["voice_banned " ] = voice_banned
276
+ data ["voice_gate_blocked " ] = has_voice_infraction
279
277
return Response (data , status = status .HTTP_200_OK )
280
278
except NotFoundError :
281
279
return Response (dict (detail = "User not found in metricity" ),
0 commit comments