mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
✨ 对于on_regex
触发器新增ev.regex_dict
和ev.regex_group
This commit is contained in:
parent
a3fbdd4096
commit
50326abdc9
@ -1,4 +1,4 @@
|
|||||||
from typing import Any, Dict, List, Literal, Optional
|
from typing import Any, Dict, List, Tuple, Literal, Optional
|
||||||
|
|
||||||
from msgspec import Struct
|
from msgspec import Struct
|
||||||
|
|
||||||
@ -34,6 +34,8 @@ class Event(MessageReceive):
|
|||||||
file_name: Optional[str] = None
|
file_name: Optional[str] = None
|
||||||
file: Optional[str] = None
|
file: Optional[str] = None
|
||||||
file_type: Optional[Literal['url', 'base64']] = None
|
file_type: Optional[Literal['url', 'base64']] = None
|
||||||
|
regex_group: Tuple[str, ...] = ()
|
||||||
|
regex_dict: Dict[str, str] = {}
|
||||||
|
|
||||||
|
|
||||||
class MessageSend(Struct):
|
class MessageSend(Struct):
|
||||||
|
@ -79,8 +79,10 @@ async def get_keyword_msg(bot: Bot, ev: Event):
|
|||||||
await bot.send('[关键词测试]校验成功!')
|
await bot.send('[关键词测试]校验成功!')
|
||||||
|
|
||||||
|
|
||||||
@sv_switch.on_regex(r'\d+')
|
@sv_switch.on_regex(r'这是一个(?P<name>正则|数字)测试!(?P<int>[\d]+)')
|
||||||
async def get_regex_msg(bot: Bot, ev: Event):
|
async def get_regex_msg(bot: Bot, ev: Event):
|
||||||
await bot.send('正在进行[正则测试]')
|
await bot.send('正在进行[正则测试]')
|
||||||
await asyncio.sleep(2)
|
await asyncio.sleep(2)
|
||||||
await bot.send('[正则测试]校验成功!')
|
await bot.send(
|
||||||
|
f'[正则测试]校验成功!{ev.regex_dict["name"]}你输入的是{ev.regex_dict["int"]}'
|
||||||
|
)
|
||||||
|
@ -202,8 +202,10 @@ async def _convert_message_to_image(
|
|||||||
and len(message.data) >= int(text2pic_limit)
|
and len(message.data) >= int(text2pic_limit)
|
||||||
):
|
):
|
||||||
image_bytes = await text2pic(message.data)
|
image_bytes = await text2pic(message.data)
|
||||||
elif message.type == 'image':
|
message = Message(type='image', data=image_bytes)
|
||||||
img: Union[bytes, str] = message.data
|
|
||||||
|
if message.type == 'image':
|
||||||
|
img: Union[bytes, str] = message.data # type: ignore
|
||||||
if isinstance(img, str) and img.startswith('base64://'):
|
if isinstance(img, str) and img.startswith('base64://'):
|
||||||
image_b64 = img
|
image_b64 = img
|
||||||
image_bytes = b64decode(img[9:])
|
image_bytes = b64decode(img[9:])
|
||||||
|
@ -80,8 +80,11 @@ class Trigger:
|
|||||||
msg.command = self.keyword
|
msg.command = self.keyword
|
||||||
msg.text = msg.raw_text.replace(self.keyword, '')
|
msg.text = msg.raw_text.replace(self.keyword, '')
|
||||||
else:
|
else:
|
||||||
command_list = re.findall(self.keyword, msg.raw_text)
|
command_group = re.search(self.keyword, msg.raw_text)
|
||||||
msg.command = '|'.join(command_list)
|
if command_group:
|
||||||
|
msg.regex_dict = command_group.groupdict()
|
||||||
|
msg.regex_group = command_group.groups()
|
||||||
|
msg.command = '|'.join(list(msg.regex_group))
|
||||||
text_list = re.split(self.keyword, msg.raw_text)
|
text_list = re.split(self.keyword, msg.raw_text)
|
||||||
msg.text = '|'.join(text_list)
|
msg.text = '|'.join(text_list)
|
||||||
return msg
|
return msg
|
||||||
|
@ -4,7 +4,7 @@ from .models import GSC, GsStrConfig
|
|||||||
|
|
||||||
SEND_PIC_CONIFG: Dict[str, GSC] = {
|
SEND_PIC_CONIFG: Dict[str, GSC] = {
|
||||||
'onebot': GsStrConfig('OneBot图片发送方式', '可选link或base64', 'base64'),
|
'onebot': GsStrConfig('OneBot图片发送方式', '可选link或base64', 'base64'),
|
||||||
'onebotv12': GsStrConfig('OneBot V12图片发送方式', '可选link或base64', 'base64'),
|
'onebot_v12': GsStrConfig('OneBot V12图片发送方式', '可选link或base64', 'base64'),
|
||||||
'qqguild': GsStrConfig('QQ Guild图片发送方式', '可选link或base64', 'base64'),
|
'qqguild': GsStrConfig('QQ Guild图片发送方式', '可选link或base64', 'base64'),
|
||||||
'qqgroup': GsStrConfig('QQ Group图片发送方式', '可选link或base64', 'link'),
|
'qqgroup': GsStrConfig('QQ Group图片发送方式', '可选link或base64', 'link'),
|
||||||
'telegram': GsStrConfig('Telegram图片发送方式', '可选link或base64', 'base64'),
|
'telegram': GsStrConfig('Telegram图片发送方式', '可选link或base64', 'base64'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user