2024-08-25 14:26:55 +08:00
|
|
|
|
import{_ as s,o as e,c as n,e as a}from"./app-Du8R6vOa.js";const t={},i=a(`<h3 id="class-messageevent" tabindex="-1"><a class="header-anchor" href="#class-messageevent"><span><em><strong>class</strong></em> <code>MessageEvent</code></span></a></h3><h3 id="def-init-self-bot-id-str-message-list-dict-str-any-str-message-type-str-raw-message-str-session-id-str-user-id-str-session-type-str-receive-channel-str-data-optional-dict-str-any-none" tabindex="-1"><a class="header-anchor" href="#def-init-self-bot-id-str-message-list-dict-str-any-str-message-type-str-raw-message-str-session-id-str-user-id-str-session-type-str-receive-channel-str-data-optional-dict-str-any-none"><span> <em><strong>def</strong></em> <code>__init__(self, bot_id: str, message: list[dict[str, Any]] | str, message_type: str, raw_message: str, session_id: str, user_id: str, session_type: str, receive_channel: str, data: Optional[dict[str, Any]]) -> None</code></span></a></h3><p> 轻雪抽象消息事件</p><p>Args:</p><pre><code>bot_id: 机器人ID
|
2024-08-21 18:00:26 +08:00
|
|
|
|
|
|
|
|
|
message: 消息,消息段数组[{type: str, data: dict[str, Any]}]
|
|
|
|
|
|
|
|
|
|
raw_message: 原始消息(通常为纯文本的格式)
|
|
|
|
|
|
|
|
|
|
message_type: 消息类型(private, group, other)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
session_id: 会话ID(私聊通常为用户ID,群聊通常为群ID)
|
|
|
|
|
|
|
|
|
|
session_type: 会话类型(private, group)
|
|
|
|
|
|
|
|
|
|
receive_channel: 接收频道(用于回复消息)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data: 附加数据
|
2024-08-23 23:48:03 +08:00
|
|
|
|
</code></pre><details><summary>源代码</summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> bot_id<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> message<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span><span class="token builtin">dict</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">,</span> Any<span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token builtin">str</span><span class="token punctuation">,</span> message_type<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> raw_message<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> session_id<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> user_id<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> session_type<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> receive_channel<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> data<span class="token punctuation">:</span> Optional<span class="token punctuation">[</span><span class="token builtin">dict</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">,</span> Any<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
|
2024-08-21 18:00:26 +08:00
|
|
|
|
<span class="token triple-quoted-string string">"""
|
|
|
|
|
轻雪抽象消息事件
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
|
|
bot_id: 机器人ID
|
|
|
|
|
message: 消息,消息段数组[{type: str, data: dict[str, Any]}]
|
|
|
|
|
raw_message: 原始消息(通常为纯文本的格式)
|
|
|
|
|
message_type: 消息类型(private, group, other)
|
|
|
|
|
|
|
|
|
|
session_id: 会话ID(私聊通常为用户ID,群聊通常为群ID)
|
|
|
|
|
session_type: 会话类型(private, group)
|
|
|
|
|
receive_channel: 接收频道(用于回复消息)
|
|
|
|
|
|
|
|
|
|
data: 附加数据
|
|
|
|
|
"""</span>
|
|
|
|
|
<span class="token keyword">if</span> data <span class="token keyword">is</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
|
|
|
|
|
data <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|
|
|
|
self<span class="token punctuation">.</span>message_type <span class="token operator">=</span> message_type
|
|
|
|
|
self<span class="token punctuation">.</span>data <span class="token operator">=</span> data
|
|
|
|
|
self<span class="token punctuation">.</span>bot_id <span class="token operator">=</span> bot_id
|
|
|
|
|
self<span class="token punctuation">.</span>message <span class="token operator">=</span> message
|
|
|
|
|
self<span class="token punctuation">.</span>raw_message <span class="token operator">=</span> raw_message
|
|
|
|
|
self<span class="token punctuation">.</span>session_id <span class="token operator">=</span> session_id
|
|
|
|
|
self<span class="token punctuation">.</span>session_type <span class="token operator">=</span> session_type
|
2024-08-23 23:48:03 +08:00
|
|
|
|
self<span class="token punctuation">.</span>user_id <span class="token operator">=</span> user_id
|
2024-08-21 18:00:26 +08:00
|
|
|
|
self<span class="token punctuation">.</span>receive_channel <span class="token operator">=</span> receive_channel
|
2024-08-23 23:48:03 +08:00
|
|
|
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h3 id="def-reply-self-message-str-dict-str-any-none" tabindex="-1"><a class="header-anchor" href="#def-reply-self-message-str-dict-str-any-none"><span> <em><strong>def</strong></em> <code>reply(self, message: str | dict[str, Any]) -> None</code></span></a></h3><p> 回复消息</p><p>Args:</p><pre><code>message:
|
2024-08-21 18:00:26 +08:00
|
|
|
|
</code></pre><p>Returns:</p><details><summary>源代码</summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">def</span> <span class="token function">reply</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> message<span class="token punctuation">:</span> <span class="token builtin">str</span> <span class="token operator">|</span> <span class="token builtin">dict</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">,</span> Any<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
|
|
|
|
|
<span class="token triple-quoted-string string">"""
|
|
|
|
|
回复消息
|
|
|
|
|
Args:
|
|
|
|
|
message:
|
|
|
|
|
Returns:
|
|
|
|
|
"""</span>
|
|
|
|
|
reply_event <span class="token operator">=</span> MessageEvent<span class="token punctuation">(</span>message_type<span class="token operator">=</span>self<span class="token punctuation">.</span>session_type<span class="token punctuation">,</span> message<span class="token operator">=</span>message<span class="token punctuation">,</span> raw_message<span class="token operator">=</span><span class="token string">''</span><span class="token punctuation">,</span> data<span class="token operator">=</span><span class="token punctuation">{</span><span class="token string">'message'</span><span class="token punctuation">:</span> message<span class="token punctuation">}</span><span class="token punctuation">,</span> bot_id<span class="token operator">=</span>self<span class="token punctuation">.</span>bot_id<span class="token punctuation">,</span> session_id<span class="token operator">=</span>self<span class="token punctuation">.</span>session_id<span class="token punctuation">,</span> session_type<span class="token operator">=</span>self<span class="token punctuation">.</span>session_type<span class="token punctuation">,</span> receive_channel<span class="token operator">=</span><span class="token string">'_'</span><span class="token punctuation">)</span>
|
|
|
|
|
shared_memory<span class="token punctuation">.</span>publish<span class="token punctuation">(</span>self<span class="token punctuation">.</span>receive_channel<span class="token punctuation">,</span> reply_event<span class="token punctuation">)</span>
|
2024-08-23 23:48:03 +08:00
|
|
|
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h3 id="var-reply-event-messageevent-message-type-self-session-type-message-message-raw-message-data-message-message-bot-id-self-bot-id-session-id-self-session-id-session-type-self-session-type-receive-channel" tabindex="-1"><a class="header-anchor" href="#var-reply-event-messageevent-message-type-self-session-type-message-message-raw-message-data-message-message-bot-id-self-bot-id-session-id-self-session-id-session-type-self-session-type-receive-channel"><span><em><strong>var</strong></em> <code>reply_event = MessageEvent(message_type=self.session_type, message=message, raw_message='', data={'message': message}, bot_id=self.bot_id, session_id=self.session_id, session_type=self.session_type, receive_channel='_')</code></span></a></h3><h3 id="var-data" tabindex="-1"><a class="header-anchor" href="#var-data"><span><em><strong>var</strong></em> <code>data = {}</code></span></a></h3>`,14),p=[i];function o(l,r){return e(),n("div",null,p)}const d=s(t,[["render",o],["__file","event.html.vue"]]),u=JSON.parse(`{"path":"/dev/api/message/event.html","title":"liteyuki.message.event","lang":"zh-CN","frontmatter":{"title":"liteyuki.message.event","order":1,"icon":"laptop-code","category":"API","description":"class MessageEvent def __init__(self, bot_id: str, message: list[dict[str, Any]] | str, message_type: str, raw_message: str, session_id: str, user_id: str, session_type: str, re...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/message/event.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/message/event.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki.message.event"}],["meta",{"property":"og:description","content":"class MessageEvent def __init__(self, bot_id: str, message: list[dict[str, Any]] | str, message_type: str, raw_message: str, session_id: str, user_id: str, session_type: str, re..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:locale:alternate","content":"en-US"}],["meta",{"property":"og:updated_time","content":"2024-08-21T09:59:21.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-21T09:59:21.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"liteyuki.message.event\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-21T09:59:21.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class MessageEvent","slug":"class-messageevent","link":"#class-messageevent","children":[]},{"level":3,"title":"def __init__(self, bot_id: str, message: list[dict[str, Any]] | str, message_type: str, raw_message: str, session_id: str, user_id: str, session_type: str, receive_channel: str, data: Optional[dict[str, Any]]) -> None","slug":"def-init-self-bot-id-str-message-list-dict-str-any-str-message-type-str-raw-message-str-session-id-str-user-id-str-session-type-str-receive-channel-str-data-optional-dict-str-any-none","link":"#def-init-self-bot-id-str-message-list-dict-str-any-str-message-type-str-raw-message-str-session-id-str-user-id-str-session-type-str-receive-channel-str-data-optional-dict-str-any-none","children":[]},{"level":3,"title":"def reply(self, message: str | dict[str, Any]) -> None","slug":"def-reply-self-message-str-dict-str-any-none","link":"#def-reply-self-message-str-dict-str-any-none","children":[]},{"level":3,"title":"var reply_event = MessageEvent(message_type=self.session_type, message=message, raw_message='', data={'message': messag
|