2024-08-19 23:47:39 +08:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
|
|
|
|
|
|
|
@Time : 2024/8/19 下午10:47
|
|
|
|
@Author : snowykami
|
|
|
|
@Email : snowykami@outlook.com
|
|
|
|
@File : event.py
|
|
|
|
@Software: PyCharm
|
|
|
|
"""
|
2024-08-20 06:20:41 +08:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from liteyuki.comm.storage import shared_memory
|
2024-08-19 23:47:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Event:
|
2024-08-20 06:20:41 +08:00
|
|
|
def __init__(self, type: str, data: dict[str, Any], bot_id: str, session_id: str, session_type: str, receive_channel: str = "event_to_nonebot"):
|
|
|
|
"""
|
|
|
|
事件
|
|
|
|
Args:
|
|
|
|
type: 类型
|
|
|
|
data: 数据
|
|
|
|
bot_id: 机器人ID
|
|
|
|
session_id: 会话ID
|
|
|
|
session_type: 会话类型
|
|
|
|
receive_channel: 接收频道
|
|
|
|
"""
|
|
|
|
self.type = type
|
2024-08-19 23:47:39 +08:00
|
|
|
self.data = data
|
2024-08-20 06:20:41 +08:00
|
|
|
self.bot_id = bot_id
|
|
|
|
self.session_id = session_id
|
|
|
|
self.session_type = session_type
|
|
|
|
self.receive_channel = receive_channel
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"Event(type={self.type}, data={self.data}, bot_id={self.bot_id}, session_id={self.session_id}, session_type={self.session_type})"
|
|
|
|
|
|
|
|
def reply(self, message: str | dict[str, Any]):
|
|
|
|
"""
|
|
|
|
回复消息
|
|
|
|
Args:
|
|
|
|
message:
|
|
|
|
Returns:
|
|
|
|
"""
|
|
|
|
to_nonebot_event = Event(
|
|
|
|
type=self.session_type,
|
|
|
|
data={
|
|
|
|
"message": message
|
|
|
|
},
|
|
|
|
bot_id=self.bot_id,
|
|
|
|
session_id=self.session_id,
|
|
|
|
session_type=self.session_type,
|
|
|
|
receive_channel="_"
|
|
|
|
)
|
|
|
|
print(to_nonebot_event)
|
|
|
|
shared_memory.publish(self.receive_channel, to_nonebot_event)
|