Browse Source

Fix some issues with MessageTypes.

Joe Clarke 4 years ago
parent
commit
c3b604c9c6
1 changed files with 26 additions and 2 deletions
  1. 26 2
      automation/spark/sparker.py

+ 26 - 2
automation/spark/sparker.py

@@ -340,6 +340,18 @@ class Sparker:
         if not self.check_token():
             return None
 
+        mt = None
+
+        try:
+            mt = MessageType(mtype)
+        except Exception as e:
+            msg = "Invalid message type: {}".format(getattr(e, "message", repr(e)))
+            if self._logit:
+                logging.error(msg)
+            else:
+                print(msg)
+            return False
+
         team_id = None
 
         if team is not None:
@@ -353,7 +365,7 @@ class Sparker:
 
         url = self.SPARK_API + "messages"
 
-        payload = {"roomId": room_id, "markdown": mtype + msg}
+        payload = {"roomId": room_id, "markdown": mt.value + msg}
 
         try:
             response = Sparker._request_with_retry(
@@ -376,6 +388,18 @@ class Sparker:
         if not self.check_token():
             return None
 
+        mt = None
+
+        try:
+            mt = MessageType(mtype)
+        except Exception as e:
+            msg = "Invalid message type: {}".format(getattr(e, "message", repr(e)))
+            if self._logit:
+                logging.error(msg)
+            else:
+                print(msg)
+            return False
+
         team_id = None
 
         if team is not None:
@@ -393,7 +417,7 @@ class Sparker:
 
         payload = {
             "roomId": room_id,
-            "markdown": mtype + msg,
+            "markdown": mt.value + msg,
             "files": (fname, bio, ftype),
         }
         m = MultipartEncoder(fields=payload)