parent
02ab21aafc
commit
229bfffb58
16
api/api.py
16
api/api.py
|
@ -64,22 +64,6 @@ def discord_notification(message='', embeds=None, ping=False):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def discord_webhook(webhook_name=None, message=None, embed=None, ping=False):
|
|
||||||
webhook = getattr(settings, 'DISCORD_{}_WEBHOOK'.format(webhook_name.upper()), getattr(settings, 'DISCORD_WEBHOOK', None))
|
|
||||||
if webhook and (message or embed):
|
|
||||||
ping_list = getattr(settings, 'DISCORD_PING_LIST', [])
|
|
||||||
if ping and ping_list:
|
|
||||||
ping_list = ["<@&{0}>".format(ping) for ping in ping_list]
|
|
||||||
message = "{0}\n{1}".format(" ".join(ping_list), message)
|
|
||||||
data = {}
|
|
||||||
if message:
|
|
||||||
data['content'] = message
|
|
||||||
if embed:
|
|
||||||
data['embeds'] = embed
|
|
||||||
return requests.post(webhook, json=data)
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def strip_format(message):
|
def strip_format(message):
|
||||||
return message.replace("§0", "").replace("§1", "").replace("§2", "").replace("§3", "").replace("§4", "") \
|
return message.replace("§0", "").replace("§1", "").replace("§2", "").replace("§3", "").replace("§4", "") \
|
||||||
|
|
|
@ -2,6 +2,11 @@ from django.db import models
|
||||||
from minecraft_manager.api.api import generate_password
|
from minecraft_manager.api.api import generate_password
|
||||||
|
|
||||||
|
|
||||||
|
class TokenManager(models.Manager):
|
||||||
|
def get_queryset(self):
|
||||||
|
return super(TokenManager, self).get_queryset().none()
|
||||||
|
|
||||||
|
|
||||||
class Token(models.Model):
|
class Token(models.Model):
|
||||||
key = models.CharField("Key", default=generate_password, max_length=50, unique=True)
|
key = models.CharField("Key", default=generate_password, max_length=50, unique=True)
|
||||||
description = models.CharField("Description", max_length=200, blank=True)
|
description = models.CharField("Description", max_length=200, blank=True)
|
||||||
|
@ -16,6 +21,8 @@ class Token(models.Model):
|
||||||
model_post_permission = models.BooleanField("Model POST", default=False)
|
model_post_permission = models.BooleanField("Model POST", default=False)
|
||||||
stats_get_permission = models.BooleanField("Stats GET", default=False)
|
stats_get_permission = models.BooleanField("Stats GET", default=False)
|
||||||
stats_post_permission = models.BooleanField("Stats POST", default=False)
|
stats_post_permission = models.BooleanField("Stats POST", default=False)
|
||||||
|
objects = models.Manager()
|
||||||
|
api = TokenManager()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def display(self):
|
def display(self):
|
||||||
|
|
|
@ -10,9 +10,9 @@ Model API
|
||||||
---------
|
---------
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
You will need to pass the API password with any request in order for the API to respond. |br|
|
You will need to pass a token with any request in order for the API to respond. |br|
|
||||||
The API will only respond to an authenticated user or a request containing the correct API password. |br|
|
The API will only respond to an authenticated user or a request containing a valid token. |br|
|
||||||
Send the password with the key ``api``
|
Send the token with the key ``api``
|
||||||
|
|
||||||
The model API is used to query any of the :ref:`models` and get back results in a JSON format.
|
The model API is used to query any of the :ref:`models` and get back results in a JSON format.
|
||||||
|
|
||||||
|
|
|
@ -153,11 +153,27 @@ Worlds
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
Warning
|
Ticket Note
|
||||||
-------
|
-----------
|
||||||
|
|
||||||
Severity
|
|
||||||
~~~~~~~~
|
``author`` - User_
|
||||||
|
|
||||||
|
``ticket`` - Ticket_
|
||||||
|
|
||||||
|
``message`` - Text
|
||||||
|
|
||||||
|
``last_update`` - DateTime
|
||||||
|
|
||||||
|
``date`` - DateTime
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Note
|
||||||
|
----
|
||||||
|
|
||||||
|
Importance
|
||||||
|
~~~~~~~~~~
|
||||||
|
|
||||||
``L`` - Low
|
``L`` - Low
|
||||||
|
|
||||||
|
@ -169,7 +185,7 @@ Severity
|
||||||
|
|
||||||
``message`` - Text
|
``message`` - Text
|
||||||
|
|
||||||
``severity`` - Severity_
|
``importance`` - Importance_
|
||||||
|
|
||||||
``staff`` - User_
|
``staff`` - User_
|
||||||
|
|
||||||
|
@ -198,27 +214,3 @@ Alert
|
||||||
``date`` - DateTime
|
``date`` - DateTime
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
Note
|
|
||||||
----
|
|
||||||
|
|
||||||
Notable
|
|
||||||
~~~~~~~
|
|
||||||
|
|
||||||
``PL`` - Player Table
|
|
||||||
|
|
||||||
``TI`` - Ticket Table
|
|
||||||
|
|
||||||
``WA`` - Warning Table
|
|
||||||
|
|
||||||
``author`` - User_
|
|
||||||
|
|
||||||
``ref_table`` - Notable_
|
|
||||||
|
|
||||||
``ref_id`` - Text (the ID of the row in the ``ref_table``)
|
|
||||||
|
|
||||||
``message`` - Text
|
|
||||||
|
|
||||||
``last_update`` - DateTime
|
|
||||||
|
|
||||||
``date`` - DateTime
|
|
Loading…
Reference in New Issue