Compare commits

...

10 Commits

Author SHA1 Message Date
Dustin Pianalto
ee02452dd5 Added broadcast endpoint 2020-08-18 00:02:28 -08:00
Dustin Pianalto
cbd2b2a60a Fix bug due to method rename 2020-04-27 11:34:15 -08:00
Dustin Pianalto
381ad71925 Add git to apk install 2020-04-26 15:20:53 -08:00
Dustin Pianalto
e181fec579 Fix error from renaming method 2020-04-26 14:58:46 -08:00
Dustin Pianalto
c2d734380e Remove Collectfast from requirements 2020-04-25 22:19:20 -08:00
Dustin Pianalto
11b56c489f Remove Collectfast from requirements 2020-04-25 22:05:18 -08:00
Dustin Pianalto
d125c0f109 Add make as a dep 2020-04-25 21:43:26 -08:00
Dustin Pianalto
0fc4c69522 Remove version requirements 2020-04-25 21:28:30 -08:00
Dustin Pianalto
42e790d174 Change requests detail to get not only open requests 2020-04-25 20:40:26 -08:00
Dustin Pianalto
7d8a7d02e5 Fix typo in Wait For Message API when generating error 2020-03-11 21:07:39 -08:00
7 changed files with 90 additions and 45 deletions

View File

@ -8,7 +8,7 @@ RUN echo "geeksbot ALL (ALL) NOPASSWD: ALL" >> /etc/sudoers
RUN echo "geeksbot:docker" | chpasswd
RUN apk update && \
apk add --virtual build-deps gcc python3-dev musl-dev postgresql-dev \
apk add gcc python3-dev musl-dev postgresql-dev \
# Pillow dependencies
&& apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
# CFFI dependencies
@ -16,7 +16,7 @@ RUN apk update && \
# Translations dependencies
&& apk add gettext \
# https://docs.djangoproject.com/en/dev/ref/django-admin/#dbshell
&& apk add postgresql-client
&& apk add postgresql-client make git
RUN mkdir /code

View File

