app/assets/en_dev_api_message_on.md.DTuiNBGv.js

16 lines
9.0 KiB
JavaScript
Raw Normal View History

import{_ as s,c as i,o as a,a6 as e}from"./chunks/framework.BcfwU5BI.js";const g=JSON.parse('{"title":"liteyuki.message.on","description":"","frontmatter":{"title":"liteyuki.message.on"},"headers":[],"relativePath":"en/dev/api/message/on.md","filePath":"en/dev/api/message/on.md","lastUpdated":1725101868000}'),t={name:"en/dev/api/message/on.md"},n=e(`<h1 id="liteyuki-message-on" tabindex="-1">liteyuki.message.on <a class="header-anchor" href="#liteyuki-message-on" aria-label="Permalink to &quot;liteyuki.message.on&quot;"></a></h1><p>Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/8/19 下午10:52 @Author : snowykami @Email : <a href="mailto:snowykami@outlook.com" target="_blank" rel="noreferrer">snowykami@outlook.com</a> @File : on.py @Software: PyCharm</p><h3 id="func-add-matcher-matcher-matcher" tabindex="-1"><em><strong>func</strong></em> <code>add_matcher(matcher: Matcher)</code> <a class="header-anchor" href="#func-add-matcher-matcher-matcher" aria-label="Permalink to &quot;***func*** \`add_matcher(matcher: Matcher)\`&quot;"></a></h3><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/message/on.py#L41" target="_blank">View on GitHub</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> add_matcher</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(matcher: Matcher):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i, m </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> enumerate</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(_matcher_list):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> m.priority </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> matcher.priority:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> _matcher_list.insert(i, matcher)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> break</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> _matcher_list.append(matcher)</span></span></code></pre></div></details><h3 id="func-on-message-rule-rule-empty-rule-priority-int-0-block-bool-false-matcher" tabindex="-1"><em><strong>func</strong></em> <code>on_message(rule: Rule = empty_rule, priority: int = 0, block: bool = False) -&gt; Matcher</code> <a class="header-anchor" href="#func-on-message-rule-rule-empty-rule-priority-int-0-block-bool-false-matcher" aria-label="Permalink to &quot;***func*** \`on_message(rule: Rule = empty_rule, priority: int = 0, block: bool = False) -&gt; Matcher\`&quot;"></a></h3><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/message/on.py#L50" target="_blank">View on GitHub</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> on_message</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(rule: Rule</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">empty_rule, priority: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">int</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, block: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">bool</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">False</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) -&gt; Matcher:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> matcher </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Matcher(rule, priority, block)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> add_matcher(matcher)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> matcher</span></span></code></pre></div></details><h3 id="func-on-keywords-keywords-list-str-rule-empty-rule-priority-int-0-block-bool-false-matcher" tabindex="-1"><em><strong>func</strong></em> <code>on_keywords(keywords: list[str], rule = empty_rule, priority: int = 0, block: bool = False) -&gt; Matcher</code> <a class="header-anchor" href="#func-on-keywords-keywords-list-str-rule-empty-rule-priority-int-0-block-bool-false-matcher" aria-label="Permalink to &quot;***func*** \`on_keywords(keywords: list[str], rule = empty_rule, priority: int = 0, block: bool = False) -&gt; Matcher\`&quot;"></a></h3><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/message/on.py#L57" target="_blank">View on GitHub</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> on_keywords</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(keywords: list[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">str</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">], rule</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">empty_rule, priority: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">int</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, block: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">bool</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">False</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) -&gt; Matcher:</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> @Rule</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> async</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> on_keywords_rule</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(event: MessageEvent):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> any</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">((keyword </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> event.raw_message </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> keyword </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> keywords))</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> on_message(on_keywords_rule </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> rule, priority, block)</span></span></code></pre></div></details>`,9),l=[n];function h(r,k,p,o,d,y){return a(),i("div",null,l)}const E=s(t,[["render",h]]);export{g as __pageData,E as default};