-
Notifications
You must be signed in to change notification settings - Fork 0
Writing a module
Michael Mikovsky edited this page Feb 21, 2024
·
1 revision
Each module is a folder in the /modules/ directory that must include several files:
- A modules.json file which contains metadata about the module.
- A main.py file which can be renamed by changing the entrypoint in modules.json
It can also include:
- HTML files, which are specified in the tab
- More python files
Here is a bare-bones example of a module:
/modules/myModule/
- modules.json
- main.py
/modules/myModule/modules.json:
{
"name": "myModule",
"creators": ["ASTATIN3"],
"version": "1.0",
"entrypoint": "modules/myModule/main.py",
"tabs": []
}/modules/myModule/main.py:
mm = None
def init(moduleMaster):
global mm
mm = moduleMaster
def main():
passThis example is literally just the code that will not cause an error.
And here is an example with more code in it:
/modules/myModule/
- modules.json
- main.py
- example.html
/modules/myModule/modules.json:
{
"name": "myModule",
"creators": ["ASTATIN3"],
"version": "1.0",
"entrypoint": "modules/myModule/main.py",
"tabs": [
{
"name": "example",
"defaultPage": "example",
"pages": [
{
"type": "page",
"name": "example",
"requiredPermGroup": "",
"location": "modules/example/example.html"
}
]
}
]
}/modules/myModule/example.html
<main class="container">
<h4>This is a very simple example module!</h4>
<button id="testButton" onclick="testFunc()">test!</button>
</main>
<script>
window.main = ()=>{}
function getel(el) {return document.getElementById(el)}
function testFunc() {
window.send('exampleTest', {
data: 'test!'
})
}
</script>/modules/myModule/main.py:
mm = None
def welcome(ac):
mm.sendPopupColor(ac.rawClient, 'Welcome!', 'test!', '#006000', True)
def test(ac, data):
mm.sendPopupColor(ac.rawClient, 'test!', 'test!', '#600060', True)
def init(moduleMaster):
global mm
mm = moduleMaster
mm.addAuthEventListener('exampleTest', test)
mm.addPageEventListener('/myModule/example', welcome)
def main():
passThis example hosts a tab, with a page, that when you load it will send a welcome popup to the client, and the page also has a button, when clicked will send a message to the module, then the module will send another popup back to the client.
If you want more in-depth examples, look at the main module