@ -105,8 +105,8 @@ ANYMAIL = {
# Collectfast
# ------------------------------------------------------------------------------
# https://github.com/antonagestam/collectfast#installation
INSTALLED_APPS = ["collectfast"] + INSTALLED_APPS # noqa F405
AWS_PRELOAD_METADATA = True
# INSTALLED_APPS = ["collectfast"] + INSTALLED_APPS # noqa F405
# AWS_PRELOAD_METADATA = True
# LOGGING
# ------------------------------------------------------------------------------

View File

@ -235,9 +235,13 @@ class AdminRequest(models.Model):
return cls.objects.filter(guild__id=guild_id).filter(completed=False)
@classmethod
def get_open_request_by_id(cls, guild_id, request_id):
def get_requests_by_guild(cls, guild_id):
return cls.objects.filter(guild__id=guild_id)
@classmethod
def get_request_by_id(cls, guild_id, request_id):
try:
return cls.get_open_requests_by_guild(guild_id).get(id=request_id)
return cls.get_requests_by_guild(guild_id).get(id=request_id)
except ObjectDoesNotExist:
return None
@ -262,7 +266,7 @@ class AdminComment(models.Model):
if not (request_id and author_id and content):
return create_error_response('Request, Author, and Content are required fields',
status=status.HTTP_400_BAD_REQUEST)
request = AdminRequest.get_open_request_by_id(guild_id, request_id)
request = AdminRequest.get_request_by_id(guild_id, request_id)
if not isinstance(request, AdminRequest):
return create_error_response("Admin Request Does Not Exist",
status=status.HTTP_404_NOT_FOUND)

View File

@ -49,8 +49,9 @@ class MessageDetailAPI(APIView):
if message:
return create_success_response(message, status.HTTP_200_OK, many=False)
else:
return create_error_response("Message Does Not Exist",
status=status.HTTP_404_NOT_FOUND)
return create_error_response(
"Message Does Not Exist", status=status.HTTP_404_NOT_FOUND
)
def put(self, request, id, format=None):
data = dict(request.data)
@ -58,8 +59,9 @@ class MessageDetailAPI(APIView):
if message:
return message.update_message(data)
else:
return create_error_response('Message Does Not Exist',
status=status.HTTP_404_NOT_FOUND)
return create_error_response(
"Message Does Not Exist", status=status.HTTP_404_NOT_FOUND
)
class WaitForMessageAPI(APIView):
@ -72,8 +74,10 @@ class WaitForMessageAPI(APIView):
sleep(0.1)
try_count += 1
if try_count > timeout * 10:
return create_error_response("Timeout reached before message is available.",
statu=status.HTTP_404_NOT_FOUND)
return create_error_response(
"Timeout reached before message is available.",
status=status.HTTP_404_NOT_FOUND,
)
message = Message.get_message_by_id(id)
return create_success_response(message, status=status.HTTP_200_OK)
@ -87,7 +91,9 @@ class RequestsAPI(PaginatedAPIView):
if page is not None:
return create_request_success_response(page, status.HTTP_200_OK, many=True)
if requests:
return create_request_success_response(requests, status.HTTP_200_OK, many=True)
return create_request_success_response(
requests, status.HTTP_200_OK, many=True
)
return create_error_response("No requests found")
def post(self, request, guild_id, format=None):
@ -104,7 +110,9 @@ class UserRequestsAPI(PaginatedAPIView):
if page is not None:
return create_request_success_response(page, status.HTTP_200_OK, many=True)
if requests:
return create_request_success_response(requests, status.HTTP_200_OK, many=True)
return create_request_success_response(
requests, status.HTTP_200_OK, many=True
)
return create_error_response("No requests found")
@ -112,32 +120,36 @@ class RequestDetailAPI(APIView):
permission_classes = [IsAuthenticated]
def get(self, req, guild_id, request_id, format=None):
req = AdminRequest.get_open_request_by_id(guild_id, request_id)
req = AdminRequest.get_request_by_id(guild_id, request_id)
if req:
comments = AdminComment.get_comments_by_request(req)
if comments:
data = AdminRequestSerializer(req).data
data['comments'] = AdminCommentSerializer(comments, many=True).data
data["comments"] = AdminCommentSerializer(comments, many=True).data
return Response(data, status.HTTP_200_OK)
else:
return create_request_success_response(req, status.HTTP_200_OK, many=False)
return create_request_success_response(
req, status.HTTP_200_OK, many=False
)
else:
return create_error_response("That Request Does Not Exist",
status=status.HTTP_404_NOT_FOUND)
return create_error_response(
"That Request Does Not Exist", status=status.HTTP_404_NOT_FOUND
)
def put(self, request, guild_id, request_id, format=None):
req = AdminRequest.get_open_request_by_id(guild_id, request_id)
req = AdminRequest.get_request_by_id(guild_id, request_id)
if req:
data = dict(request.data)
return req.update_request(data)
return create_error_response("That Request Does Not Exist",
status=status.HTTP_404_NOT_FOUND)
return create_error_response(
"That Request Does Not Exist", status=status.HTTP_404_NOT_FOUND
)
def delete(self, request, guild_id, request_id, format=None):
data = dict(request.data)
request = AdminRequest.get_open_request_by_id(guild_id, request_id)
data['completed'] = True
data['completed_at'] = datetime.utcnow()
request = AdminRequest.get_request_by_id(guild_id, request_id)
data["completed"] = True
data["completed_at"] = datetime.utcnow()
return request.update_request(data)
@ -147,7 +159,9 @@ class CommentsAPI(PaginatedAPIView):
def get(self, request, guild_id, request_id, format=None):
comments = AdminComment.get_comments_by_request(request_id)
if comments:
return create_comment_success_response(comments, status=status.HTTP_200_OK, many=True)
return create_comment_success_response(
comments, status=status.HTTP_200_OK, many=True
)
return create_error_response("No Comments found")
def post(self, request, guild_id, request_id, format=None):
@ -172,9 +186,14 @@ class CommentDetailAPI(APIView):
comment = AdminComment.get_comment_by_id(comment_id)
if comment:
if comment.request.id != request_id:
return create_error_response("That comment is not for this request",
status=status.HTTP_400_BAD_REQUEST)
return create_comment_success_response(comment, status.HTTP_200_OK, many=False)
return create_error_response(
"That comment is not for this request",
status=status.HTTP_400_BAD_REQUEST,
)
return create_comment_success_response(
comment, status.HTTP_200_OK, many=False
)
else:
return create_error_response("Comment Does Not Exist",
status=status.HTTP_404_NOT_FOUND)
return create_error_response(
"Comment Does Not Exist", status=status.HTTP_404_NOT_FOUND
)

View File

@ -1,6 +1,6 @@
from django.urls import path
from .views import RCONServersAPI, RCONServerDetailAPI, ListPlayers, WhitelistAPI
from .views import RCONServersAPI, RCONServerDetailAPI, ListPlayers, WhitelistAPI, BroadcastAPI
app_name = "rcon_api"
urlpatterns = [
@ -8,4 +8,5 @@ urlpatterns = [
path("<str:guild_id>/<str:name>/", view=RCONServerDetailAPI.as_view(), name="server_detail"),
path("<str:guild_id>/<str:name>/listplayers/", view=ListPlayers.as_view(), name='listplayers'),
path("<str:guild_id>/<str:name>/whitelist/", view=WhitelistAPI.as_view(), name='whitelist'),
path("<str:guild_id>/<str:name>/broadcast/", view=BroadcastAPI.as_view(), name='broadcast'),
]

View File

@ -96,3 +96,24 @@ class WhitelistAPI(APIView):
status=status.HTTP_408_REQUEST_TIMEOUT)
resp = ark.whitelist(user.steam_id)
return create_rcon_response(resp, status=status.HTTP_200_OK)
class BroadcastAPI(APIView):
permission_classes = [IsAuthenticated]
def post(self, request, guild_id, name, format=None):
message = request.data.get('message')
if not message:
return create_error_response('A message is required',
status=status.HTTP_400_BAD_REQUEST)
server: RconServer = RconServer.get_server(guild_id, name)
if not server:
return create_error_response('RCON Server Does Not Exist',
status=status.HTTP_404_NOT_FOUND)
ark = arcon.ARKServer(host=server.ip, port=server.port, password=server.password)
connected = ark.connect()
if not connected == 1:
return create_error_response('Connection Failure',
status=status.HTTP_408_REQUEST_TIMEOUT)
resp = ark.broadcast(message)
return create_rcon_response(resp, status=status.HTTP_200_OK)

View File

@ -1,22 +1,22 @@
# Django
# ------------------------------------------------------------------------------
django==2.2.4 # pyup: < 3.0 # https://www.djangoproject.com/
django-environ==0.4.5 # https://github.com/joke2k/django-environ
django-model-utils==3.2.0 # https://github.com/jazzband/django-model-utils
django-allauth==0.39.1 # https://github.com/pennersr/django-allauth
django-crispy-forms==1.7.2 # https://github.com/django-crispy-forms/django-crispy-forms
django-redis==4.10.0 # https://github.com/niwinz/django-redis
django-anymail[mailgun]==6.1.0 # https://github.com/anymail/django-anymail
django # pyup: < 3.0 # https://www.djangoproject.com/
django-environ # https://github.com/joke2k/django-environ
django-model-utils # https://github.com/jazzband/django-model-utils
django-allauth # https://github.com/pennersr/django-allauth
django-crispy-forms # https://github.com/django-crispy-forms/django-crispy-forms
django-redis # https://github.com/niwinz/django-redis
django-anymail[mailgun] # https://github.com/anymail/django-anymail
django-debug-toolbar
django-extensions
# Django REST Framework
djangorestframework==3.10.2 # https://github.com/encode/django-rest-framework
coreapi==2.3.3 # https://github.com/core-api/python-client
djangorestframework # https://github.com/encode/django-rest-framework
coreapi # https://github.com/core-api/python-client
gevent
gunicorn==19.9.0 # https://github.com/benoitc/gunicorn
psycopg2==2.8.3 --no-binary psycopg2 # https://github.com/psycopg/psycopg2
Collectfast==1.0.0 # https://github.com/antonagestam/collectfast
gunicorn # https://github.com/benoitc/gunicorn
psycopg2 --no-binary psycopg2 # https://github.com/psycopg/psycopg2
# Collectfast # https://github.com/antonagestam/collectfast
python-valve