Compare commits
2 Commits
4a65d8d07d
...
e874b98896
Author | SHA1 | Date |
---|---|---|
dymik739 | e874b98896 | |
dymik739 | baa8a4c7ae |
12
README.md
12
README.md
|
@ -34,6 +34,7 @@ Firstly, you want to make a file called "meta.json" - it will let the module loa
|
|||
"start_on_boot": true, # tells mod loader to start your module automatically; false by default
|
||||
"version": 1, # this points to the specific version of modVM your code needs to run; 1 by default
|
||||
"alias": "testapp" # adds an alias to your module which can be later specified in control commands
|
||||
"predefine": "predefine.py" # locates your predefine code (it is being run only once on module load
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -44,5 +45,14 @@ After that you can start writing your code in the index.py file; every code is d
|
|||
- you can use modules already available to you (json, codecs); please, try to avoid importing unneccesary modules
|
||||
- if you need to access files amd folders in your module dicertory, you can easily do so by using self.path + "filename"; self.path always contains your current folder name
|
||||
- please, avoid using time.sleep() in any scenario; modules are syncronous, so usage of this method will stall the entire bot
|
||||
- in order to define persistent variables you can set them in your predefine file
|
||||
|
||||
If you want to submit your code, please check if it works by running the bot and testing the output; if you want to submit the code for someone to do more work on it, you should set "start_on_boot" to "false" in meta.json file (the same should be done for testing/unstable modules)
|
||||
If you want to submit your code, please check if it works by testing the output (see "testing" section below); if you want to submit the code for someone to do more work on it, you should set "start_on_boot" to "false" in meta.json file (the same should be done for testing/unstable modules)
|
||||
|
||||
## Testing modules locally
|
||||
In order to test the modules/bot offline you can run the module-testing.py file - it behaves just like the bot, but allows you to enter any message, doesn't require Internet connection and bot token. This is a good way to test your modules before publishing them.
|
||||
|
||||
It can be used like this:
|
||||
```
|
||||
python3 module-testing.py
|
||||
```
|
||||
|
|
|
@ -154,40 +154,49 @@ class ModuleControlUnit:
|
|||
# synchronous message processor
|
||||
def queue_processor():
|
||||
while True:
|
||||
if len(message_queue) > 0:
|
||||
msg = message_queue[0]
|
||||
print("[DEBUG] queue_processor: {}".format(msg)) # debug
|
||||
|
||||
# check for control commands
|
||||
if msg["chat"]["id"] == 575246355:
|
||||
if msg["text"][0] == "$":
|
||||
command = msg["text"][1:].split(" ")
|
||||
|
||||
if len(command) >= 2 and command[0] == "module":
|
||||
if command[1] == "reload":
|
||||
print("[INFO] Module reloading triggered by a command")
|
||||
del mcu.modules[:]
|
||||
mcu.reload_modules()
|
||||
|
||||
del message_queue[0]
|
||||
continue
|
||||
|
||||
# modules are used in here
|
||||
for mod in mcu.modules:
|
||||
if mod.enabled:
|
||||
if mod.version == 1:
|
||||
responce = mod.process(msg)
|
||||
if len(responce) > 0:
|
||||
#updater.bot.send_message(chat_id = msg.chat.id, text = responce)
|
||||
print("Responded using module {} ({}) with text: {}".format(mod.path, mod.alias, responce))
|
||||
break
|
||||
|
||||
del message_queue[0]
|
||||
else:
|
||||
if STOP_REQUESTED:
|
||||
break
|
||||
try:
|
||||
if len(message_queue) > 0:
|
||||
msg = message_queue[0]
|
||||
print("[DEBUG] queue_processor: {}".format(msg)) # debug
|
||||
|
||||
# check for control commands
|
||||
if msg["chat"]["id"] == 575246355:
|
||||
if msg["text"][0] == "$":
|
||||
command = msg["text"][1:].split(" ")
|
||||
|
||||
if len(command) >= 2 and command[0] == "module":
|
||||
if command[1] == "reload":
|
||||
print("[INFO] Module reloading triggered by a command")
|
||||
del mcu.modules[:]
|
||||
mcu.reload_modules()
|
||||
|
||||
del message_queue[0]
|
||||
continue
|
||||
|
||||
# modules are used in here
|
||||
for mod in mcu.modules:
|
||||
if mod.enabled:
|
||||
if mod.version == 1:
|
||||
responce = mod.process(msg)
|
||||
if len(responce) > 0:
|
||||
updater.bot.send_message(chat_id = msg.chat.id, text = responce)
|
||||
print("Responded using module {} ({}) with text: {}".format(mod.path, mod.alias, responce))
|
||||
break
|
||||
|
||||
del message_queue[0]
|
||||
else:
|
||||
time.sleep(1)
|
||||
if STOP_REQUESTED:
|
||||
break
|
||||
else:
|
||||
time.sleep(1)
|
||||
except Exception as e:
|
||||
print("[ERROR] queue_processor: current message queue: {}".format(message_queue))
|
||||
print("[ERROR] queue_processor: error while processing message, trying to delete it...")
|
||||
try:
|
||||
del message_queue[0]
|
||||
print("[INFO] queue_processor: deleted broken message from the queue")
|
||||
except:
|
||||
print("[WARN] queue_processor: message seems absent, whatever")
|
||||
|
||||
print("[INFO] queue_processor thread stops successfully")
|
||||
|
||||
|
|
Loading…
Reference in New Issue