iShotaBot/defs/ask.py

74 lines
2.4 KiB
Python
Raw Normal View History

2021-11-28 14:55:10 +00:00
import re
import secrets
from typing import List
2021-12-08 09:10:31 +00:00
from init import bot
2021-11-28 14:55:10 +00:00
async def how_many(message: str) -> str:
while re.findall("几|多少", message):
2022-07-25 09:35:54 +00:00
message = message.replace("", str(secrets.choice(range(99))), 1)
message = message.replace("多少", str(secrets.choice(range(99))), 1)
2021-11-28 14:55:10 +00:00
return message
async def what_time(message: str) -> str:
time = ["早上", "中午", "晚上", "今天", "明天", "下周", "下个月", "明年"]
while re.findall("什么时候|啥时候", message):
message = message.replace("什么时候", secrets.choice(time), 1)
message = message.replace("啥时候", secrets.choice(time), 1)
return message
async def how_long(message: str) -> str:
unit = ["", "小时", "", "", "", "", "世纪"]
while re.findall("多久|多长时间", message):
2023-01-12 13:19:54 +00:00
message = message.replace(
"多久", str(secrets.choice(range(99))) + secrets.choice(unit), 1
)
message = message.replace(
"多长时间", str(secrets.choice(range(99))) + secrets.choice(unit), 1
)
2021-11-28 14:55:10 +00:00
return message
async def hif(message: str) -> str:
keyword = list(set(re.findall(r"(.)不\1", message)))
for k in keyword:
k = f"{k}{k}"
if secrets.choice([True, False]):
message = message.replace(k, k[:1])
else:
message = message.replace(k, k[1:])
return message
async def who(message: str, group_id: int) -> str:
group_member_list = await bot.get_chat_member(group_id)
2022-07-25 09:35:54 +00:00
member_list: List[str] = [n.first_name for n in group_member_list]
2021-11-28 14:55:10 +00:00
while "" in message:
2022-07-25 09:35:54 +00:00
member_name = member_list[secrets.choice(range(len(member_list) - 1))]
2021-11-28 14:55:10 +00:00
message = message.replace("", member_name, 1)
return message
async def handle_pers(message: str) -> str:
message_list = list(message)
2022-07-25 09:35:54 +00:00
for i in range(len(message_list)):
2021-11-28 14:55:10 +00:00
if message_list[i] == "":
message_list[i] = ""
continue
if message[i] == "":
message_list[i] = ""
continue
message = "".join(message_list)
message = message.replace("bot", "")
message = message.replace("Bot", "")
message = message.replace("", "")
message = message.replace("", "")
message = message.replace("", "")
message = message.replace("?", "")
return message