forked from dymik739/modular-bot-framework-for-telegram
		
	transliteration-decoder: add automatic photo caption detection and let bot core deal with exceptions
This commit is contained in:
		
							parent
							
								
									604054af9e
								
							
						
					
					
						commit
						09def1cd63
					
				@ -4,37 +4,36 @@ command_length = len(command)
 | 
			
		||||
def escaped_string(unescaped_string):
 | 
			
		||||
    result_string = str(unescaped_string)
 | 
			
		||||
 | 
			
		||||
    for i in ["/", "<", ">"]:
 | 
			
		||||
    for i in ["<", ">"]:
 | 
			
		||||
        result_string = result_string.replace(i, f"\\{i}")
 | 
			
		||||
 | 
			
		||||
    return result_string
 | 
			
		||||
 | 
			
		||||
if (command[0] in self.aliases) and (1 <= command_length <= 3):
 | 
			
		||||
    try:
 | 
			
		||||
        models = json.loads(readfile(self.path + "translate_models.json"))
 | 
			
		||||
    models = json.loads(readfile(self.path + "translate_models.json"))
 | 
			
		||||
 | 
			
		||||
        if command_length == 1:
 | 
			
		||||
            chosen_model = "cz-ua"
 | 
			
		||||
        else:
 | 
			
		||||
            chosen_model = command[1]
 | 
			
		||||
    if command_length == 1:
 | 
			
		||||
        chosen_model = "cz-ua"
 | 
			
		||||
    else:
 | 
			
		||||
        chosen_model = command[1]
 | 
			
		||||
 | 
			
		||||
        if command_length == 3:
 | 
			
		||||
            text_to_decode = command[2]
 | 
			
		||||
        else:
 | 
			
		||||
            text_to_decode = self.MESSAGE['reply_to_message']['text']
 | 
			
		||||
    
 | 
			
		||||
        decoded_text = text_to_decode
 | 
			
		||||
        if chosen_model not in models:
 | 
			
		||||
            self.RESPONSE = f"Такого варіанту транслітерації не існує. Доступні варіанти: " \
 | 
			
		||||
                            f"{', '.join(list(models.keys()))}"
 | 
			
		||||
        else:
 | 
			
		||||
            for i in models[chosen_model]:
 | 
			
		||||
                decoded_text = decoded_text.replace(i[0], i[1])
 | 
			
		||||
                decoded_text = decoded_text.replace(i[0].capitalize(), i[1].capitalize())
 | 
			
		||||
                decoded_text = decoded_text.replace(i[0].upper(), i[1].upper())
 | 
			
		||||
    
 | 
			
		||||
            self.RESPONSE = f"<b><u>Результат</u></b>\n{escaped_string(decoded_text)}"
 | 
			
		||||
            self.FORMAT = "HTML"
 | 
			
		||||
    if command_length == 3:
 | 
			
		||||
        text_to_decode = command[2]
 | 
			
		||||
    else:
 | 
			
		||||
        if self.MESSAGE['reply_to_message'].caption:
 | 
			
		||||
            text_to_decode = self.MESSAGE['reply_to_message'].caption
 | 
			
		||||
        elif self.MESSAGE['reply_to_message'].text:
 | 
			
		||||
            text_to_decode = self.MESSAGE['reply_to_message'].text
 | 
			
		||||
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
        print(f"[translit-decoder] Got exception: {e}")
 | 
			
		||||
    decoded_text = text_to_decode
 | 
			
		||||
    if chosen_model not in models:
 | 
			
		||||
        self.RESPONSE = f"Такого варіанту транслітерації не існує. Доступні варіанти: " \
 | 
			
		||||
                        f"{', '.join(list(models.keys()))}"
 | 
			
		||||
    else:
 | 
			
		||||
        for i in models[chosen_model]:
 | 
			
		||||
            decoded_text = decoded_text.replace(i[0], i[1])
 | 
			
		||||
            decoded_text = decoded_text.replace(i[0].capitalize(), i[1].capitalize())
 | 
			
		||||
            decoded_text = decoded_text.replace(i[0].upper(), i[1].upper())
 | 
			
		||||
 | 
			
		||||
        self.RESPONSE = f"<b><u>Результат</u></b>\n{escaped_string(decoded_text)}"
 | 
			
		||||
        self.FORMAT = "HTML"
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user