From 0abca6fb9542b0c1c3f7dd07986c2d80c6038116 Mon Sep 17 00:00:00 2001 From: Context 77 <126421199+ctx77@users.noreply.github.com> Date: Sat, 14 Dec 2024 13:43:03 +0100 Subject: [PATCH] require .icd to resolve ICD10 codes and limit answer to at most 5 --- .../Modules/CustomUserModules/ICDObserver.py | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/FaustBot/Modules/CustomUserModules/ICDObserver.py b/FaustBot/Modules/CustomUserModules/ICDObserver.py index d69aaa9..d4715a9 100644 --- a/FaustBot/Modules/CustomUserModules/ICDObserver.py +++ b/FaustBot/Modules/CustomUserModules/ICDObserver.py @@ -21,17 +21,18 @@ class ICDObserver(PrivMsgObserverPrototype): return None def update_on_priv_msg(self, data, connection: Connection): - if data["channel"] == connection.details.get_channel(): - regex = r"\b(\w\d{2}\.?\d?\d?)\b" - codes = re.findall(regex, data["message"]) - for code in codes: - code = code.capitalize() - text = self.icd10_dict.get(code, False) - if text == False: - if "." in code: - code += "-" - else: - code += ".-" - text = self.icd10_dict.get(code, False) - if text: - connection.send_back(f"{code} - {text}", data) + if data["message"].startswith(".icd "): + if data["channel"] == connection.details.get_channel(): + regex = r"\b(\w\d{2}\.?\d?\d?)\b" + codes = re.findall(regex, data["message"]) + for code in codes[:5]: + code = code.capitalize() + text = self.icd10_dict.get(code, False) + if text == False: + if "." in code: + code += "-" + else: + code += ".-" + text = self.icd10_dict.get(code, False) + if text: + connection.send_back(f"{code} - {text}", data)