Skip to content

Commit

Permalink
请不要输入奇怪的东西
Browse files Browse the repository at this point in the history
  • Loading branch information
krau committed Dec 14, 2023
1 parent 3b405e3 commit eeb87c2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion kmua/callbacks/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import kmua.common as common
import kmua.dao as dao
from kmua.logger import logger
import re

from .jobs import delete_message

Expand Down Expand Up @@ -148,8 +149,18 @@ async def set_quote_probability(update: Update, context: ContextTypes.DEFAULT_TY
logger.info(f"Bot: {sent_message.text}")
return
except_text = "概率是在[0,1]之间的浮点数,请检查输入"
if not context.args:
sent_message = await message.reply_text(except_text)
logger.info(f"Bot: {sent_message.text}")
return
float_pattern = re.compile(r"^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$")
value = context.args[0]
if not float_pattern.match(value) or len(value) > 8:
sent_message = await message.reply_text("请不要输入奇怪的东西> <")
logger.info(f"Bot: {sent_message.text}")
return
try:
probability = float(context.args[0])
probability = float(value)
except Exception:
sent_message = await message.reply_text(except_text)
logger.info(f"Bot: {sent_message.text}")
Expand Down

0 comments on commit eeb87c2

Please sign in to comment.