mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-03-20 20:17:22 +08:00
49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
from typing import List, Optional, Union
|
|
|
|
from pydantic import Field
|
|
|
|
from app.actions import BaseAction
|
|
from app.schemas import ActionParams, ActionContext, MessageChannel
|
|
|
|
|
|
class SendMessageParams(ActionParams):
|
|
"""
|
|
发送消息参数
|
|
"""
|
|
channel: Optional[List[str]] = Field([], description="消息渠道")
|
|
userid: Optional[Union[str, int]] = Field(None, description="用户ID")
|
|
|
|
|
|
class SendMessageAction(BaseAction):
|
|
"""
|
|
发送消息
|
|
"""
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return "发送消息"
|
|
|
|
@property
|
|
def description(self) -> str:
|
|
return "发送特定消息"
|
|
|
|
@property
|
|
def success(self) -> bool:
|
|
return self.done
|
|
|
|
async def execute(self, params: SendMessageParams, context: ActionContext) -> ActionContext:
|
|
"""
|
|
发送messages中的消息
|
|
"""
|
|
for message in context.messages:
|
|
if params.channel:
|
|
message.channel = MessageChannel(params.channel)
|
|
if params.userid:
|
|
message.userid = params.userid
|
|
self.chain.post_message(message)
|
|
|
|
context.messages = []
|
|
|
|
self.job_done()
|
|
return context
|