diff options
| author | 2021-04-19 00:00:52 -0700 | |
|---|---|---|
| committer | 2021-04-19 00:00:52 -0700 | |
| commit | fc4a9e24dd23b520b9a5560215dea434ea2e03ea (patch) | |
| tree | 8baba14d03013fa3155ba5a93d8b1c92d868e92d /pydis_site/apps/api/viewsets | |
| parent | Update tests to use trailing slashes on valid urls (diff) | |
| parent | Merge pull request #472 from python-discord/ks123/ghcr-token-to-github (diff) | |
Merge branch 'main' into doc-validator
Diffstat (limited to 'pydis_site/apps/api/viewsets')
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/user.py | 31 | 
1 files changed, 31 insertions, 0 deletions
| diff --git a/pydis_site/apps/api/viewsets/bot/user.py b/pydis_site/apps/api/viewsets/bot/user.py index 829e2694..25722f5a 100644 --- a/pydis_site/apps/api/viewsets/bot/user.py +++ b/pydis_site/apps/api/viewsets/bot/user.py @@ -119,6 +119,22 @@ class UserViewSet(ModelViewSet):      - 200: returned on success      - 404: if a user with the given `snowflake` could not be found +    ### GET /bot/users/<snowflake:int>/metricity_review_data +    Gets metricity data for a single user's review by ID. + +    #### Response format +    >>> { +    ...     'joined_at': '2020-08-26T08:09:43.507000', +    ...     'top_channel_activity': [['off-topic', 15], +    ...                              ['talent-pool', 4], +    ...                              ['defcon', 2]], +    ...     'total_messages': 22 +    ... } + +    #### Status codes +    - 200: returned on success +    - 404: if a user with the given `snowflake` could not be found +      ### POST /bot/users      Adds a single or multiple new users.      The roles attached to the user(s) must be roles known by the site. @@ -262,3 +278,18 @@ class UserViewSet(ModelViewSet):              except NotFound:                  return Response(dict(detail="User not found in metricity"),                                  status=status.HTTP_404_NOT_FOUND) + +    @action(detail=True) +    def metricity_review_data(self, request: Request, pk: str = None) -> Response: +        """Request handler for metricity_review_data endpoint.""" +        user = self.get_object() + +        with Metricity() as metricity: +            try: +                data = metricity.user(user.id) +                data["total_messages"] = metricity.total_messages(user.id) +                data["top_channel_activity"] = metricity.top_channel_activity(user.id) +                return Response(data, status=status.HTTP_200_OK) +            except NotFound: +                return Response(dict(detail="User not found in metricity"), +                                status=status.HTTP_404_NOT_FOUND) | 
