Mercurial > libervia-backend
changeset 4022:cdb7de398c85
plugin lang detect: don't detect the language if the body is empty
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 23 Mar 2023 15:39:48 +0100 |
parents | 412b99c29d83 |
children | 78b5f356900c |
files | sat/plugins/plugin_exp_lang_detect.py |
diffstat | 1 files changed, 7 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/plugins/plugin_exp_lang_detect.py Thu Mar 23 15:38:07 2023 +0100 +++ b/sat/plugins/plugin_exp_lang_detect.py Thu Mar 23 15:39:48 2023 +0100 @@ -69,12 +69,13 @@ host.trigger.add("messageReceived", self.messageReceivedTrigger) host.trigger.add("sendMessage", self.MessageSendTrigger) - def addLanguage(self, mess_data): + def add_language(self, mess_data): message = mess_data["message"] if len(message) == 1 and list(message.keys())[0] == "": - msg = list(message.values())[0] - lang = identifier.classify(msg)[0] - mess_data["message"] = {lang: msg} + msg = list(message.values())[0].strip() + if msg: + lang = identifier.classify(msg)[0] + mess_data["message"] = {lang: msg} return mess_data def messageReceivedTrigger(self, client, message_elt, post_treat): @@ -84,7 +85,7 @@ NAME, CATEGORY, profile_key=client.profile ) if lang_detect: - post_treat.addCallback(self.addLanguage) + post_treat.addCallback(self.add_language) return True def MessageSendTrigger(self, client, data, pre_xml_treatments, post_xml_treatments): @@ -92,5 +93,5 @@ NAME, CATEGORY, profile_key=client.profile ) if lang_detect: - self.addLanguage(data) + self.add_language(data) return True