Added ftfy and length limit
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
from asyncio import sleep
|
||||
from ftfy import fix_text
|
||||
from traceback import format_exc
|
||||
from app import app, isAnAdmin
|
||||
from typing import Any, List, Literal, Union
|
||||
@@ -122,6 +123,11 @@ class HoloUser():
|
||||
* adm_context (`bool`, *optional*): Whether context sender is an admin. Defaults to False.
|
||||
"""
|
||||
|
||||
if text is not None:
|
||||
text = fix_text(text)
|
||||
elif caption is not None:
|
||||
caption = fix_text(caption)
|
||||
|
||||
# Check if any text available and log message sending
|
||||
if text is not None:
|
||||
logWrite(f"{context.from_user.id} sent message '{text}' to {self.id} (source message: {context.id})")
|
||||
@@ -313,6 +319,9 @@ class HoloUser():
|
||||
|
||||
if progress["state"] == "fill" and progress["sent"] is False:
|
||||
|
||||
if msg.text is not None:
|
||||
msg.text = fix_text(msg.text)
|
||||
|
||||
if stage == 2:
|
||||
|
||||
try:
|
||||
@@ -359,6 +368,9 @@ class HoloUser():
|
||||
return
|
||||
|
||||
elif stage == 10:
|
||||
if len(query) > 1024:
|
||||
await msg.reply_text(locale("question10_too_long", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage}", "force_reply", locale=self.locale))))
|
||||
return
|
||||
progress["application"][str(stage)] = query
|
||||
col_tmp.update_one({"user": {"$eq": self.id}, "type": {"$eq": "application"}}, {"$set": {"application": progress["application"], "complete": True}})
|
||||
application_content = []
|
||||
@@ -378,6 +390,9 @@ class HoloUser():
|
||||
await msg.reply_text(locale("confirm", "message", locale=self.locale).format("\n".join(application_content)), reply_markup=ReplyKeyboardMarkup(locale("confirm", "keyboard", locale=self.locale), resize_keyboard=True))
|
||||
|
||||
else:
|
||||
if len(query) > 256:
|
||||
await msg.reply_text(locale("question_too_long", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage}", "force_reply", locale=self.locale))))
|
||||
return
|
||||
progress["application"][str(stage)] = query
|
||||
col_tmp.update_one({"user": {"$eq": self.id}, "type": {"$eq": "application"}}, {"$set": {"application": progress["application"], "stage": progress["stage"]+1}})
|
||||
await msg.reply_text(locale(f"question{stage+1}", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage+1}", "force_reply", locale=self.locale))))
|
||||
@@ -430,10 +445,20 @@ class HoloUser():
|
||||
|
||||
stage = progress["stage"]
|
||||
|
||||
if msg.text is not None:
|
||||
msg.text = fix_text(msg.text)
|
||||
elif msg.caption is not None:
|
||||
msg.caption = fix_text(msg.caption)
|
||||
|
||||
if progress["state"] == "fill" and progress["sent"] is False:
|
||||
|
||||
if stage == 1:
|
||||
|
||||
if len(query) > 240:
|
||||
logWrite(f"User {msg.from_user.id} failed stage {stage} due to sending invalid date format")
|
||||
await msg.reply_text(locale(f"sponsor1_invalid", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"sponsor{stage}", "force_reply", locale=self.locale))))
|
||||
return
|
||||
|
||||
progress["sponsorship"]["streamer"] = query
|
||||
col_tmp.update_one({"user": {"$eq": self.id}, "type": {"$eq": "sponsorship"}}, {"$set": {"sponsorship": progress["sponsorship"], "stage": progress["stage"]+1}})
|
||||
await msg.reply_text(locale(f"sponsor{stage+1}", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"sponsor{stage+1}", "force_reply", locale=self.locale))))
|
||||
|
Reference in New Issue
Block a user