Fixed a few stability issues and added support for dynamic module reloading
This commit is contained in:
		
							parent
							
								
									6e544331a2
								
							
						
					
					
						commit
						f621ec4aad
					
				
							
								
								
									
										22
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								main.py
									
									
									
									
									
								
							@ -1,4 +1,5 @@
 | 
				
			|||||||
from telegram.ext import Updater, MessageHandler, Filters
 | 
					from telegram.ext import Updater, MessageHandler, Filters
 | 
				
			||||||
 | 
					import datetime
 | 
				
			||||||
import codecs
 | 
					import codecs
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
@ -30,13 +31,13 @@ class ModuleV1:
 | 
				
			|||||||
        self.predefine = predefine
 | 
					        self.predefine = predefine
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if self.predefine:
 | 
					        if self.predefine:
 | 
				
			||||||
            self.predefine()
 | 
					            self.set_predefine()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # set environmental variables
 | 
					    # set environmental variables
 | 
				
			||||||
    def set_env(self):
 | 
					    def set_env(self):
 | 
				
			||||||
        self.RESPONCE = ""
 | 
					        self.RESPONCE = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def predefine(self):
 | 
					    def set_predefine(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            exec(self.predefine)
 | 
					            exec(self.predefine)
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
@ -52,6 +53,7 @@ class ModuleV1:
 | 
				
			|||||||
            return self.RESPONCE
 | 
					            return self.RESPONCE
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            print("[ERROR] module: module \"{}\" ({}) raised exception \"{}\"".format(self.path, self.alias, e))
 | 
					            print("[ERROR] module: module \"{}\" ({}) raised exception \"{}\"".format(self.path, self.alias, e))
 | 
				
			||||||
 | 
					            return ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# module control unit
 | 
					# module control unit
 | 
				
			||||||
@ -157,7 +159,21 @@ def queue_processor():
 | 
				
			|||||||
            msg = message_queue[0]
 | 
					            msg = message_queue[0]
 | 
				
			||||||
            print("[DEBUG] queue_processor: {}".format(msg)) # debug
 | 
					            print("[DEBUG] queue_processor: {}".format(msg)) # debug
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # modules will be used in here
 | 
					            # 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:
 | 
					            for mod in mcu.modules:
 | 
				
			||||||
                if mod.enabled:
 | 
					                if mod.enabled:
 | 
				
			||||||
                    if mod.version == 1:
 | 
					                    if mod.version == 1:
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user