aboutsummaryrefslogtreecommitdiffstats
path: root/pysite
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-05-31 14:45:03 +0100
committerGravatar Gareth Coles <[email protected]>2018-05-31 14:45:03 +0100
commitcddc4184e3c24c65e74286ea0c232b037bd88071 (patch)
tree5ab091b566e13ad1b98b0a087995e6c5b31f5104 /pysite
parentUpdate privacy policy and related migrations (diff)
[RMQ] Finish events implementation; add jammer role to constants
Diffstat (limited to 'pysite')
-rw-r--r--pysite/constants.py3
-rw-r--r--pysite/mixins.py18
2 files changed, 19 insertions, 2 deletions
diff --git a/pysite/constants.py b/pysite/constants.py
index bc2a3aa4..5bdb025f 100644
--- a/pysite/constants.py
+++ b/pysite/constants.py
@@ -23,7 +23,7 @@ class BotEventTypes(Enum):
send_message = "send_message"
send_embed = "send_embed"
- add_role = "ensure_role"
+ add_role = "add_role"
remove_role = "remove_role"
@@ -36,6 +36,7 @@ MODERATOR_ROLE = "267629731250176001"
DEVOPS_ROLE = "409416496733880320"
HELPER_ROLE = "267630620367257601"
CONTRIB_ROLE = "295488872404484098"
+JAMMERS_ROLE = "423054537079783434 "
ALL_STAFF_ROLES = (OWNER_ROLE, ADMIN_ROLE, MODERATOR_ROLE, DEVOPS_ROLE)
TABLE_MANAGER_ROLES = (OWNER_ROLE, ADMIN_ROLE, DEVOPS_ROLE)
diff --git a/pysite/mixins.py b/pysite/mixins.py
index 6b5f7187..98528891 100644
--- a/pysite/mixins.py
+++ b/pysite/mixins.py
@@ -13,6 +13,15 @@ from pysite.database import RethinkDB
from pysite.oauth import OAuthBackend
+BOT_EVENT_REQUIRED_PARAMS = {
+ "mod_log": ("level", "title", "message"),
+ "send_message": ("target", "message"),
+ "send_embed": ("target",),
+ "add_role": ("target", "role_id", "reason"),
+ "remove_role": ("target", "role_id", "reason")
+}
+
+
class DBMixin:
"""
Mixin for classes that make use of RethinkDB. It can automatically create a table with the specified primary
@@ -147,8 +156,15 @@ class RMQMixin:
if not isinstance(event_type, BotEventTypes):
raise ValueError("`event_type` must be a member of the the `pysite.constants.BotEventTypes` enum")
+ event_type = event_type.value
+ required_params = BOT_EVENT_REQUIRED_PARAMS[event_type]
+
+ for param in required_params:
+ if param not in data:
+ raise KeyError(f"Event is missing required parameter: {param}")
+
return self.rmq_send(
- {"event": event_type.value, "data": data},
+ {"event": event_type, "data": data},
routing_key=BOT_EVENT_QUEUE,
)