mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-25 18:35:26 +00:00
parent
7f6124e11b
commit
40d06a0c16
15
keyword.py
15
keyword.py
@ -5,8 +5,7 @@ from base64 import b64encode, b64decode
|
|||||||
from pagermaid import bot, redis, log, redis_status
|
from pagermaid import bot, redis, log, redis_status
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
|
|
||||||
msg_rate = 0.01
|
read_context = {}
|
||||||
last_time = time.time()
|
|
||||||
|
|
||||||
def is_num(x: str):
|
def is_num(x: str):
|
||||||
try:
|
try:
|
||||||
@ -395,23 +394,25 @@ async def auto_reply(context):
|
|||||||
elif g_list or n_list: user_list = g_list if g_list else n_list
|
elif g_list or n_list: user_list = g_list if g_list else n_list
|
||||||
send_text = context.text
|
send_text = context.text
|
||||||
for k, v in plain_dict.items():
|
for k, v in plain_dict.items():
|
||||||
if k in send_text and time.time() - last_time > msg_rate:
|
if k in send_text and context.id not in read_context:
|
||||||
tmp = get_redis(f"keyword.{chat_id}.single.plain.{encode(k)}")
|
tmp = get_redis(f"keyword.{chat_id}.single.plain.{encode(k)}")
|
||||||
could_reply = validate(str(sender_id), int(mode), user_list)
|
could_reply = validate(str(sender_id), int(mode), user_list)
|
||||||
if tmp:
|
if tmp:
|
||||||
could_reply = validate(str(sender_id), int(tmp.get("mode", "0")), tmp.get("list", []))
|
could_reply = validate(str(sender_id), int(tmp.get("mode", "0")), tmp.get("list", []))
|
||||||
if could_reply:
|
if could_reply:
|
||||||
last_time = time.time()
|
read_context[context.id] = None
|
||||||
await send_reply(chat_id, parse_multi(v), context)
|
await send_reply(chat_id, parse_multi(v), context)
|
||||||
|
elif context.id in read_context:
|
||||||
|
del read_context[context.id]
|
||||||
for k, v in regex_dict.items():
|
for k, v in regex_dict.items():
|
||||||
pattern = re.compile(k)
|
pattern = re.compile(k)
|
||||||
if pattern.search(send_text) and time.time() - last_time > msg_rate:
|
if pattern.search(send_text) and context.id not in read_context:
|
||||||
tmp = get_redis(f"keyword.{chat_id}.single.regex.{encode(k)}")
|
tmp = get_redis(f"keyword.{chat_id}.single.regex.{encode(k)}")
|
||||||
could_reply = validate(str(sender_id), int(mode), user_list)
|
could_reply = validate(str(sender_id), int(mode), user_list)
|
||||||
if tmp:
|
if tmp:
|
||||||
could_reply = validate(str(sender_id), int(tmp.get("mode", "0")), tmp.get("list", []))
|
could_reply = validate(str(sender_id), int(tmp.get("mode", "0")), tmp.get("list", []))
|
||||||
if could_reply:
|
if could_reply:
|
||||||
last_time = time.time()
|
read_context[context.id] = None
|
||||||
catch_pattern = r"\$\{regex_(?P<str>((?!\}).)+)\}"
|
catch_pattern = r"\$\{regex_(?P<str>((?!\}).)+)\}"
|
||||||
count = 0
|
count = 0
|
||||||
while re.search(catch_pattern, v) and count < 20:
|
while re.search(catch_pattern, v) and count < 20:
|
||||||
@ -423,3 +424,5 @@ async def auto_reply(context):
|
|||||||
v = v.replace("${regex_%s}" % group_name, capture_data)
|
v = v.replace("${regex_%s}" % group_name, capture_data)
|
||||||
count += 1
|
count += 1
|
||||||
await send_reply(chat_id, parse_multi(v), context)
|
await send_reply(chat_id, parse_multi(v), context)
|
||||||
|
elif context.id in read_context:
|
||||||
|
del read_context[context.id]
|
||||||
|
@ -362,10 +362,10 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "keyword",
|
"name": "keyword",
|
||||||
"version": "2.01",
|
"version": "2.02",
|
||||||
"section": "chat",
|
"section": "chat",
|
||||||
"maintainer": "c3b2a",
|
"maintainer": "c3b2a",
|
||||||
"size": "17.3 kb",
|
"size": "17.4 kb",
|
||||||
"supported": true,
|
"supported": true,
|
||||||
"des-short": "群组关键词自动回复插件",
|
"des-short": "群组关键词自动回复插件",
|
||||||
"des": "命令: keyword, replyset。"
|
"des": "命令: keyword, replyset。"
|
||||||
|
Loading…
Reference in New Issue
Block a user