|  | @@ -9,15 +9,13 @@ from telethon.tl.functions.stickers import (
 | 
	
		
			
				|  |  |      CreateStickerSetRequest,
 | 
	
		
			
				|  |  |      AddStickerToSetRequest,
 | 
	
		
			
				|  |  |  )
 | 
	
		
			
				|  |  | -from telethon.tl.functions.messages import UploadMediaRequest, GetStickerSetRequest
 | 
	
		
			
				|  |  | +from telethon.tl.functions.messages import UploadMediaRequest
 | 
	
		
			
				|  |  |  from telethon.tl.types import (
 | 
	
		
			
				|  |  |      InputStickerSetID,
 | 
	
		
			
				|  |  | -    InputStickerSetShortName,
 | 
	
		
			
				|  |  |      InputStickerSetItem,
 | 
	
		
			
				|  |  |      InputMediaUploadedDocument,
 | 
	
		
			
				|  |  |      InputPeerSelf,
 | 
	
		
			
				|  |  |  )
 | 
	
		
			
				|  |  | -from telethon.errors import MessageEmptyError
 | 
	
		
			
				|  |  |  from tortoise.expressions import F
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  from models import (
 | 
	
	
		
			
				|  | @@ -278,6 +276,7 @@ async def disable_markov(peer_id):
 | 
	
		
			
				|  |  |  async def list_markov_chats():
 | 
	
		
			
				|  |  |      return await MarkovChat.all()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  async def markov_say(bot, peer_id, reply_to=None, init_state=None):
 | 
	
		
			
				|  |  |      if not bot.markov.is_ready:
 | 
	
		
			
				|  |  |          return
 | 
	
	
		
			
				|  | @@ -293,18 +292,23 @@ async def markov_say(bot, peer_id, reply_to=None, init_state=None):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      await bot.send_message(peer_id, message=text, reply_to=reply_to)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  async def run(text):
 | 
	
		
			
				|  |  |      match = re.match(r"^(\w+)(?:\s|\n)((?:\n|.)*)$", text)
 | 
	
		
			
				|  |  |      if not match:
 | 
	
		
			
				|  |  | -        return "Пожалуйста, не оставляйте ввод пустым!"
 | 
	
		
			
				|  |  | +        return None, None, "Пожалуйста, не оставляйте ввод пустым!"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      language_name, text = match.groups()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    text = re.sub(r"^```\w+\n((.|\n)*)```$", r"\1", text)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      if text.startswith("```") and text.endswith("```"):
 | 
	
		
			
				|  |  |          text = text[3:-3]
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      text = text.replace("\xa0", " ")  # i hate telegram
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    input_text = text
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      async with ClientSession() as session:
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  |              async with session.post(
 | 
	
	
		
			
				|  | @@ -313,14 +317,26 @@ async def run(text):
 | 
	
		
			
				|  |  |                  if resp.status in (404, 500):
 | 
	
		
			
				|  |  |                      info = await resp.json()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    return f"Произошла ошибка при попытке обращения к API… :(\nОтвет API: {info['detail']}"
 | 
	
		
			
				|  |  | +                    return (
 | 
	
		
			
				|  |  | +                        language_name,
 | 
	
		
			
				|  |  | +                        input_text,
 | 
	
		
			
				|  |  | +                        f"Произошла ошибка при попытке обращения к API… :(\nОтвет API: {info['detail']}",
 | 
	
		
			
				|  |  | +                    )
 | 
	
		
			
				|  |  |                  elif resp.status != 200:
 | 
	
		
			
				|  |  | -                    return "Сервер API временно недоступен. Пожалуйста, попробуйте ещё раз чуть позже."
 | 
	
		
			
				|  |  | +                    return (
 | 
	
		
			
				|  |  | +                        language_name,
 | 
	
		
			
				|  |  | +                        input_text,
 | 
	
		
			
				|  |  | +                        "Сервер API временно недоступен. Пожалуйста, попробуйте ещё раз чуть позже.",
 | 
	
		
			
				|  |  | +                    )
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  text = await resp.read()
 | 
	
		
			
				|  |  |                  text = text.decode("UTF-8")[:4096]
 | 
	
		
			
				|  |  | -        except:
 | 
	
		
			
				|  |  | -            return "Произошла ошибка при попытке обращения к API… :("
 | 
	
		
			
				|  |  | +        except Exception:
 | 
	
		
			
				|  |  | +            return (
 | 
	
		
			
				|  |  | +                language_name,
 | 
	
		
			
				|  |  | +                input_text,
 | 
	
		
			
				|  |  | +                "Произошла ошибка при попытке обращения к API… :(",
 | 
	
		
			
				|  |  | +            )
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      text = remove_ansi_escapes(text).strip()
 | 
	
		
			
				|  |  |      text = filter(
 | 
	
	
		
			
				|  | @@ -330,9 +346,6 @@ async def run(text):
 | 
	
		
			
				|  |  |      text = text.replace("`", "")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      if not text:
 | 
	
		
			
				|  |  | -        return "<пусто>"
 | 
	
		
			
				|  |  | +        return language_name, input_text, "<пусто>"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    try:
 | 
	
		
			
				|  |  | -        return f"```\n{text}```"
 | 
	
		
			
				|  |  | -    except (ValueError, MessageEmptyError):
 | 
	
		
			
				|  |  | -        return "<Telegram не смог декодировать текст сообщения>"
 | 
	
		
			
				|  |  | +    return language_name, input_text, f"```\n{text}```"
 |