1
0
forked from bot/app
LiteyukiBot/assets/matcher.html-BhA4-npt.js

39 lines
10 KiB
JavaScript

import{_ as n,o as e,c as s,e as a}from"./app-BvUYPzLF.js";const t={},o=a(`<h1 id="liteyuki-message-matcher" tabindex="-1"><a class="header-anchor" href="#liteyuki-message-matcher"><span>liteyuki.message.matcher</span></a></h1><p><strong>说明</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/8/19 下午10:51 @Author : snowykami @Email : snowykami@outlook.com @File : matcher.py @Software: PyCharm</p><h3 id="class-matcher" tabindex="-1"><a class="header-anchor" href="#class-matcher"><span><em><strong>class</strong></em> <code>Matcher</code></span></a></h3><h4 id="def-init-self-rule-rule-priority-int-block-bool" tabindex="-1"><a class="header-anchor" href="#def-init-self-rule-rule-priority-int-block-bool"><span><em><strong>def</strong></em> <code>__init__(self, rule: Rule, priority: int, block: bool)</code></span></a></h4><p><strong>说明</strong>: 匹配器</p><p><strong>参数</strong>:</p><blockquote><ul><li>rule: 规则</li><li>priority: 优先级 &gt;= 0</li><li>block: 是否阻断后续优先级更低的匹配器</li></ul></blockquote><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/message/matcher.py#L21" target="_blank">在GitHub上查看</a></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> rule<span class="token punctuation">:</span> Rule<span class="token punctuation">,</span> priority<span class="token punctuation">:</span> <span class="token builtin">int</span><span class="token punctuation">,</span> block<span class="token punctuation">:</span> <span class="token builtin">bool</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
匹配器
Args:
rule: 规则
priority: 优先级 &gt;= 0
block: 是否阻断后续优先级更低的匹配器
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>rule <span class="token operator">=</span> rule
self<span class="token punctuation">.</span>priority <span class="token operator">=</span> priority
self<span class="token punctuation">.</span>block <span class="token operator">=</span> block
self<span class="token punctuation">.</span>handlers<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>EventHandler<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
</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></div></details><h4 id="def-handle-self-callable-eventhandler-eventhandler" tabindex="-1"><a class="header-anchor" href="#def-handle-self-callable-eventhandler-eventhandler"><span><em><strong>def</strong></em> <code>handle(self) -&gt; Callable[[EventHandler], EventHandler]</code></span></a></h4><p><strong>说明</strong>: 添加处理函数,装饰器</p><p><strong>返回</strong>: 装饰器 handler</p><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/message/matcher.py#L37" target="_blank">在GitHub上查看</a></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">handle</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> Callable<span class="token punctuation">[</span><span class="token punctuation">[</span>EventHandler<span class="token punctuation">]</span><span class="token punctuation">,</span> EventHandler<span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
添加处理函数,装饰器
Returns:
装饰器 handler
&quot;&quot;&quot;</span>
<span class="token keyword">def</span> <span class="token function">decorator</span><span class="token punctuation">(</span>handler<span class="token punctuation">:</span> EventHandler<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> EventHandler<span class="token punctuation">:</span>
self<span class="token punctuation">.</span>handlers<span class="token punctuation">.</span>append<span class="token punctuation">(</span>handler<span class="token punctuation">)</span>
<span class="token keyword">return</span> handler
<span class="token keyword">return</span> decorator
</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></div></details><h4 id="async-def-run-self-event-messageevent-none" tabindex="-1"><a class="header-anchor" href="#async-def-run-self-event-messageevent-none"><span><em><strong>async def</strong></em> <code>run(self, event: MessageEvent) -&gt; None</code></span></a></h4><p><strong>说明</strong>: 运行处理函数</p><p><strong>参数</strong>:</p><blockquote><ul><li>event:</li></ul></blockquote><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/message/matcher.py#L49" target="_blank">在GitHub上查看</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">run</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> event<span class="token punctuation">:</span> MessageEvent<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
运行处理函数
Args:
event:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token keyword">await</span> self<span class="token punctuation">.</span>rule<span class="token punctuation">(</span>event<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span>
<span class="token keyword">for</span> handler <span class="token keyword">in</span> self<span class="token punctuation">.</span>handlers<span class="token punctuation">:</span>
<span class="token keyword">try</span><span class="token punctuation">:</span>
<span class="token keyword">await</span> handler<span class="token punctuation">(</span>event<span class="token punctuation">)</span>
<span class="token keyword">except</span> Exception<span class="token punctuation">:</span>
traceback<span class="token punctuation">.</span>print_exc<span class="token punctuation">(</span><span class="token punctuation">)</span>
</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></div></details>`,18),i=[o];function l(p,c){return e(),s("div",null,i)}const u=n(t,[["render",l],["__file","matcher.html.vue"]]),d=JSON.parse('{"path":"/dev/api/message/matcher.html","title":"liteyuki.message.matcher","lang":"zh-CN","frontmatter":{"title":"liteyuki.message.matcher","lastUpdated":false,"description":"liteyuki.message.matcher 说明: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/19 下午10:51 @Author : snowykami @Email : snowykami@outlook.com @File : mat...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/message/matcher.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/message/matcher.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki.message.matcher"}],["meta",{"property":"og:description","content":"liteyuki.message.matcher 说明: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/19 下午10:51 @Author : snowykami @Email : snowykami@outlook.com @File : mat..."}],["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-29T06:19:39.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:19:39.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"liteyuki.message.matcher\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class Matcher","slug":"class-matcher","link":"#class-matcher","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.98,"words":294},"filePathRelative":"dev/api/message/matcher.md","localizedDate":"2024年8月21日","autoDesc":true}');export{u as comp,d as data};