add support for parse_mode selection in all module APIs and update modules to respect these changes
This commit is contained in:
+14
-9
@@ -41,6 +41,7 @@ class ModuleV1:
|
||||
# set environmental variables
|
||||
def set_env(self):
|
||||
self.RESPONSE = ""
|
||||
self.FORMAT = ""
|
||||
|
||||
def set_predefine(self):
|
||||
try:
|
||||
@@ -56,11 +57,11 @@ class ModuleV1:
|
||||
self.MESSAGE = msg
|
||||
try:
|
||||
exec(self.code)
|
||||
return self.RESPONSE
|
||||
return self.RESPONSE, self.FORMAT
|
||||
except Exception as e:
|
||||
print(f"[ERROR] module v1: module \"{self.path}\" ({self.alias}) raised exception \"{e}\"")
|
||||
print(f"[ERROR] module v1: traceback:\ntraceback.format_exc()")
|
||||
return ""
|
||||
return "", None
|
||||
|
||||
|
||||
class ModuleV2:
|
||||
@@ -75,12 +76,11 @@ class ModuleV2:
|
||||
# running the module
|
||||
def process(self, msg):
|
||||
try:
|
||||
responce = self.obj.process(msg, self.path)
|
||||
return responce
|
||||
return self.obj.process(msg, self.path)
|
||||
except Exception as e:
|
||||
print(f"[ERROR] module v2: module \"{self.path}\" ({self.alias}) raised exception \"{e}\"")
|
||||
print(f"[ERROR] module v2: traceback:\n{traceback.format_exc()}")
|
||||
return None
|
||||
return None, None
|
||||
|
||||
|
||||
# module control unit
|
||||
@@ -191,11 +191,16 @@ def queue_processor():
|
||||
# modules are used in here
|
||||
for mod in mcu.modules:
|
||||
if mod.enabled:
|
||||
if mod.version == 1 or mod.version == 2:
|
||||
response = mod.process(msg)
|
||||
if mod.version in [1, 2]:
|
||||
response, formatting = mod.process(msg)
|
||||
|
||||
if response:
|
||||
print(f"Responded using module {mod.path} ({mod.alias}) with text: {response}")
|
||||
break
|
||||
if formatting == None:
|
||||
print(f"Responded using module {mod.path} ({mod.alias}) with text: {response}")
|
||||
break
|
||||
elif formatting in ["Markdown", "MarkdownV2", "HTML"]:
|
||||
print(f"Responded using module {mod.path} ({mod.alias}) with text (using {formatting}): {response}")
|
||||
break
|
||||
|
||||
del message_queue[0]
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user