mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-25 10:02:23 +00:00
keyword 更合理的频率限制
This commit is contained in:
parent
1395c71678
commit
b0af55dbeb
236
keyword.py
236
keyword.py
@ -216,11 +216,13 @@ async def send_reply(chat_id, trigger, mode, reply_msg, context):
|
|||||||
if not last_name:
|
if not last_name:
|
||||||
last_name = ""
|
last_name = ""
|
||||||
replace_data["chat_name"] = f"{chat.first_name} {last_name}"
|
replace_data["chat_name"] = f"{chat.first_name} {last_name}"
|
||||||
update_last_time = False
|
|
||||||
could_send_msg = valid_time(chat_id)
|
could_send_msg = valid_time(chat_id)
|
||||||
|
if not could_send_msg:
|
||||||
|
return
|
||||||
message_list = []
|
message_list = []
|
||||||
for re_type, re_msg in reply_msg:
|
for re_type, re_msg in reply_msg:
|
||||||
try:
|
try:
|
||||||
|
update_last_time = False
|
||||||
catch_pattern = r"\$\{func_(?P<str>((?!\}).)+)\}"
|
catch_pattern = r"\$\{func_(?P<str>((?!\}).)+)\}"
|
||||||
count = 0
|
count = 0
|
||||||
bracket_str = random_str()
|
bracket_str = random_str()
|
||||||
@ -256,21 +258,12 @@ async def send_reply(chat_id, trigger, mode, reply_msg, context):
|
|||||||
edit_id = int(s[5:])
|
edit_id = int(s[5:])
|
||||||
type_parse.remove(s)
|
type_parse.remove(s)
|
||||||
if ("file" in type_parse or "photo" in type_parse) and len(re_msg.split()) >= 2:
|
if ("file" in type_parse or "photo" in type_parse) and len(re_msg.split()) >= 2:
|
||||||
if could_send_msg:
|
update_last_time = True
|
||||||
update_last_time = True
|
re_data = re_msg.split(" ")
|
||||||
re_data = re_msg.split(" ")
|
cache_exists, filename = has_cache(chat_id, mode, trigger, re_data[0])
|
||||||
cache_exists, filename = has_cache(chat_id, mode, trigger, re_data[0])
|
is_opened = cache_opened(chat_id, mode, trigger)
|
||||||
is_opened = cache_opened(chat_id, mode, trigger)
|
if is_opened:
|
||||||
if is_opened:
|
if not cache_exists:
|
||||||
if not cache_exists:
|
|
||||||
if re_data[1][0:7] == "file://":
|
|
||||||
re_data[1] = re_data[1][7:]
|
|
||||||
copyfile(" ".join(re_data[1:]), filename)
|
|
||||||
else:
|
|
||||||
fileget = requests.get(" ".join(re_data[1:]))
|
|
||||||
with open(filename, "wb") as f:
|
|
||||||
f.write(fileget.content)
|
|
||||||
else:
|
|
||||||
if re_data[1][0:7] == "file://":
|
if re_data[1][0:7] == "file://":
|
||||||
re_data[1] = re_data[1][7:]
|
re_data[1] = re_data[1][7:]
|
||||||
copyfile(" ".join(re_data[1:]), filename)
|
copyfile(" ".join(re_data[1:]), filename)
|
||||||
@ -278,54 +271,52 @@ async def send_reply(chat_id, trigger, mode, reply_msg, context):
|
|||||||
fileget = requests.get(" ".join(re_data[1:]))
|
fileget = requests.get(" ".join(re_data[1:]))
|
||||||
with open(filename, "wb") as f:
|
with open(filename, "wb") as f:
|
||||||
f.write(fileget.content)
|
f.write(fileget.content)
|
||||||
reply_to = None
|
else:
|
||||||
if "reply" in type_parse:
|
if re_data[1][0:7] == "file://":
|
||||||
reply_to = context.id
|
re_data[1] = re_data[1][7:]
|
||||||
redir = getsetting(chat_id, mode, trigger, "redir", "0")
|
copyfile(" ".join(re_data[1:]), filename)
|
||||||
reply = await context.get_reply_message()
|
|
||||||
if redir == "1" and reply:
|
|
||||||
reply_to = reply.id
|
|
||||||
if edit_id == -1:
|
|
||||||
message_list.append(await bot.send_file(
|
|
||||||
chat_id,
|
|
||||||
filename,
|
|
||||||
reply_to=reply_to,
|
|
||||||
force_document=("file" in type_parse)
|
|
||||||
))
|
|
||||||
else:
|
else:
|
||||||
edit_file = await bot.upload_file(filename)
|
fileget = requests.get(" ".join(re_data[1:]))
|
||||||
message_list[edit_id] = await message_list[edit_id].edit(
|
with open(filename, "wb") as f:
|
||||||
file=edit_file,
|
f.write(fileget.content)
|
||||||
force_document=("file" in type_parse)
|
reply_to = None
|
||||||
)
|
if "reply" in type_parse:
|
||||||
if not is_opened:
|
reply_to = context.id
|
||||||
remove(filename)
|
redir = getsetting(chat_id, mode, trigger, "redir", "0")
|
||||||
|
reply = await context.get_reply_message()
|
||||||
|
if redir == "1" and reply:
|
||||||
|
reply_to = reply.id
|
||||||
|
if edit_id == -1:
|
||||||
|
message_list.append(await bot.send_file(
|
||||||
|
chat_id,
|
||||||
|
filename,
|
||||||
|
reply_to=reply_to,
|
||||||
|
force_document=("file" in type_parse)
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
edit_file = await bot.upload_file(filename)
|
||||||
|
message_list[edit_id] = await message_list[edit_id].edit(
|
||||||
|
file=edit_file,
|
||||||
|
force_document=("file" in type_parse)
|
||||||
|
)
|
||||||
|
if not is_opened:
|
||||||
|
remove(filename)
|
||||||
elif ("tgfile" in type_parse or "tgphoto" in type_parse) and len(re_msg.split()) >= 2:
|
elif ("tgfile" in type_parse or "tgphoto" in type_parse) and len(re_msg.split()) >= 2:
|
||||||
if could_send_msg:
|
update_last_time = True
|
||||||
update_last_time = True
|
re_data = re_msg.split(" ")
|
||||||
re_data = re_msg.split(" ")
|
re_data[0] = " ".join(re_data[0:-1])
|
||||||
re_data[0] = " ".join(re_data[0:-1])
|
re_data[1] = re_data[-1:][0].split("/")[-2:]
|
||||||
re_data[1] = re_data[-1:][0].split("/")[-2:]
|
cache_exists, filename = has_cache(chat_id, mode, trigger, re_data[0])
|
||||||
cache_exists, filename = has_cache(chat_id, mode, trigger, re_data[0])
|
is_opened = cache_opened(chat_id, mode, trigger)
|
||||||
is_opened = cache_opened(chat_id, mode, trigger)
|
_data = BytesIO()
|
||||||
_data = BytesIO()
|
try:
|
||||||
try:
|
msg_chat_id = int(re_data[1][0])
|
||||||
msg_chat_id = int(re_data[1][0])
|
except:
|
||||||
except:
|
async with bot.conversation(re_data[1][0]) as conversation:
|
||||||
async with bot.conversation(re_data[1][0]) as conversation:
|
msg_chat_id = conversation.chat_id
|
||||||
msg_chat_id = conversation.chat_id
|
msg_id_inchat = int(re_data[1][1])
|
||||||
msg_id_inchat = int(re_data[1][1])
|
if is_opened:
|
||||||
if is_opened:
|
if not cache_exists:
|
||||||
if not cache_exists:
|
|
||||||
media_msg = await bot.get_messages(msg_chat_id, ids=msg_id_inchat, offset_id=0)
|
|
||||||
if media_msg and media_msg.media:
|
|
||||||
try:
|
|
||||||
await bot.download_file(media_msg.media.document, _data)
|
|
||||||
except:
|
|
||||||
await bot.download_file(media_msg.photo, _data)
|
|
||||||
with open(filename, "wb") as f:
|
|
||||||
f.write(_data.getvalue())
|
|
||||||
else:
|
|
||||||
media_msg = await bot.get_messages(msg_chat_id, ids=msg_id_inchat, offset_id=0)
|
media_msg = await bot.get_messages(msg_chat_id, ids=msg_id_inchat, offset_id=0)
|
||||||
if media_msg and media_msg.media:
|
if media_msg and media_msg.media:
|
||||||
try:
|
try:
|
||||||
@ -334,62 +325,69 @@ async def send_reply(chat_id, trigger, mode, reply_msg, context):
|
|||||||
await bot.download_file(media_msg.photo, _data)
|
await bot.download_file(media_msg.photo, _data)
|
||||||
with open(filename, "wb") as f:
|
with open(filename, "wb") as f:
|
||||||
f.write(_data.getvalue())
|
f.write(_data.getvalue())
|
||||||
reply_to = None
|
else:
|
||||||
if "reply" in type_parse:
|
media_msg = await bot.get_messages(msg_chat_id, ids=msg_id_inchat, offset_id=0)
|
||||||
reply_to = context.id
|
if media_msg and media_msg.media:
|
||||||
redir = getsetting(chat_id, mode, trigger, "redir", "0")
|
try:
|
||||||
reply = await context.get_reply_message()
|
await bot.download_file(media_msg.media.document, _data)
|
||||||
if redir == "1" and reply:
|
except:
|
||||||
reply_to = reply.id
|
await bot.download_file(media_msg.photo, _data)
|
||||||
if edit_id == -1:
|
with open(filename, "wb") as f:
|
||||||
message_list.append(await bot.send_file(
|
f.write(_data.getvalue())
|
||||||
chat_id,
|
reply_to = None
|
||||||
filename,
|
if "reply" in type_parse:
|
||||||
reply_to=reply_to,
|
reply_to = context.id
|
||||||
force_document=("tgfile" in type_parse)
|
redir = getsetting(chat_id, mode, trigger, "redir", "0")
|
||||||
))
|
reply = await context.get_reply_message()
|
||||||
else:
|
if redir == "1" and reply:
|
||||||
edit_file = await bot.upload_file(filename)
|
reply_to = reply.id
|
||||||
message_list[edit_id] = await message_list[edit_id].edit(
|
if edit_id == -1:
|
||||||
file=edit_file,
|
message_list.append(await bot.send_file(
|
||||||
force_document=("tgfile" in type_parse)
|
chat_id,
|
||||||
)
|
filename,
|
||||||
if not is_opened:
|
reply_to=reply_to,
|
||||||
remove(filename)
|
force_document=("tgfile" in type_parse)
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
edit_file = await bot.upload_file(filename)
|
||||||
|
message_list[edit_id] = await message_list[edit_id].edit(
|
||||||
|
file=edit_file,
|
||||||
|
force_document=("tgfile" in type_parse)
|
||||||
|
)
|
||||||
|
if not is_opened:
|
||||||
|
remove(filename)
|
||||||
elif "plain" in type_parse:
|
elif "plain" in type_parse:
|
||||||
if could_send_msg:
|
update_last_time = True
|
||||||
update_last_time = True
|
if edit_id == -1:
|
||||||
if edit_id == -1:
|
message_list.append(await bot.send_message(
|
||||||
message_list.append(await bot.send_message(
|
chat_id,
|
||||||
chat_id,
|
re_msg,
|
||||||
re_msg,
|
link_preview=("nopreview" not in type_parse)
|
||||||
link_preview=("nopreview" not in type_parse)
|
))
|
||||||
))
|
else:
|
||||||
else:
|
message_list[edit_id] = await message_list[edit_id].edit(
|
||||||
message_list[edit_id] = await message_list[edit_id].edit(
|
re_msg,
|
||||||
re_msg,
|
link_preview=("nopreview" not in type_parse)
|
||||||
link_preview=("nopreview" not in type_parse)
|
)
|
||||||
)
|
|
||||||
elif "reply" in type_parse and chat_id == real_chat_id:
|
elif "reply" in type_parse and chat_id == real_chat_id:
|
||||||
if could_send_msg:
|
update_last_time = True
|
||||||
update_last_time = True
|
if edit_id == -1:
|
||||||
if edit_id == -1:
|
reply_to = context.id
|
||||||
reply_to = context.id
|
redir = getsetting(chat_id, mode, trigger, "redir", "0")
|
||||||
redir = getsetting(chat_id, mode, trigger, "redir", "0")
|
reply = await context.get_reply_message()
|
||||||
reply = await context.get_reply_message()
|
if redir == "1" and reply:
|
||||||
if redir == "1" and reply:
|
reply_to = reply.id
|
||||||
reply_to = reply.id
|
message_list.append(await bot.send_message(
|
||||||
message_list.append(await bot.send_message(
|
chat_id,
|
||||||
chat_id,
|
re_msg,
|
||||||
re_msg,
|
reply_to=reply_to,
|
||||||
reply_to=reply_to,
|
link_preview=("nopreview" not in type_parse)
|
||||||
link_preview=("nopreview" not in type_parse)
|
))
|
||||||
))
|
else:
|
||||||
else:
|
message_list[edit_id] = await message_list[edit_id].edit(
|
||||||
message_list[edit_id] = await message_list[edit_id].edit(
|
re_msg,
|
||||||
re_msg,
|
link_preview=("nopreview" not in type_parse)
|
||||||
link_preview=("nopreview" not in type_parse)
|
)
|
||||||
)
|
|
||||||
elif "op" in type_parse:
|
elif "op" in type_parse:
|
||||||
if re_msg == "delete":
|
if re_msg == "delete":
|
||||||
await context.delete()
|
await context.delete()
|
||||||
@ -407,12 +405,12 @@ async def send_reply(chat_id, trigger, mode, reply_msg, context):
|
|||||||
]
|
]
|
||||||
await eval(f"aexec(args[0]{f', {args[1]}' if args[1] else ''})")
|
await eval(f"aexec(args[0]{f', {args[1]}' if args[1] else ''})")
|
||||||
chdir(working_dir)
|
chdir(working_dir)
|
||||||
|
if update_last_time:
|
||||||
|
global group_last_time
|
||||||
|
group_last_time[int(chat_id)] = time.time()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
chat_id = real_chat_id
|
chat_id = real_chat_id
|
||||||
if update_last_time:
|
|
||||||
global group_last_time
|
|
||||||
group_last_time[int(chat_id)] = time.time()
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user