mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
✨ 新增on_file
触发器
This commit is contained in:
parent
c0802a9b48
commit
087f81db83
@ -47,6 +47,10 @@ async def msg_process(msg: MessageReceive) -> Event:
|
||||
event.image_list.append(_msg.data)
|
||||
elif _msg.type == 'reply':
|
||||
event.reply = _msg.data
|
||||
elif _msg.type == 'file' and _msg.data:
|
||||
data = _msg.data.split('|')
|
||||
event.file_name = data[0]
|
||||
event.file = data[1]
|
||||
_content.append(_msg)
|
||||
event.content = _content
|
||||
return event
|
||||
|
@ -29,6 +29,8 @@ class Event(MessageReceive):
|
||||
at_list: List[Any] = []
|
||||
is_tome: bool = False
|
||||
reply: Optional[str] = None
|
||||
file_name: Optional[str] = None
|
||||
file: Optional[str] = None
|
||||
|
||||
|
||||
class MessageSend(Struct):
|
||||
|
@ -101,7 +101,9 @@ class SV:
|
||||
|
||||
def _on(
|
||||
self,
|
||||
type: Literal['prefix', 'suffix', 'keyword', 'fullmatch', 'command'],
|
||||
type: Literal[
|
||||
'prefix', 'suffix', 'keyword', 'fullmatch', 'command', 'file'
|
||||
],
|
||||
keyword: Union[str, Tuple[str, ...]],
|
||||
block: bool = False,
|
||||
to_me: bool = False,
|
||||
@ -162,3 +164,11 @@ class SV:
|
||||
to_me: bool = False,
|
||||
) -> Callable:
|
||||
return self._on('command', keyword, block, to_me)
|
||||
|
||||
def on_file(
|
||||
self,
|
||||
file_type: str,
|
||||
block: bool = False,
|
||||
to_me: bool = False,
|
||||
) -> Callable:
|
||||
return self._on('file', file_type, block, to_me)
|
||||
|
@ -6,7 +6,9 @@ from gsuid_core.models import Event
|
||||
class Trigger:
|
||||
def __init__(
|
||||
self,
|
||||
type: Literal['prefix', 'suffix', 'keyword', 'fullmatch', 'command'],
|
||||
type: Literal[
|
||||
'prefix', 'suffix', 'keyword', 'fullmatch', 'command', 'file'
|
||||
],
|
||||
keyword: str,
|
||||
func: Callable,
|
||||
block: bool = False,
|
||||
@ -18,13 +20,15 @@ class Trigger:
|
||||
self.block = block
|
||||
self.to_me = to_me
|
||||
|
||||
def check_command(self, raw_msg: Event) -> bool:
|
||||
msg = raw_msg.raw_text
|
||||
def check_command(self, ev: Event) -> bool:
|
||||
msg = ev.raw_text
|
||||
if self.to_me:
|
||||
if raw_msg.is_tome:
|
||||
if ev.is_tome:
|
||||
pass
|
||||
else:
|
||||
return False
|
||||
if self.type == 'file':
|
||||
return self._check_file(self.keyword, ev)
|
||||
return getattr(self, f'_check_{self.type}')(self.keyword, msg)
|
||||
|
||||
def _check_prefix(self, prefix: str, msg: str) -> bool:
|
||||
@ -52,6 +56,12 @@ class Trigger:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _check_file(self, file_type: str, ev: Event) -> bool:
|
||||
if ev.file:
|
||||
if ev.file_name and ev.file_name.split('.')[-1] == file_type:
|
||||
return True
|
||||
return False
|
||||
|
||||
async def get_command(self, msg: Event) -> Event:
|
||||
msg.command = self.keyword
|
||||
msg.text = msg.raw_text.replace(self.keyword, '')
|
||||
|
Loading…
x
Reference in New Issue
Block a user