-
-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathmoodle.py
56 lines (44 loc) · 1.56 KB
/
moodle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import requests
from api import API_PERMISSIONS
HUBURL = "https://moodle.net/local/sitecheck/check.php"
def process_pushnotification_payload(data):
extra = data.get("extra", {})
userfrom = extra.get("userfromfullname", None)
site = extra.get("site", None)
timecreated = extra.get("timecreated", None)
message = extra.get("smallmessage", None)
notif = extra.get("notification", None)
title = extra.get("sitefullname", None)
if not message:
message = extra.get("fullmessage", None)
if not title:
title = "Notification"
if "alert" not in data:
data["alert"] = {"body": message, "title": title}
data["fcm"] = {"data": extra}
if not "wns" in extra:
data["wns"] = {
"type": "toast",
"template": "ToastText01",
"text": [data["alert"]],
}
return data
def process_accesskey_payload(data):
mdlurl = data.get("url", "")
mdlsiteid = data.get("siteid", "")
params = {"siteid": mdlsiteid, "url": mdlurl}
response = requests.get(HUBURL, params=params)
result = int(response.text)
if result == 0:
raise Exception("Site not registered on moodle.net")
else:
# This is 1111 in binary means all permissions are granted
data["permission"] = (
API_PERMISSIONS["create_token"][0]
| API_PERMISSIONS["delete_token"][0]
| API_PERMISSIONS["send_notification"][0]
| API_PERMISSIONS["send_broadcast"][0]
)
return data
def process_token_payload(data):
return data