Skip to content

Commit 0aed5f7

Browse files
committed
Add support for BumpedThreads to be stored in site
Following our move to use Redis as just a cache, this PR allows the site to store a list of threads that need to be bumped. The bot will interact with this within the ThreadBumper cog.
1 parent 30b7b42 commit 0aed5f7

File tree

9 files changed

+129
-0
lines changed

9 files changed

+129
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 3.1.14 on 2022-02-19 16:26
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
import pydis_site.apps.api.models.mixins
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('api', '0080_add_aoc_tables'),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='BumpedThread',
17+
fields=[
18+
('thread_id', models.BigIntegerField(help_text='The thread ID that should be bumped.', primary_key=True, serialize=False, validators=[django.core.validators.MinValueValidator(limit_value=0, message='Thread IDs cannot be negative.')], verbose_name='Thread ID')),
19+
],
20+
bases=(pydis_site.apps.api.models.mixins.ModelReprMixin, models.Model),
21+
),
22+
]

pydis_site/apps/api/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# flake8: noqa
22
from .bot import (
33
BotSetting,
4+
BumpedThread,
45
DocumentationLink,
56
DeletedMessage,
67
FilterList,

pydis_site/apps/api/models/bot/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# flake8: noqa
22
from .bot_setting import BotSetting
3+
from .bumped_thread import BumpedThread
34
from .deleted_message import DeletedMessage
45
from .documentation_link import DocumentationLink
56
from .filter_list import FilterList
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from django.core.validators import MinValueValidator
2+
from django.db import models
3+
4+
from pydis_site.apps.api.models.mixins import ModelReprMixin
5+
6+
7+
class BumpedThread(ModelReprMixin, models.Model):
8+
"""A list of thread IDs to be bumped."""
9+
10+
thread_id = models.BigIntegerField(
11+
primary_key=True,
12+
help_text=(
13+
"The thread ID that should be bumped."
14+
),
15+
validators=(
16+
MinValueValidator(
17+
limit_value=0,
18+
message="Thread IDs cannot be negative."
19+
),
20+
),
21+
verbose_name="Thread ID",
22+
)

pydis_site/apps/api/serializers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
AocAccountLink,
1717
AocCompletionistBlock,
1818
BotSetting,
19+
BumpedThread,
1920
DeletedMessage,
2021
DocumentationLink,
2122
FilterList,
@@ -41,6 +42,16 @@ class Meta:
4142
fields = ('name', 'data')
4243

4344

45+
class BumpedThreadSerializer(ModelSerializer):
46+
"""A class providing (de-)serialization of `BumpedThread` instances."""
47+
48+
class Meta:
49+
"""Metadata defined for the Django REST Framework."""
50+
51+
model = BumpedThread
52+
fields = ('thread_id',)
53+
54+
4455
class DeletedMessageSerializer(ModelSerializer):
4556
"""
4657
A class providing (de-)serialization of `DeletedMessage` instances.

pydis_site/apps/api/urls.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
AocAccountLinkViewSet,
77
AocCompletionistBlockViewSet,
88
BotSettingViewSet,
9+
BumpedThreadViewSet,
910
DeletedMessageViewSet,
1011
DocumentationLinkViewSet,
1112
FilterListViewSet,
@@ -32,6 +33,10 @@
3233
'bot-settings',
3334
BotSettingViewSet
3435
)
36+
bot_router.register(
37+
'bumped-threads',
38+
BumpedThreadViewSet
39+
)
3540
bot_router.register(
3641
'deleted-messages',
3742
DeletedMessageViewSet

pydis_site/apps/api/viewsets/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# flake8: noqa
22
from .bot import (
33
BotSettingViewSet,
4+
BumpedThreadViewSet,
45
DeletedMessageViewSet,
56
DocumentationLinkViewSet,
67
FilterListViewSet,

pydis_site/apps/api/viewsets/bot/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# flake8: noqa
22
from .filter_list import FilterListViewSet
33
from .bot_setting import BotSettingViewSet
4+
from .bumped_thread import BumpedThreadViewSet
45
from .deleted_message import DeletedMessageViewSet
56
from .documentation_link import DocumentationLinkViewSet
67
from .infraction import InfractionViewSet
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from rest_framework.mixins import (
2+
CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin
3+
)
4+
from rest_framework.viewsets import GenericViewSet
5+
6+
from pydis_site.apps.api.models.bot import BumpedThread
7+
from pydis_site.apps.api.serializers import BumpedThreadSerializer
8+
9+
10+
class BumpedThreadViewSet(
11+
GenericViewSet, CreateModelMixin, DestroyModelMixin, RetrieveModelMixin, ListModelMixin
12+
):
13+
"""
14+
View providing CRUD (Minus the U) operations on threads to be bumped.
15+
16+
## Routes
17+
### GET /bot/bumped-threads
18+
Returns all BumpedThread items in the database.
19+
20+
#### Response format
21+
>>> [
22+
... {
23+
... 'thread_id': "941705627405811793",
24+
... },
25+
... ...
26+
... ]
27+
28+
#### Status codes
29+
- 200: returned on success
30+
- 401: returned if unauthenticated
31+
32+
### GET /bot/bumped-threads/<thread_id:int>
33+
Returns a specific BumpedThread item from the database.
34+
35+
#### Response format
36+
>>> {
37+
... 'thread_id': "941705627405811793",
38+
... }
39+
40+
#### Status codes
41+
- 200: returned on success
42+
- 404: returned if a BumpedThread with the given thread_id was not found.
43+
44+
### POST /bot/bumped-threads
45+
Adds a single BumpedThread item to the database.
46+
47+
#### Request body
48+
>>> {
49+
... 'thread_id': int,
50+
... }
51+
52+
#### Status codes
53+
- 201: returned on success
54+
- 400: if one of the given fields is invalid
55+
56+
### DELETE /bot/bumped-threads/<thread_id:int>
57+
Deletes the BumpedThread item with the given `thread_id`.
58+
59+
#### Status codes
60+
- 204: returned on success
61+
- 404: if a BumpedThread with the given `thread_id` does not exist
62+
"""
63+
64+
serializer_class = BumpedThreadSerializer
65+
queryset = BumpedThread.objects.all()

0 commit comments

Comments
 (0)