1
0
forked from bot/app

Compare commits

...

No commits in common. "main" and "old-docs" have entirely different histories.

612 changed files with 12726 additions and 33692 deletions

View File

@ -1,53 +0,0 @@
---
name: 问题反馈
about: 反馈你在使用轻雪中遇到的问题
title: ''
labels: ''
assignees: ''
---
# 问题反馈
## **请确保**
- 已认真阅读[文档]("https://bot.liteyuki.icu"),该问题不是文档提及的或你自己操作不当造成的
- 你的问题是在最新版本的代码上测试的
- 请勿重复提交相同或类似的issue
## **描述问题**
请在此简单描述问题
## **如何复现**
请阐述一下如何重现这个问题
### 预期
描述你期望发生的事情
### 实际
描述实际发生的事情
## **日志或截图**
```
日志内容
```
## **设备信息**
- **系统**: [例如 Ubuntu 22.04]
- **CPU**: [例如 Intel i7-7700K]
- **内存**: [例如 16GB]
- **Python**: [例如CPython 3.10.7]
**补充内容**
可选,推荐提供`pip freeze`的输出,以及其他相关信息,以及你的建议

View File

@ -1,11 +0,0 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
- package-ecosystem: "" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

View File

@ -1,44 +0,0 @@
# 问题反馈
## **请确保**
- 已认真阅读[文档]("https://bot.liteyuki.icu"),该问题不是文档提及的或你自己操作不当造成的
- 你的问题是在最新版本的代码上测试的
- 请勿重复提交相同或类似的issue
## **描述问题**
请在此简单描述问题
## **如何复现**
请阐述一下如何重现这个问题
### 预期
描述你期望发生的事情
### 实际
描述实际发生的事情
## **日志或截图**
```
日志内容
```
## **设备信息**
- **系统**: [例如 Ubuntu 22.04]
- **CPU**: [例如 Intel i7-7700K]
- **内存**: [例如 16GB]
- **Python**: [例如CPython 3.10.7]
**补充内容**
可选,推荐提供`pip freeze`的输出,以及其他相关信息,以及你的建议

View File

@ -1,70 +0,0 @@
# 构建 VitePress 站点并将其部署到 GitHub Pages 的示例工作流程
#
name: Deploy VitePress site to Pages
on:
# 在针对 `main` 分支的推送上运行。如果你
# 使用 `master` 分支作为默认分支,请将其更改为 `master`
push:
branches: [main]
# 允许你从 Actions 选项卡手动运行此工作流程
workflow_dispatch:
# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages
permissions:
contents: write
# 只允许同时进行一次部署,跳过正在运行和最新队列之间的运行队列
# 但是,不要取消正在进行的运行,因为我们希望允许这些生产部署完成
concurrency:
group: pages
cancel-in-progress: false
jobs:
# 构建工作
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # 如果未启用 lastUpdated则不需要
# - uses: pnpm/action-setup@v3 # 如果使用 pnpm请取消注释
# - uses: oven-sh/setup-bun@v1 # 如果使用 Bun请取消注释
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.11'
- name: Setup API markdown
run: |-
python -m pip install litedoc
litedoc liteyuki -o docs/zh/dev/api -l zh-Hans -cd class -fd func -md func -vd var -cs -bu https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/
litedoc liteyuki -o docs/en/dev/api -l en -cd class -fd func -md func -vd var -cs -bu https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/
- name: 安装 pnpm
uses: pnpm/action-setup@v2
with:
run_install: true
version: 8
- name: 设置 Node.js
run: |-
cd docs
pnpm install
- name: 构建文档
env:
NODE_OPTIONS: --max_old_space_size=8192
run: |-
cd docs
pnpm run docs:build
> .vitepress/dist/.nojekyll
- name: 部署文档
uses: JamesIves/github-pages-deploy-action@v4
with:
# 这是文档部署到的分支名称
branch: docs
folder: docs/.vitepress/dist

View File

@ -1,20 +0,0 @@
name: Publish
on:
release:
types: [published]
jobs:
pypi-publish:
name: upload release to PyPI
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
- uses: pdm-project/setup-pdm@v3
- name: Publish package distributions to PyPI
run: pdm publish

67
.gitignore vendored
View File

@ -1,67 +0,0 @@
.venv/
.idea/
.vscode/
.cache/
venv/
node_modules/
data/
db/
/resources/
__pycache__/
*.pyc
*.pyo
*.pyd
*.pyw
/plugins/
#config
/config/
!config/default.yml
_config.yml
config.yml
config.example.yml
# vuepress
.github
# mupy
mypy.ini
# nuitka
compile.bat
src/resources/templates/latest-debug.html
main.build/
main.dist/
main.exe
main.cmd
docs/.vuepress/.cache/
docs/.vuepress/.temp/
docs/.vuepress/dist/
prompt.txt
# js
**/echarts.js
.env
# pdm
.pdm-python
.pdm-build
dist
doc
mkdoc2.py
result.json
# litedoc
docs/zh/dev/api
docs/en/dev/api
mkdoc.bat
# vitepress
docs/.vitepress/dist/
docs/.vitepress/cache
docs/.vitepress/.temp

40
404.html Normal file

File diff suppressed because one or more lines are too long

1
CNAME Normal file
View File

@ -0,0 +1 @@
bot.liteyuki.icu

View File

@ -1,19 +0,0 @@
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/library/python:3.10-slim-bullseye
ENV TZ Asia/Shanghai
COPY docker/sources.list /etc/apt/sources.list
RUN apt-get update && apt-get install -y git
WORKDIR /liteyukibot
COPY . /liteyukibot
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN apt-get install -y libnss3 libnspr4 libdbus-1-3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libatspi2.0-0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libxkbcommon0 libasound2
EXPOSE 20216
CMD ["python", "main.py"]

31
LICENSE
View File

@ -1,31 +0,0 @@
LSO license
LiteyukiStudio Opensource license
---
版权所有 © 2024 Snowykami
---
免费向任何获得副本的人或组织授予以相同许可为基础的权利
包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件的副本
本软件及相关文档文件(以下简称"本软件")在相同方式许可为基础, 以开源的形式发布于互联网抑或其他媒体介质平台
任何人都有权利获取副本并以上述方式获取许可传播和/或使用
但获取副本时仍需注意:
- 上述版权声明和本许可声明应包含在本软件的副本中
- 使用本软件及其副本时仍需保持与原有形式相同
- 在使用时仍需将本软件的副本以相同许可公开表现:
- 不得未经原作者允许将本软件的副本以非原许可的形式对外盈利
---
该软件按"原样"之副本提供,不提供任何形式的任意保证,明示或暗示:
包括但不限于适销性保证, 适用于特定目的非侵权
在任何情况下, 作者或版权所有者对任何非因作者或版权所有者使用该软件造成的索赔、损害或其他责任, 无论是在合同诉讼、侵权行为还是其他诉讼中都不具有责任, 作者及其版权所有者有权利驳回使用者因个人原因造成的任何损失之赔付

View File

@ -1,51 +0,0 @@
<div align="center">
[//]: # (<img src="https://cdn.liteyuki.icu/static/svg/lylogo-full.svg" style="align-content: center; width: 50%; margin-top:10%;" alt="a">)
[![][banner]][lightyuki-link]
<h2><a href="https://bot.liteyuki.icu"> <span style="color: #a2d8f4">轻雪</span> <span style="color: #d0e9ff">6</span></a></h2>
<h4> <span style="color: #a2d8f4">✨ 轻量,高效,易于扩展✨</span></h4>
[![][OneBot]][onebot-link]
[![][NoneBot2]][nonebot-link]
[![][Liteyuki6.0]][lightyuki-link]
[![][Python3.10+]][python-link]
[![][Usage]][usage-link]
- 基于[Nonebot2](https://github.com/nonebot/nonebot2),有良好的生态支持
- 开箱即用,无需复杂配置
- 集成包管理器,支持一键安装插件
- 支持OneBot标准通信但不限于此
- 自定义主题支持,满足审美需求
- 国际化支持,支持多种语言
- 高性能500插件2s内启动
<h3>👇更多内容请访问👇</h3>
<h2><a href="https://bot.liteyuki.icu">轻雪机器人主页</a></h2>
</div>
### 感谢
- [NoneBot2](https://nonebot.dev)提供的框架支持
- [nonebot-plugin-alconna](https://github.com/ArcletProject/nonebot-plugin-alconna)提供的命令解析功能
[OneBot]: https://img.shields.io/badge/OneBot-11/12-blue?style=for-the-badge
[NoneBot2]: https://img.shields.io/badge/Nonebot-2-red?style=for-the-badge
[Liteyuki6.0]: https://img.shields.io/badge/Liteyuki-6.0-blue?style=for-the-badge
[Python3.10+]: https://img.shields.io/badge/Python-3.10+-blue?style=for-the-badge
[Usage]: https://img.shields.io/badge/文档-页面-blue?style=for-the-badge
[onebot-link]:https://onebot.dev/
[nonebot-link]:https://nonebot.dev/
[lightyuki-link]:/
[python-link]:https://www.python.org/
[usage-link]:https://bot.liteyuki.icu/
[banner]: https://socialify.git.ci/LiteyukiStudio/LiteyukiBot/image?description=1&forks=1&issues=1&Plus&pulls=1&stargazers=1&theme=Auto&logo=https%3a%2f%2fcdn.liteyuki.icu%2fstatic%2fsvg%2flylogo-full.svg

View File

@ -0,0 +1 @@
import{_ as t,o as e,c as o,b as n}from"./app-BvUYPzLF.js";const a={},r=n("p",null,"404 Not Found",-1),s=[r];function c(p,i){return e(),o("div",null,s)}const d=t(a,[["render",c],["__file","404.html.vue"]]),m=JSON.parse('{"path":"/404.html","title":"","lang":"zh-CN","frontmatter":{"layout":"NotFound","description":"404 Not Found","head":[["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/404.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:description","content":"404 Not Found"}],["meta",{"property":"og:type","content":"website"}],["meta",{"property":"og:locale","content":"zh-CN"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"WebPage\\",\\"name\\":\\"\\",\\"description\\":\\"404 Not Found\\"}"]]},"headers":[],"git":{},"readingTime":{"minutes":0.01,"words":3},"filePathRelative":null,"autoDesc":true}');export{d as comp,m as data};

View File

@ -0,0 +1 @@
import{_ as e,o as t,c as o,e as r}from"./app-BvUYPzLF.js";const a={},n=r("<ol><li>本项目遵循<code>MIT</code>协议,你可以自由使用,修改,分发,但是请保留原作者信息</li><li>你可以选择开启<code>auto_report</code>(默认开启),轻雪会收集以下内容 <ul><li>运行环境的设备信息CPU内存系统信息及Python信息</li><li>插件信息(不含插件数据)</li><li>部分异常信息,</li><li>会话负载信息(不含隐私部分) 以上内容仅用于项目的优化,不包含任何隐私信息,且通过安全的方式传输到轻雪的服务器,若你不希望提供这些信息,可以在配置文件中把<code>auto_report</code>设定为<code>false</code></li></ul></li><li>本项目不会收集用户的任何隐私信息,但请注意甄别第三方插件的安全性</li><li>使用此项目代表你已经同意以上协议</li></ol>",1),i=[n];function l(c,s){return t(),o("div",null,i)}const p=e(a,[["render",l],["__file","agreement.html.vue"]]),d=JSON.parse('{"path":"/en/usage/agreement.html","title":"User Agreement","lang":"en-US","frontmatter":{"title":"User Agreement","icon":"user-secret","order":3,"category":"usage","description":"本项目遵循MIT协议你可以自由使用修改分发但是请保留原作者信息 你可以选择开启auto_report(默认开启),轻雪会收集以下内容 运行环境的设备信息CPU内存系统信息及Python信息 插件信息(不含插件数据) 部分异常信息, 会话负载信息(不含隐私部分) 以上内容仅用于项目的优化,不包含任何隐私信息,且通过安全的方式传输到轻雪的服务...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/usage/agreement.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/usage/agreement.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"User Agreement"}],["meta",{"property":"og:description","content":"本项目遵循MIT协议你可以自由使用修改分发但是请保留原作者信息 你可以选择开启auto_report(默认开启),轻雪会收集以下内容 运行环境的设备信息CPU内存系统信息及Python信息 插件信息(不含插件数据) 部分异常信息, 会话负载信息(不含隐私部分) 以上内容仅用于项目的优化,不包含任何隐私信息,且通过安全的方式传输到轻雪的服务..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-16T18:24:25.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-16T18:24:25.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"User Agreement\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-16T18:24:25.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1723829277000,"updatedTime":1723832665000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.74,"words":222},"filePathRelative":"en/usage/agreement.md","localizedDate":"August 16, 2024","autoDesc":true}');export{p as comp,d as data};

View File

@ -0,0 +1 @@
import{_ as e,o as t,c as o,e as a}from"./app-BvUYPzLF.js";const r={},i=a("<ol><li>本项目遵循<code>MIT</code>协议,你可以自由使用,修改,分发,但是请保留原作者信息</li><li>你可以选择开启<code>auto_report</code>(默认开启),轻雪会收集以下内容 <ul><li>运行环境的设备信息CPU内存系统信息及Python信息</li><li>插件信息(不含插件数据)</li><li>部分异常信息,</li><li>会话负载信息(不含隐私部分) 以上内容仅用于项目的优化,不包含任何隐私信息,且通过安全的方式传输到轻雪的服务器,若你不希望提供这些信息,可以在配置文件中把<code>auto_report</code>设定为<code>false</code></li></ul></li><li>本项目不会收集用户的任何隐私信息,但请注意甄别第三方插件的安全性</li><li>使用此项目代表你已经同意以上协议</li></ol>",1),n=[i];function l(c,m){return t(),o("div",null,n)}const s=e(r,[["render",l],["__file","agreement.html.vue"]]),d=JSON.parse('{"path":"/usage/agreement.html","title":"用户协议","lang":"zh-CN","frontmatter":{"title":"用户协议","icon":"user-secret","order":3,"category":"使用手册","description":"本项目遵循MIT协议你可以自由使用修改分发但是请保留原作者信息 你可以选择开启auto_report(默认开启),轻雪会收集以下内容 运行环境的设备信息CPU内存系统信息及Python信息 插件信息(不含插件数据) 部分异常信息, 会话负载信息(不含隐私部分) 以上内容仅用于项目的优化,不包含任何隐私信息,且通过安全的方式传输到轻雪的服务...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/usage/agreement.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/usage/agreement.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"用户协议"}],["meta",{"property":"og:description","content":"本项目遵循MIT协议你可以自由使用修改分发但是请保留原作者信息 你可以选择开启auto_report(默认开启),轻雪会收集以下内容 运行环境的设备信息CPU内存系统信息及Python信息 插件信息(不含插件数据) 部分异常信息, 会话负载信息(不含隐私部分) 以上内容仅用于项目的优化,不包含任何隐私信息,且通过安全的方式传输到轻雪的服务..."}],["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-07-20T16:40:55.000Z"}],["meta",{"property":"article:modified_time","content":"2024-07-20T16:40:55.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"用户协议\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-07-20T16:40:55.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1711621856000,"updatedTime":1721493655000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":3},{"name":"Nanaloveyuki","email":"miaomiao_159@outlook.com","commits":1}]},"readingTime":{"minutes":0.76,"words":227},"filePathRelative":"usage/agreement.md","localizedDate":"2024年3月28日","autoDesc":true}');export{s as comp,d as data};

45
assets/app-BvUYPzLF.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,212 @@
import{_ as n,o as s,c as a,e as t}from"./app-BvUYPzLF.js";const e={},p=t(`<h1 id="liteyuki-comm-channel" tabindex="-1"><a class="header-anchor" href="#liteyuki-comm-channel"><span>liteyuki.comm.channel</span></a></h1><p><strong>说明</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/7/26 下午11:21 @Author : snowykami @Email : snowykami@outlook.com @File : channel_.py @Software: PyCharm</p><p>本模块定义了一个通用的通道类,用于进程间通信</p><h3 id="class-channel-generic-t" tabindex="-1"><a class="header-anchor" href="#class-channel-generic-t"><span><em><strong>class</strong></em> <code>Channel(Generic[T])</code></span></a></h3><h4 id="def-init-self-name-str-type-check-optional-bool-none" tabindex="-1"><a class="header-anchor" href="#def-init-self-name-str-type-check-optional-bool-none"><span><em><strong>def</strong></em> <code>__init__(self, name: str, type_check: Optional[bool] = None)</code></span></a></h4><p><strong>说明</strong>: 初始化通道</p><p><strong>参数</strong>:</p><blockquote><ul><li>name: 通道ID</li><li>type_check: 是否开启类型检查, 若为空,则传入泛型默认开启,否则默认关闭</li></ul></blockquote><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L41" 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> name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> type_check<span class="token punctuation">:</span> Optional<span class="token punctuation">[</span><span class="token builtin">bool</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>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
初始化通道
Args:
name: 通道ID
type_check: 是否开启类型检查, 若为空则传入泛型默认开启否则默认关闭
&quot;&quot;&quot;</span>
<span class="token punctuation">(</span>self<span class="token punctuation">.</span>conn_send<span class="token punctuation">,</span> self<span class="token punctuation">.</span>conn_recv<span class="token punctuation">)</span> <span class="token operator">=</span> Pipe<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_conn_send_inner<span class="token punctuation">,</span> self<span class="token punctuation">.</span>_conn_recv_inner<span class="token punctuation">)</span> <span class="token operator">=</span> Pipe<span class="token punctuation">(</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>_closed <span class="token operator">=</span> <span class="token boolean">False</span>
self<span class="token punctuation">.</span>_on_main_receive_func_ids<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span><span class="token builtin">int</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>_on_sub_receive_func_ids<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span><span class="token builtin">int</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>name<span class="token punctuation">:</span> <span class="token builtin">str</span> <span class="token operator">=</span> name
self<span class="token punctuation">.</span>is_receive_loop_running <span class="token operator">=</span> <span class="token boolean">False</span>
<span class="token keyword">if</span> type_check <span class="token keyword">is</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
type_check <span class="token operator">=</span> self<span class="token punctuation">.</span>_get_generic_type<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span>
<span class="token keyword">elif</span> type_check<span class="token punctuation">:</span>
<span class="token keyword">if</span> self<span class="token punctuation">.</span>_get_generic_type<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">is</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
<span class="token keyword">raise</span> TypeError<span class="token punctuation">(</span><span class="token string">&#39;Type hint is required for enforcing type check.&#39;</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>type_check <span class="token operator">=</span> type_check
<span class="token keyword">if</span> name <span class="token keyword">in</span> _channel<span class="token punctuation">:</span>
<span class="token keyword">raise</span> ValueError<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Channel </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> already exists&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token keyword">if</span> name <span class="token keyword">in</span> _channel<span class="token punctuation">:</span>
<span class="token keyword">raise</span> ValueError<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Channel </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> already exists&#39;</span></span><span class="token punctuation">)</span>
_channel<span class="token punctuation">[</span>name<span class="token punctuation">]</span> <span class="token operator">=</span> self
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Channel </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> initialized in main process&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Channel </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> initialized in sub process, should manually set in main process&#39;</span></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 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><h4 id="def-get-generic-type-self-optional-type" tabindex="-1"><a class="header-anchor" href="#def-get-generic-type-self-optional-type"><span><em><strong>def</strong></em> <code>_get_generic_type(self) -&gt; Optional[type]</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>: Optional[type]: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L77" 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">_get_generic_type</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> Optional<span class="token punctuation">[</span><span class="token builtin">type</span><span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取通道传递泛型类型
Returns:
Optional[type]: 泛型类型
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> <span class="token builtin">hasattr</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> <span class="token string">&#39;__orig_class__&#39;</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> get_args<span class="token punctuation">(</span>self<span class="token punctuation">.</span>__orig_class__<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
<span class="token keyword">return</span> <span class="token boolean">None</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></div></details><h4 id="def-validate-structure-self-data-any-structure-type-bool" tabindex="-1"><a class="header-anchor" href="#def-validate-structure-self-data-any-structure-type-bool"><span><em><strong>def</strong></em> <code>_validate_structure(self, data: Any, structure: type) -&gt; bool</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>data: </li><li>structure: </li></ul></blockquote><p><strong></strong>: bool: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L88" 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">_validate_structure</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> data<span class="token punctuation">:</span> Any<span class="token punctuation">,</span> structure<span class="token punctuation">:</span> <span class="token builtin">type</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">bool</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
验证数据结构
Args:
data: 数据
structure: 结构
Returns:
bool: 是否通过验证
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>structure<span class="token punctuation">,</span> <span class="token builtin">type</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> structure<span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>structure<span class="token punctuation">,</span> <span class="token builtin">tuple</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> <span class="token builtin">tuple</span><span class="token punctuation">)</span> <span class="token keyword">or</span> <span class="token builtin">len</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>structure<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> <span class="token boolean">False</span>
<span class="token keyword">return</span> <span class="token builtin">all</span><span class="token punctuation">(</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>_validate_structure<span class="token punctuation">(</span>d<span class="token punctuation">,</span> s<span class="token punctuation">)</span> <span class="token keyword">for</span> <span class="token punctuation">(</span>d<span class="token punctuation">,</span> s<span class="token punctuation">)</span> <span class="token keyword">in</span> <span class="token builtin">zip</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> structure<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>structure<span class="token punctuation">,</span> <span class="token builtin">list</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> <span class="token builtin">list</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> <span class="token boolean">False</span>
<span class="token keyword">return</span> <span class="token builtin">all</span><span class="token punctuation">(</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>_validate_structure<span class="token punctuation">(</span>d<span class="token punctuation">,</span> structure<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token keyword">for</span> d <span class="token keyword">in</span> data<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>structure<span class="token punctuation">,</span> <span class="token builtin">dict</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> <span class="token builtin">dict</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> <span class="token boolean">False</span>
<span class="token keyword">return</span> <span class="token builtin">all</span><span class="token punctuation">(</span><span class="token punctuation">(</span>k <span class="token keyword">in</span> data <span class="token keyword">and</span> self<span class="token punctuation">.</span>_validate_structure<span class="token punctuation">(</span>data<span class="token punctuation">[</span>k<span class="token punctuation">]</span><span class="token punctuation">,</span> structure<span class="token punctuation">[</span>k<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token keyword">for</span> k <span class="token keyword">in</span> structure<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token boolean">False</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 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-send-self-data-t" tabindex="-1"><a class="header-anchor" href="#def-send-self-data-t"><span><em><strong>def</strong></em> <code>send(self, data: T)</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>data: </li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L117" 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">send</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> data<span class="token punctuation">:</span> T<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
发送数据发送函数为同步函数没有异步的必要
Args:
data: 数据
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> self<span class="token punctuation">.</span>type_check<span class="token punctuation">:</span>
_type <span class="token operator">=</span> self<span class="token punctuation">.</span>_get_generic_type<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">if</span> _type <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span> <span class="token keyword">and</span> <span class="token punctuation">(</span><span class="token keyword">not</span> self<span class="token punctuation">.</span>_validate_structure<span class="token punctuation">(</span>data<span class="token punctuation">,</span> _type<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">raise</span> TypeError<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Data must be an instance of </span><span class="token interpolation"><span class="token punctuation">{</span>_type<span class="token punctuation">}</span></span><span class="token string">, </span><span class="token interpolation"><span class="token punctuation">{</span><span class="token builtin">type</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string"> found&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">if</span> self<span class="token punctuation">.</span>_closed<span class="token punctuation">:</span>
<span class="token keyword">raise</span> RuntimeError<span class="token punctuation">(</span><span class="token string">&#39;Cannot send to a closed channel_&#39;</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>conn_send<span class="token punctuation">.</span>send<span class="token punctuation">(</span>data<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></div></details><h4 id="def-receive-self-t" tabindex="-1"><a class="header-anchor" href="#def-receive-self-t"><span><em><strong>def</strong></em> <code>receive(self) -&gt; T</code></span></a></h4><p><strong></strong>: 线</p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L132" 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">receive</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> T<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
同步接收数据会阻塞线程
Args:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> self<span class="token punctuation">.</span>_closed<span class="token punctuation">:</span>
<span class="token keyword">raise</span> RuntimeError<span class="token punctuation">(</span><span class="token string">&#39;Cannot receive from a closed channel_&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
data <span class="token operator">=</span> self<span class="token punctuation">.</span>conn_recv<span class="token punctuation">.</span>recv<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> data
</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></div></details><h4 id="async-def-async-receive-self-t" tabindex="-1"><a class="header-anchor" href="#async-def-async-receive-self-t"><span><em><strong>async def</strong></em> <code>async_receive(self) -&gt; T</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L144" 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">async_receive</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> T<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
异步接收数据会挂起等待
&quot;&quot;&quot;</span>
<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">&#39;&#39;</span><span class="token punctuation">)</span>
loop <span class="token operator">=</span> asyncio<span class="token punctuation">.</span>get_running_loop<span class="token punctuation">(</span><span class="token punctuation">)</span>
data <span class="token operator">=</span> <span class="token keyword">await</span> loop<span class="token punctuation">.</span>run_in_executor<span class="token punctuation">(</span><span class="token boolean">None</span><span class="token punctuation">,</span> self<span class="token punctuation">.</span>receive<span class="token punctuation">)</span>
<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">&#39;&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> data
</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><h4 id="def-on-receive-self-filter-func-optional-filter-func-none-callable-callable-t-any-callable-t-any" tabindex="-1"><a class="header-anchor" href="#def-on-receive-self-filter-func-optional-filter-func-none-callable-callable-t-any-callable-t-any"><span><em><strong>def</strong></em> <code>on_receive(self, filter_func: Optional[FILTER_FUNC] = None) -&gt; Callable[[Callable[[T], Any]], Callable[[T], Any]]</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>filter_func: None</li></ul></blockquote><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L154" 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">on_receive</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> filter_func<span class="token punctuation">:</span> Optional<span class="token punctuation">[</span>FILTER_FUNC<span class="token punctuation">]</span><span class="token operator">=</span><span class="token boolean">None</span><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>Callable<span class="token punctuation">[</span><span class="token punctuation">[</span>T<span class="token punctuation">]</span><span class="token punctuation">,</span> Any<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">,</span> Callable<span class="token punctuation">[</span><span class="token punctuation">[</span>T<span class="token punctuation">]</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">&quot;&quot;&quot;
接收数据并执行函数
Args:
filter_func: 过滤函数为None则不过滤
Returns:
装饰器装饰一个函数在接收到数据后执行
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token keyword">raise</span> RuntimeError<span class="token punctuation">(</span><span class="token string">&#39;on_receive can only be used in main process&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">decorator</span><span class="token punctuation">(</span>func<span class="token punctuation">:</span> Callable<span class="token punctuation">[</span><span class="token punctuation">[</span>T<span class="token punctuation">]</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 operator">&gt;</span> Callable<span class="token punctuation">[</span><span class="token punctuation">[</span>T<span class="token punctuation">]</span><span class="token punctuation">,</span> Any<span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token keyword">global</span> _func_id
<span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">wrapper</span><span class="token punctuation">(</span>data<span class="token punctuation">:</span> T<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> Any<span class="token punctuation">:</span>
<span class="token keyword">if</span> filter_func <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> is_coroutine_callable<span class="token punctuation">(</span>filter_func<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token keyword">await</span> filter_func<span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span>
<span class="token keyword">elif</span> <span class="token keyword">not</span> filter_func<span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span>
<span class="token keyword">if</span> is_coroutine_callable<span class="token punctuation">(</span>func<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> <span class="token keyword">await</span> func<span class="token punctuation">(</span>data<span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> func<span class="token punctuation">(</span>data<span class="token punctuation">)</span>
_callback_funcs<span class="token punctuation">[</span>_func_id<span class="token punctuation">]</span> <span class="token operator">=</span> wrapper
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
self<span class="token punctuation">.</span>_on_main_receive_func_ids<span class="token punctuation">.</span>append<span class="token punctuation">(</span>_func_id<span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
self<span class="token punctuation">.</span>_on_sub_receive_func_ids<span class="token punctuation">.</span>append<span class="token punctuation">(</span>_func_id<span class="token punctuation">)</span>
_func_id <span class="token operator">+=</span> <span class="token number">1</span>
<span class="token keyword">return</span> func
<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 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><h4 id="async-def-run-on-receive-funcs-self-data-any" tabindex="-1"><a class="header-anchor" href="#async-def-run-on-receive-funcs-self-data-any"><span><em><strong>async def</strong></em> <code>_run_on_receive_funcs(self, data: Any)</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>data: </li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L192" 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_on_receive_funcs</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> data<span class="token punctuation">:</span> Any<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
运行接收函数
Args:
data: 数据
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token punctuation">[</span>asyncio<span class="token punctuation">.</span>create_task<span class="token punctuation">(</span>_callback_funcs<span class="token punctuation">[</span>func_id<span class="token punctuation">]</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">for</span> func_id <span class="token keyword">in</span> self<span class="token punctuation">.</span>_on_main_receive_func_ids<span class="token punctuation">]</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
<span class="token punctuation">[</span>asyncio<span class="token punctuation">.</span>create_task<span class="token punctuation">(</span>_callback_funcs<span class="token punctuation">[</span>func_id<span class="token punctuation">]</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">for</span> func_id <span class="token keyword">in</span> self<span class="token punctuation">.</span>_on_sub_receive_func_ids<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></div></details><h4 id="async-def-start-receive-loop-self" tabindex="-1"><a class="header-anchor" href="#async-def-start-receive-loop-self"><span><em><strong>async def</strong></em> <code>start_receive_loop(self)</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L203" 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">start_receive_loop</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
开始接收数据
会自动判断主进程和子进程需要在对应进程都调度一次
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> <span class="token builtin">len</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>_on_main_receive_func_ids<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;No on_receive function registered for </span><span class="token interpolation"><span class="token punctuation">{</span>self<span class="token punctuation">.</span>name<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">return</span>
self<span class="token punctuation">.</span>is_receive_loop_running <span class="token operator">=</span> <span class="token boolean">True</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Starting receive loop for </span><span class="token interpolation"><span class="token punctuation">{</span>self<span class="token punctuation">.</span>name<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">while</span> <span class="token keyword">not</span> self<span class="token punctuation">.</span>_closed<span class="token punctuation">:</span>
data <span class="token operator">=</span> <span class="token keyword">await</span> self<span class="token punctuation">.</span>async_receive<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>_run_on_receive_funcs<span class="token punctuation">(</span>data<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></div></details><h3 id="var-active-channel" tabindex="-1"><a class="header-anchor" href="#var-active-channel"><span>var <code>active_channel</code></span></a></h3><ul><li><p><strong></strong>: </p></li><li><p><strong></strong>: <code>Channel</code></p></li><li><p><strong></strong>: <code>Channel(name=&#39;active_channel&#39;)</code></p></li></ul><h3 id="var-publish-channel" tabindex="-1"><a class="header-anchor" href="#var-publish-channel"><span>var <code>publish_channel</code></span></a></h3><ul><li><p><strong></strong>: </p></li><li><p><strong></strong>: <code>Channel[tuple[str, dict[str, Any]]]</code></p></li><li><p><strong></strong>: <code>Channel(name=&#39;publish_channel&#39;)</code></p></li></ul><h3 id="var-channel-deliver-active-channel" tabindex="-1"><a class="header-anchor" href="#var-channel-deliver-active-channel"><span>var <code>channel_deliver_active_channel</code></span></a></h3><ul><li><p><strong></strong>: </p></li><li><p><strong></strong>: <code>Channel[Channel[Any]]</code></p></li><li><p><strong></strong>: <code>NO_DEFAULT</code></p></li></ul><h3 id="def-set-channel-name-str-channel-channel" tabindex="-1"><a class="header-anchor" href="#def-set-channel-name-str-channel-channel"><span><em><strong>def</strong></em> <code>set_channel(name: str, channel: Channel)</code></span></a></h3><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>name: </li><li>channel: </li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L250" 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">set_channel</span><span class="token punctuation">(</span>name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> channel<span class="token punctuation">:</span> <span class="token string">&#39;Channel&#39;</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
设置通道实例
Args:
name: 通道名称
channel: 通道实例
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>channel<span class="token punctuation">,</span> Channel<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">raise</span> TypeError<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;channel_ must be an instance of Channel, </span><span class="token interpolation"><span class="token punctuation">{</span><span class="token builtin">type</span><span class="token punctuation">(</span>channel<span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string"> found&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token keyword">if</span> name <span class="token keyword">in</span> _channel<span class="token punctuation">:</span>
<span class="token keyword">raise</span> ValueError<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Channel </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> already exists&#39;</span></span><span class="token punctuation">)</span>
_channel<span class="token punctuation">[</span>name<span class="token punctuation">]</span> <span class="token operator">=</span> channel
<span class="token keyword">else</span><span class="token punctuation">:</span>
channel_deliver_passive_channel<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#39;set_channel&#39;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token string">&#39;name&#39;</span><span class="token punctuation">:</span> name<span class="token punctuation">,</span> <span class="token string">&#39;channel_&#39;</span><span class="token punctuation">:</span> channel<span class="token punctuation">}</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 class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h3 id="def-set-channels-channels-dict-str-channel" tabindex="-1"><a class="header-anchor" href="#def-set-channels-channels-dict-str-channel"><span><em><strong>def</strong></em> <code>set_channels(channels: dict[str, Channel])</code></span></a></h3><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>channels: </li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L276" 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">set_channels</span><span class="token punctuation">(</span>channels<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> <span class="token string">&#39;Channel&#39;</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
设置通道实例
Args:
channels: 通道名称
&quot;&quot;&quot;</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span>name<span class="token punctuation">,</span> channel<span class="token punctuation">)</span> <span class="token keyword">in</span> channels<span class="token punctuation">.</span>items<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
set_channel<span class="token punctuation">(</span>name<span class="token punctuation">,</span> channel<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></div></details><h3 id="def-get-channel-name-str-channel" tabindex="-1"><a class="header-anchor" href="#def-get-channel-name-str-channel"><span><em><strong>def</strong></em> <code>get_channel(name: str) -&gt; Channel</code></span></a></h3><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>name: </li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L286" 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">get_channel</span><span class="token punctuation">(</span>name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token string">&#39;Channel&#39;</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取通道实例
Args:
name: 通道名称
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token keyword">return</span> _channel<span class="token punctuation">[</span>name<span class="token punctuation">]</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
recv_chan <span class="token operator">=</span> Channel<span class="token punctuation">[</span>Channel<span class="token punctuation">[</span>Any<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">(</span><span class="token string">&#39;recv_chan&#39;</span><span class="token punctuation">)</span>
channel_deliver_passive_channel<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#39;get_channel&#39;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token string">&#39;name&#39;</span><span class="token punctuation">:</span> name<span class="token punctuation">,</span> <span class="token string">&#39;recv_chan&#39;</span><span class="token punctuation">:</span> recv_chan<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> recv_chan<span class="token punctuation">.</span>receive<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></div></details><h3 id="def-get-channels-dict-str-channel" tabindex="-1"><a class="header-anchor" href="#def-get-channels-dict-str-channel"><span><em><strong>def</strong></em> <code>get_channels() -&gt; dict[str, Channel]</code></span></a></h3><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L310" 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">get_channels</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">dict</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">,</span> <span class="token string">&#39;Channel&#39;</span><span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取通道实例
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token keyword">return</span> _channel
<span class="token keyword">else</span><span class="token punctuation">:</span>
recv_chan <span class="token operator">=</span> Channel<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> Channel<span class="token punctuation">[</span>Any<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">(</span><span class="token string">&#39;recv_chan&#39;</span><span class="token punctuation">)</span>
channel_deliver_passive_channel<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#39;get_channels&#39;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token string">&#39;recv_chan&#39;</span><span class="token punctuation">:</span> recv_chan<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> recv_chan<span class="token punctuation">.</span>receive<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></div></details><p><code>@channel_deliver_passive_channel.on_receive(filter_func=lambda data: data[0] == &#39;set_channel&#39;)</code></p><h3 id="def-on-set-channel-data-tuple-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-on-set-channel-data-tuple-str-dict-str-any"><span><em><strong>def</strong></em> <code>on_set_channel(data: tuple[str, dict[str, Any]])</code></span></a></h3><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L233" 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 decorator annotation punctuation">@channel_deliver_passive_channel<span class="token punctuation">.</span>on_receive</span><span class="token punctuation">(</span>filter_func<span class="token operator">=</span><span class="token keyword">lambda</span> data<span class="token punctuation">:</span> data<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token string">&#39;set_channel&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">on_set_channel</span><span class="token punctuation">(</span>data<span class="token punctuation">:</span> <span class="token builtin">tuple</span><span class="token punctuation">[</span><span class="token builtin">str</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 punctuation">)</span><span class="token punctuation">:</span>
<span class="token punctuation">(</span>name<span class="token punctuation">,</span> channel<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token punctuation">(</span>data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&#39;name&#39;</span><span class="token punctuation">]</span><span class="token punctuation">,</span> data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&#39;channel_&#39;</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
set_channel<span class="token punctuation">(</span>name<span class="token punctuation">,</span> channel<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></div></details><p><code>@channel_deliver_passive_channel.on_receive(filter_func=lambda data: data[0] == &#39;get_channel&#39;)</code></p><h3 id="def-on-get-channel-data-tuple-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-on-get-channel-data-tuple-str-dict-str-any"><span><em><strong>def</strong></em> <code>on_get_channel(data: tuple[str, dict[str, Any]])</code></span></a></h3><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L239" 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 decorator annotation punctuation">@channel_deliver_passive_channel<span class="token punctuation">.</span>on_receive</span><span class="token punctuation">(</span>filter_func<span class="token operator">=</span><span class="token keyword">lambda</span> data<span class="token punctuation">:</span> data<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token string">&#39;get_channel&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">on_get_channel</span><span class="token punctuation">(</span>data<span class="token punctuation">:</span> <span class="token builtin">tuple</span><span class="token punctuation">[</span><span class="token builtin">str</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 punctuation">)</span><span class="token punctuation">:</span>
<span class="token punctuation">(</span>name<span class="token punctuation">,</span> recv_chan<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token punctuation">(</span>data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&#39;name&#39;</span><span class="token punctuation">]</span><span class="token punctuation">,</span> data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&#39;recv_chan&#39;</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
recv_chan<span class="token punctuation">.</span>send<span class="token punctuation">(</span>get_channel<span class="token punctuation">(</span>name<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></div></details><p><code>@channel_deliver_passive_channel.on_receive(filter_func=lambda data: data[0] == &#39;get_channels&#39;)</code></p><h3 id="def-on-get-channels-data-tuple-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-on-get-channels-data-tuple-str-dict-str-any"><span><em><strong>def</strong></em> <code>on_get_channels(data: tuple[str, dict[str, Any]])</code></span></a></h3><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L245" 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 decorator annotation punctuation">@channel_deliver_passive_channel<span class="token punctuation">.</span>on_receive</span><span class="token punctuation">(</span>filter_func<span class="token operator">=</span><span class="token keyword">lambda</span> data<span class="token punctuation">:</span> data<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token string">&#39;get_channels&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">on_get_channels</span><span class="token punctuation">(</span>data<span class="token punctuation">:</span> <span class="token builtin">tuple</span><span class="token punctuation">[</span><span class="token builtin">str</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 punctuation">)</span><span class="token punctuation">:</span>
recv_chan <span class="token operator">=</span> data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&#39;recv_chan&#39;</span><span class="token punctuation">]</span>
recv_chan<span class="token punctuation">.</span>send<span class="token punctuation">(</span>get_channels<span class="token punctuation">(</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></div></details>`,78),o=[p];function c(l,i){return s(),a("div",null,o)}const r=n(e,[["render",c],["__file","channel.html.vue"]]),d=JSON.parse('{"path":"/dev/api/comm/channel.html","title":"liteyuki.comm.channel","lang":"zh-CN","frontmatter":{"title":"liteyuki.comm.channel","lastUpdated":false,"description":"liteyuki.comm.channel : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/26 11:21 @Author : snowykami @Email : snowykami@outlook.com @File : channe...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/comm/channel.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/comm/channel.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":"liteyuki.comm.channel"}],["meta",{"property":"og:description","content":"liteyuki.comm.channel : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/26 11:21 @Author : snowykami @Email : snowykami@outlook.com @File : channe..."}],["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.comm.channel\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class Channel(Generic[T])","slug":"class-channel-generic-t","link":"#class-channel-generic-t","children":[]},{"level":3,"title":"var active_channel","slug":"var-active-channel","link":"#var-active-channel","children":[]},{"level":3,"title":"var publish_channel","slug":"var-publish-channel","link":"#var-publish-channel","children":[]},{"level":3,"title":"var channel_deliver_active_channel","slug":"var-channel-deliver-active-channel","link":"#var-channel-deliver-active-channel","children":[]},{"level":3,"title":"def set_channel(name: str, channel: Channel)","slug":"def-set-channel-name-str-channel-channel","link":"#def-set-channel-name-str-channel-channel","children":[]},{"level":3,"title":"def set_channels(channels: dict[str, Channel])","slug":"def-set-channels-channels-dict-str-channel","link":"#def-set-channels-channels-dict-str-channel","children":[]},{"level":3,"title":"def get_channel(name: str) -> Channel","slug":"def-get-channel-name-str-channel","link":"#def-get-channel-name-str-channel","children":[]},{"level":3,"title":"def get_channels() -> dict[str, Channel]","slug":"def-get-channels-dict-str-channel","link":"#def-get-channels-dict-str-channel","children":[]},{"level":3,"title":"def on_set_channel(data: tuple[str, dict[str, Any]])","slug":"def-on-set-channel-data-tuple-str-dict-str-any","link":"#def-on-set-channel-data-tuple-str-dict-str-any","children":[]},{"level":3,"title":"def on_get_channel(data: tuple[str, dict[str, Any]])","slug":"def-on-get-channel-data-tuple-str-dict-str-any","link":"#def-on-get-channel-data-tuple-str-dict-str-any","children":[]},{"level":3,"title":"def on_get_channels(data: tuple[str, dict[str, Any]])","slug":"def-on-get-channels-data-tuple-str-dict-str-any","link":"#def-on-get-channels-data-tuple-str-dict-str-any","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":7}]},"readingTime":{"minutes":6.13,"words":1839},"filePathRelative":"dev/api/comm/channel.md","localizedDate":"2024819","autoDesc":true}');export{r as comp,d as data};

View File

@ -0,0 +1,212 @@
import{_ as n,o as s,c as a,e as t}from"./app-BvUYPzLF.js";const e={},p=t(`<h1 id="liteyuki-comm-channel" tabindex="-1"><a class="header-anchor" href="#liteyuki-comm-channel"><span>liteyuki.comm.channel</span></a></h1><p><strong>Description</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/7/26 下午11:21 @Author : snowykami @Email : snowykami@outlook.com @File : channel_.py @Software: PyCharm</p><p>本模块定义了一个通用的通道类,用于进程间通信</p><h3 id="class-channel-generic-t" tabindex="-1"><a class="header-anchor" href="#class-channel-generic-t"><span><em><strong>class</strong></em> <code>Channel(Generic[T])</code></span></a></h3><h4 id="def-init-self-name-str-type-check-optional-bool-none" tabindex="-1"><a class="header-anchor" href="#def-init-self-name-str-type-check-optional-bool-none"><span><em><strong>def</strong></em> <code>__init__(self, name: str, type_check: Optional[bool] = None)</code></span></a></h4><p><strong>Description</strong>: 初始化通道</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>name: 通道ID</li><li>type_check: 是否开启类型检查, 若为空,则传入泛型默认开启,否则默认关闭</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L41" target="_blank">View on 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> name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> type_check<span class="token punctuation">:</span> Optional<span class="token punctuation">[</span><span class="token builtin">bool</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>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
初始化通道
Args:
name: 通道ID
type_check: 是否开启类型检查, 若为空则传入泛型默认开启否则默认关闭
&quot;&quot;&quot;</span>
<span class="token punctuation">(</span>self<span class="token punctuation">.</span>conn_send<span class="token punctuation">,</span> self<span class="token punctuation">.</span>conn_recv<span class="token punctuation">)</span> <span class="token operator">=</span> Pipe<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_conn_send_inner<span class="token punctuation">,</span> self<span class="token punctuation">.</span>_conn_recv_inner<span class="token punctuation">)</span> <span class="token operator">=</span> Pipe<span class="token punctuation">(</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>_closed <span class="token operator">=</span> <span class="token boolean">False</span>
self<span class="token punctuation">.</span>_on_main_receive_func_ids<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span><span class="token builtin">int</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>_on_sub_receive_func_ids<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span><span class="token builtin">int</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>name<span class="token punctuation">:</span> <span class="token builtin">str</span> <span class="token operator">=</span> name
self<span class="token punctuation">.</span>is_receive_loop_running <span class="token operator">=</span> <span class="token boolean">False</span>
<span class="token keyword">if</span> type_check <span class="token keyword">is</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
type_check <span class="token operator">=</span> self<span class="token punctuation">.</span>_get_generic_type<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span>
<span class="token keyword">elif</span> type_check<span class="token punctuation">:</span>
<span class="token keyword">if</span> self<span class="token punctuation">.</span>_get_generic_type<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">is</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
<span class="token keyword">raise</span> TypeError<span class="token punctuation">(</span><span class="token string">&#39;Type hint is required for enforcing type check.&#39;</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>type_check <span class="token operator">=</span> type_check
<span class="token keyword">if</span> name <span class="token keyword">in</span> _channel<span class="token punctuation">:</span>
<span class="token keyword">raise</span> ValueError<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Channel </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> already exists&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token keyword">if</span> name <span class="token keyword">in</span> _channel<span class="token punctuation">:</span>
<span class="token keyword">raise</span> ValueError<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Channel </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> already exists&#39;</span></span><span class="token punctuation">)</span>
_channel<span class="token punctuation">[</span>name<span class="token punctuation">]</span> <span class="token operator">=</span> self
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Channel </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> initialized in main process&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Channel </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> initialized in sub process, should manually set in main process&#39;</span></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 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><h4 id="def-get-generic-type-self-optional-type" tabindex="-1"><a class="header-anchor" href="#def-get-generic-type-self-optional-type"><span><em><strong>def</strong></em> <code>_get_generic_type(self) -&gt; Optional[type]</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Return</strong>: Optional[type]: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L77" target="_blank">View on 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">_get_generic_type</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> Optional<span class="token punctuation">[</span><span class="token builtin">type</span><span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取通道传递泛型类型
Returns:
Optional[type]: 泛型类型
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> <span class="token builtin">hasattr</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> <span class="token string">&#39;__orig_class__&#39;</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> get_args<span class="token punctuation">(</span>self<span class="token punctuation">.</span>__orig_class__<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
<span class="token keyword">return</span> <span class="token boolean">None</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></div></details><h4 id="def-validate-structure-self-data-any-structure-type-bool" tabindex="-1"><a class="header-anchor" href="#def-validate-structure-self-data-any-structure-type-bool"><span><em><strong>def</strong></em> <code>_validate_structure(self, data: Any, structure: type) -&gt; bool</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>data: </li><li>structure: </li></ul></blockquote><p><strong>Return</strong>: bool: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L88" target="_blank">View on 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">_validate_structure</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> data<span class="token punctuation">:</span> Any<span class="token punctuation">,</span> structure<span class="token punctuation">:</span> <span class="token builtin">type</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">bool</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
验证数据结构
Args:
data: 数据
structure: 结构
Returns:
bool: 是否通过验证
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>structure<span class="token punctuation">,</span> <span class="token builtin">type</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> structure<span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>structure<span class="token punctuation">,</span> <span class="token builtin">tuple</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> <span class="token builtin">tuple</span><span class="token punctuation">)</span> <span class="token keyword">or</span> <span class="token builtin">len</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>structure<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> <span class="token boolean">False</span>
<span class="token keyword">return</span> <span class="token builtin">all</span><span class="token punctuation">(</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>_validate_structure<span class="token punctuation">(</span>d<span class="token punctuation">,</span> s<span class="token punctuation">)</span> <span class="token keyword">for</span> <span class="token punctuation">(</span>d<span class="token punctuation">,</span> s<span class="token punctuation">)</span> <span class="token keyword">in</span> <span class="token builtin">zip</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> structure<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>structure<span class="token punctuation">,</span> <span class="token builtin">list</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> <span class="token builtin">list</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> <span class="token boolean">False</span>
<span class="token keyword">return</span> <span class="token builtin">all</span><span class="token punctuation">(</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>_validate_structure<span class="token punctuation">(</span>d<span class="token punctuation">,</span> structure<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token keyword">for</span> d <span class="token keyword">in</span> data<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>structure<span class="token punctuation">,</span> <span class="token builtin">dict</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> <span class="token builtin">dict</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> <span class="token boolean">False</span>
<span class="token keyword">return</span> <span class="token builtin">all</span><span class="token punctuation">(</span><span class="token punctuation">(</span>k <span class="token keyword">in</span> data <span class="token keyword">and</span> self<span class="token punctuation">.</span>_validate_structure<span class="token punctuation">(</span>data<span class="token punctuation">[</span>k<span class="token punctuation">]</span><span class="token punctuation">,</span> structure<span class="token punctuation">[</span>k<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token keyword">for</span> k <span class="token keyword">in</span> structure<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token boolean">False</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 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-send-self-data-t" tabindex="-1"><a class="header-anchor" href="#def-send-self-data-t"><span><em><strong>def</strong></em> <code>send(self, data: T)</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>data: </li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L117" target="_blank">View on 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">send</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> data<span class="token punctuation">:</span> T<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
发送数据发送函数为同步函数没有异步的必要
Args:
data: 数据
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> self<span class="token punctuation">.</span>type_check<span class="token punctuation">:</span>
_type <span class="token operator">=</span> self<span class="token punctuation">.</span>_get_generic_type<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">if</span> _type <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span> <span class="token keyword">and</span> <span class="token punctuation">(</span><span class="token keyword">not</span> self<span class="token punctuation">.</span>_validate_structure<span class="token punctuation">(</span>data<span class="token punctuation">,</span> _type<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">raise</span> TypeError<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Data must be an instance of </span><span class="token interpolation"><span class="token punctuation">{</span>_type<span class="token punctuation">}</span></span><span class="token string">, </span><span class="token interpolation"><span class="token punctuation">{</span><span class="token builtin">type</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string"> found&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">if</span> self<span class="token punctuation">.</span>_closed<span class="token punctuation">:</span>
<span class="token keyword">raise</span> RuntimeError<span class="token punctuation">(</span><span class="token string">&#39;Cannot send to a closed channel_&#39;</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>conn_send<span class="token punctuation">.</span>send<span class="token punctuation">(</span>data<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></div></details><h4 id="def-receive-self-t" tabindex="-1"><a class="header-anchor" href="#def-receive-self-t"><span><em><strong>def</strong></em> <code>receive(self) -&gt; T</code></span></a></h4><p><strong>Description</strong>: 线</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L132" target="_blank">View on 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">receive</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> T<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
同步接收数据会阻塞线程
Args:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> self<span class="token punctuation">.</span>_closed<span class="token punctuation">:</span>
<span class="token keyword">raise</span> RuntimeError<span class="token punctuation">(</span><span class="token string">&#39;Cannot receive from a closed channel_&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
data <span class="token operator">=</span> self<span class="token punctuation">.</span>conn_recv<span class="token punctuation">.</span>recv<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> data
</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></div></details><h4 id="async-def-async-receive-self-t" tabindex="-1"><a class="header-anchor" href="#async-def-async-receive-self-t"><span><em><strong>async def</strong></em> <code>async_receive(self) -&gt; T</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L144" target="_blank">View on 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">async_receive</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> T<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
异步接收数据会挂起等待
&quot;&quot;&quot;</span>
<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">&#39;&#39;</span><span class="token punctuation">)</span>
loop <span class="token operator">=</span> asyncio<span class="token punctuation">.</span>get_running_loop<span class="token punctuation">(</span><span class="token punctuation">)</span>
data <span class="token operator">=</span> <span class="token keyword">await</span> loop<span class="token punctuation">.</span>run_in_executor<span class="token punctuation">(</span><span class="token boolean">None</span><span class="token punctuation">,</span> self<span class="token punctuation">.</span>receive<span class="token punctuation">)</span>
<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">&#39;&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> data
</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><h4 id="def-on-receive-self-filter-func-optional-filter-func-none-callable-callable-t-any-callable-t-any" tabindex="-1"><a class="header-anchor" href="#def-on-receive-self-filter-func-optional-filter-func-none-callable-callable-t-any-callable-t-any"><span><em><strong>def</strong></em> <code>on_receive(self, filter_func: Optional[FILTER_FUNC] = None) -&gt; Callable[[Callable[[T], Any]], Callable[[T], Any]]</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>filter_func: None</li></ul></blockquote><p><strong>Return</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L154" target="_blank">View on 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">on_receive</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> filter_func<span class="token punctuation">:</span> Optional<span class="token punctuation">[</span>FILTER_FUNC<span class="token punctuation">]</span><span class="token operator">=</span><span class="token boolean">None</span><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>Callable<span class="token punctuation">[</span><span class="token punctuation">[</span>T<span class="token punctuation">]</span><span class="token punctuation">,</span> Any<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">,</span> Callable<span class="token punctuation">[</span><span class="token punctuation">[</span>T<span class="token punctuation">]</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">&quot;&quot;&quot;
接收数据并执行函数
Args:
filter_func: 过滤函数为None则不过滤
Returns:
装饰器装饰一个函数在接收到数据后执行
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token keyword">raise</span> RuntimeError<span class="token punctuation">(</span><span class="token string">&#39;on_receive can only be used in main process&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">decorator</span><span class="token punctuation">(</span>func<span class="token punctuation">:</span> Callable<span class="token punctuation">[</span><span class="token punctuation">[</span>T<span class="token punctuation">]</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 operator">&gt;</span> Callable<span class="token punctuation">[</span><span class="token punctuation">[</span>T<span class="token punctuation">]</span><span class="token punctuation">,</span> Any<span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token keyword">global</span> _func_id
<span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">wrapper</span><span class="token punctuation">(</span>data<span class="token punctuation">:</span> T<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> Any<span class="token punctuation">:</span>
<span class="token keyword">if</span> filter_func <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> is_coroutine_callable<span class="token punctuation">(</span>filter_func<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token keyword">await</span> filter_func<span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span>
<span class="token keyword">elif</span> <span class="token keyword">not</span> filter_func<span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span>
<span class="token keyword">if</span> is_coroutine_callable<span class="token punctuation">(</span>func<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> <span class="token keyword">await</span> func<span class="token punctuation">(</span>data<span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> func<span class="token punctuation">(</span>data<span class="token punctuation">)</span>
_callback_funcs<span class="token punctuation">[</span>_func_id<span class="token punctuation">]</span> <span class="token operator">=</span> wrapper
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
self<span class="token punctuation">.</span>_on_main_receive_func_ids<span class="token punctuation">.</span>append<span class="token punctuation">(</span>_func_id<span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
self<span class="token punctuation">.</span>_on_sub_receive_func_ids<span class="token punctuation">.</span>append<span class="token punctuation">(</span>_func_id<span class="token punctuation">)</span>
_func_id <span class="token operator">+=</span> <span class="token number">1</span>
<span class="token keyword">return</span> func
<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 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><h4 id="async-def-run-on-receive-funcs-self-data-any" tabindex="-1"><a class="header-anchor" href="#async-def-run-on-receive-funcs-self-data-any"><span><em><strong>async def</strong></em> <code>_run_on_receive_funcs(self, data: Any)</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>data: </li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L192" target="_blank">View on 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_on_receive_funcs</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> data<span class="token punctuation">:</span> Any<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
运行接收函数
Args:
data: 数据
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token punctuation">[</span>asyncio<span class="token punctuation">.</span>create_task<span class="token punctuation">(</span>_callback_funcs<span class="token punctuation">[</span>func_id<span class="token punctuation">]</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">for</span> func_id <span class="token keyword">in</span> self<span class="token punctuation">.</span>_on_main_receive_func_ids<span class="token punctuation">]</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
<span class="token punctuation">[</span>asyncio<span class="token punctuation">.</span>create_task<span class="token punctuation">(</span>_callback_funcs<span class="token punctuation">[</span>func_id<span class="token punctuation">]</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">for</span> func_id <span class="token keyword">in</span> self<span class="token punctuation">.</span>_on_sub_receive_func_ids<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></div></details><h4 id="async-def-start-receive-loop-self" tabindex="-1"><a class="header-anchor" href="#async-def-start-receive-loop-self"><span><em><strong>async def</strong></em> <code>start_receive_loop(self)</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L203" target="_blank">View on 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">start_receive_loop</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
开始接收数据
会自动判断主进程和子进程需要在对应进程都调度一次
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> <span class="token builtin">len</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>_on_main_receive_func_ids<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;No on_receive function registered for </span><span class="token interpolation"><span class="token punctuation">{</span>self<span class="token punctuation">.</span>name<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">return</span>
self<span class="token punctuation">.</span>is_receive_loop_running <span class="token operator">=</span> <span class="token boolean">True</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Starting receive loop for </span><span class="token interpolation"><span class="token punctuation">{</span>self<span class="token punctuation">.</span>name<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">while</span> <span class="token keyword">not</span> self<span class="token punctuation">.</span>_closed<span class="token punctuation">:</span>
data <span class="token operator">=</span> <span class="token keyword">await</span> self<span class="token punctuation">.</span>async_receive<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>_run_on_receive_funcs<span class="token punctuation">(</span>data<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></div></details><h3 id="var-active-channel" tabindex="-1"><a class="header-anchor" href="#var-active-channel"><span>var <code>active_channel</code></span></a></h3><ul><li><p><strong>Description</strong>: </p></li><li><p><strong>Type</strong>: <code>Channel</code></p></li><li><p><strong>Default</strong>: <code>Channel(name=&#39;active_channel&#39;)</code></p></li></ul><h3 id="var-publish-channel" tabindex="-1"><a class="header-anchor" href="#var-publish-channel"><span>var <code>publish_channel</code></span></a></h3><ul><li><p><strong>Description</strong>: </p></li><li><p><strong>Type</strong>: <code>Channel[tuple[str, dict[str, Any]]]</code></p></li><li><p><strong>Default</strong>: <code>Channel(name=&#39;publish_channel&#39;)</code></p></li></ul><h3 id="var-channel-deliver-active-channel" tabindex="-1"><a class="header-anchor" href="#var-channel-deliver-active-channel"><span>var <code>channel_deliver_active_channel</code></span></a></h3><ul><li><p><strong>Description</strong>: </p></li><li><p><strong>Type</strong>: <code>Channel[Channel[Any]]</code></p></li><li><p><strong>Default</strong>: <code>NO_DEFAULT</code></p></li></ul><h3 id="def-set-channel-name-str-channel-channel" tabindex="-1"><a class="header-anchor" href="#def-set-channel-name-str-channel-channel"><span><em><strong>def</strong></em> <code>set_channel(name: str, channel: Channel)</code></span></a></h3><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>name: </li><li>channel: </li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L250" target="_blank">View on 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">set_channel</span><span class="token punctuation">(</span>name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> channel<span class="token punctuation">:</span> <span class="token string">&#39;Channel&#39;</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
设置通道实例
Args:
name: 通道名称
channel: 通道实例
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>channel<span class="token punctuation">,</span> Channel<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">raise</span> TypeError<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;channel_ must be an instance of Channel, </span><span class="token interpolation"><span class="token punctuation">{</span><span class="token builtin">type</span><span class="token punctuation">(</span>channel<span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string"> found&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token keyword">if</span> name <span class="token keyword">in</span> _channel<span class="token punctuation">:</span>
<span class="token keyword">raise</span> ValueError<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Channel </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> already exists&#39;</span></span><span class="token punctuation">)</span>
_channel<span class="token punctuation">[</span>name<span class="token punctuation">]</span> <span class="token operator">=</span> channel
<span class="token keyword">else</span><span class="token punctuation">:</span>
channel_deliver_passive_channel<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#39;set_channel&#39;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token string">&#39;name&#39;</span><span class="token punctuation">:</span> name<span class="token punctuation">,</span> <span class="token string">&#39;channel_&#39;</span><span class="token punctuation">:</span> channel<span class="token punctuation">}</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 class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h3 id="def-set-channels-channels-dict-str-channel" tabindex="-1"><a class="header-anchor" href="#def-set-channels-channels-dict-str-channel"><span><em><strong>def</strong></em> <code>set_channels(channels: dict[str, Channel])</code></span></a></h3><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>channels: </li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L276" target="_blank">View on 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">set_channels</span><span class="token punctuation">(</span>channels<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> <span class="token string">&#39;Channel&#39;</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
设置通道实例
Args:
channels: 通道名称
&quot;&quot;&quot;</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span>name<span class="token punctuation">,</span> channel<span class="token punctuation">)</span> <span class="token keyword">in</span> channels<span class="token punctuation">.</span>items<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
set_channel<span class="token punctuation">(</span>name<span class="token punctuation">,</span> channel<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></div></details><h3 id="def-get-channel-name-str-channel" tabindex="-1"><a class="header-anchor" href="#def-get-channel-name-str-channel"><span><em><strong>def</strong></em> <code>get_channel(name: str) -&gt; Channel</code></span></a></h3><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>name: </li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L286" target="_blank">View on 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">get_channel</span><span class="token punctuation">(</span>name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token string">&#39;Channel&#39;</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取通道实例
Args:
name: 通道名称
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token keyword">return</span> _channel<span class="token punctuation">[</span>name<span class="token punctuation">]</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
recv_chan <span class="token operator">=</span> Channel<span class="token punctuation">[</span>Channel<span class="token punctuation">[</span>Any<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">(</span><span class="token string">&#39;recv_chan&#39;</span><span class="token punctuation">)</span>
channel_deliver_passive_channel<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#39;get_channel&#39;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token string">&#39;name&#39;</span><span class="token punctuation">:</span> name<span class="token punctuation">,</span> <span class="token string">&#39;recv_chan&#39;</span><span class="token punctuation">:</span> recv_chan<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> recv_chan<span class="token punctuation">.</span>receive<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></div></details><h3 id="def-get-channels-dict-str-channel" tabindex="-1"><a class="header-anchor" href="#def-get-channels-dict-str-channel"><span><em><strong>def</strong></em> <code>get_channels() -&gt; dict[str, Channel]</code></span></a></h3><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L310" target="_blank">View on 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">get_channels</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">dict</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">,</span> <span class="token string">&#39;Channel&#39;</span><span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取通道实例
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token keyword">return</span> _channel
<span class="token keyword">else</span><span class="token punctuation">:</span>
recv_chan <span class="token operator">=</span> Channel<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> Channel<span class="token punctuation">[</span>Any<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">(</span><span class="token string">&#39;recv_chan&#39;</span><span class="token punctuation">)</span>
channel_deliver_passive_channel<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#39;get_channels&#39;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token string">&#39;recv_chan&#39;</span><span class="token punctuation">:</span> recv_chan<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> recv_chan<span class="token punctuation">.</span>receive<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></div></details><p><code>@channel_deliver_passive_channel.on_receive(filter_func=lambda data: data[0] == &#39;set_channel&#39;)</code></p><h3 id="def-on-set-channel-data-tuple-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-on-set-channel-data-tuple-str-dict-str-any"><span><em><strong>def</strong></em> <code>on_set_channel(data: tuple[str, dict[str, Any]])</code></span></a></h3><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L233" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token decorator annotation punctuation">@channel_deliver_passive_channel<span class="token punctuation">.</span>on_receive</span><span class="token punctuation">(</span>filter_func<span class="token operator">=</span><span class="token keyword">lambda</span> data<span class="token punctuation">:</span> data<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token string">&#39;set_channel&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">on_set_channel</span><span class="token punctuation">(</span>data<span class="token punctuation">:</span> <span class="token builtin">tuple</span><span class="token punctuation">[</span><span class="token builtin">str</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 punctuation">)</span><span class="token punctuation">:</span>
<span class="token punctuation">(</span>name<span class="token punctuation">,</span> channel<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token punctuation">(</span>data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&#39;name&#39;</span><span class="token punctuation">]</span><span class="token punctuation">,</span> data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&#39;channel_&#39;</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
set_channel<span class="token punctuation">(</span>name<span class="token punctuation">,</span> channel<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></div></details><p><code>@channel_deliver_passive_channel.on_receive(filter_func=lambda data: data[0] == &#39;get_channel&#39;)</code></p><h3 id="def-on-get-channel-data-tuple-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-on-get-channel-data-tuple-str-dict-str-any"><span><em><strong>def</strong></em> <code>on_get_channel(data: tuple[str, dict[str, Any]])</code></span></a></h3><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L239" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token decorator annotation punctuation">@channel_deliver_passive_channel<span class="token punctuation">.</span>on_receive</span><span class="token punctuation">(</span>filter_func<span class="token operator">=</span><span class="token keyword">lambda</span> data<span class="token punctuation">:</span> data<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token string">&#39;get_channel&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">on_get_channel</span><span class="token punctuation">(</span>data<span class="token punctuation">:</span> <span class="token builtin">tuple</span><span class="token punctuation">[</span><span class="token builtin">str</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 punctuation">)</span><span class="token punctuation">:</span>
<span class="token punctuation">(</span>name<span class="token punctuation">,</span> recv_chan<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token punctuation">(</span>data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&#39;name&#39;</span><span class="token punctuation">]</span><span class="token punctuation">,</span> data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&#39;recv_chan&#39;</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
recv_chan<span class="token punctuation">.</span>send<span class="token punctuation">(</span>get_channel<span class="token punctuation">(</span>name<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></div></details><p><code>@channel_deliver_passive_channel.on_receive(filter_func=lambda data: data[0] == &#39;get_channels&#39;)</code></p><h3 id="def-on-get-channels-data-tuple-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-on-get-channels-data-tuple-str-dict-str-any"><span><em><strong>def</strong></em> <code>on_get_channels(data: tuple[str, dict[str, Any]])</code></span></a></h3><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/channel.py#L245" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token decorator annotation punctuation">@channel_deliver_passive_channel<span class="token punctuation">.</span>on_receive</span><span class="token punctuation">(</span>filter_func<span class="token operator">=</span><span class="token keyword">lambda</span> data<span class="token punctuation">:</span> data<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token string">&#39;get_channels&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">on_get_channels</span><span class="token punctuation">(</span>data<span class="token punctuation">:</span> <span class="token builtin">tuple</span><span class="token punctuation">[</span><span class="token builtin">str</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 punctuation">)</span><span class="token punctuation">:</span>
recv_chan <span class="token operator">=</span> data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&#39;recv_chan&#39;</span><span class="token punctuation">]</span>
recv_chan<span class="token punctuation">.</span>send<span class="token punctuation">(</span>get_channels<span class="token punctuation">(</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></div></details>`,78),o=[p];function c(l,i){return s(),a("div",null,o)}const r=n(e,[["render",c],["__file","channel.html.vue"]]),d=JSON.parse('{"path":"/en/dev/api/comm/channel.html","title":"liteyuki.comm.channel","lang":"en-US","frontmatter":{"title":"liteyuki.comm.channel","lastUpdated":false,"description":"liteyuki.comm.channel Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/26 11:21 @Author : snowykami @Email : snowykami@outlook.com @File...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/comm/channel.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/comm/channel.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.comm.channel"}],["meta",{"property":"og:description","content":"liteyuki.comm.channel Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/26 11:21 @Author : snowykami @Email : snowykami@outlook.com @File..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.comm.channel\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class Channel(Generic[T])","slug":"class-channel-generic-t","link":"#class-channel-generic-t","children":[]},{"level":3,"title":"var active_channel","slug":"var-active-channel","link":"#var-active-channel","children":[]},{"level":3,"title":"var publish_channel","slug":"var-publish-channel","link":"#var-publish-channel","children":[]},{"level":3,"title":"var channel_deliver_active_channel","slug":"var-channel-deliver-active-channel","link":"#var-channel-deliver-active-channel","children":[]},{"level":3,"title":"def set_channel(name: str, channel: Channel)","slug":"def-set-channel-name-str-channel-channel","link":"#def-set-channel-name-str-channel-channel","children":[]},{"level":3,"title":"def set_channels(channels: dict[str, Channel])","slug":"def-set-channels-channels-dict-str-channel","link":"#def-set-channels-channels-dict-str-channel","children":[]},{"level":3,"title":"def get_channel(name: str) -> Channel","slug":"def-get-channel-name-str-channel","link":"#def-get-channel-name-str-channel","children":[]},{"level":3,"title":"def get_channels() -> dict[str, Channel]","slug":"def-get-channels-dict-str-channel","link":"#def-get-channels-dict-str-channel","children":[]},{"level":3,"title":"def on_set_channel(data: tuple[str, dict[str, Any]])","slug":"def-on-set-channel-data-tuple-str-dict-str-any","link":"#def-on-set-channel-data-tuple-str-dict-str-any","children":[]},{"level":3,"title":"def on_get_channel(data: tuple[str, dict[str, Any]])","slug":"def-on-get-channel-data-tuple-str-dict-str-any","link":"#def-on-get-channel-data-tuple-str-dict-str-any","children":[]},{"level":3,"title":"def on_get_channels(data: tuple[str, dict[str, Any]])","slug":"def-on-get-channels-data-tuple-str-dict-str-any","link":"#def-on-get-channels-data-tuple-str-dict-str-any","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":5.85,"words":1754},"filePathRelative":"en/dev/api/comm/channel.md","localizedDate":"August 21, 2024","autoDesc":true}');export{r as comp,d as data};

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,84 @@
import{_ as s,o as a,c as t,e as n,b as o}from"./app-BvUYPzLF.js";const e={},p=n('<h1 id="liteyuki-config" tabindex="-1"><a class="header-anchor" href="#liteyuki-config"><span>liteyuki.config</span></a></h1><p><strong>说明</strong>: 该模块用于常用配置文件的加载 多配置文件编写原则: 1.尽量不要冲突: 一个键不要多次出现 2.分工明确: 每个配置文件给一个或一类服务提供配置 3.扁平化编写: 配置文件尽量扁平化,不要出现过多的嵌套 4.注意冲突时的优先级: 项目目录下的配置文件优先级高于config目录下的配置文件 5.请不要将需要动态加载的内容写入配置文件,你应该使用其他储存方式</p><h3 id="def-flat-config-config-dict-str-any-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-flat-config-config-dict-str-any-dict-str-any"><span><em><strong>def</strong></em> <code>flat_config(config: dict[str, Any]) -&gt; dict[str, Any]</code></span></a></h3><p><strong>说明</strong>: 扁平化配置文件</p>',4),i=o("p",{"a.b.c:1":""},"{a:{b:{c:1}}} ->",-1),l=n(`<p><strong>参数</strong>:</p><blockquote><ul><li>config: 配置项目</li></ul></blockquote><p><strong>返回</strong>: 扁平化后的配置文件,但也包含原有的键值对</p><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L24" 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">flat_config</span><span class="token punctuation">(</span>config<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 operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
扁平化配置文件
{a:{b:{c:1}}} -&gt; {&quot;a.b.c&quot;: 1}
Args:
config: 配置项目
Returns:
扁平化后的配置文件但也包含原有的键值对
&quot;&quot;&quot;</span>
new_config <span class="token operator">=</span> copy<span class="token punctuation">.</span>deepcopy<span class="token punctuation">(</span>config<span class="token punctuation">)</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span>key<span class="token punctuation">,</span> value<span class="token punctuation">)</span> <span class="token keyword">in</span> config<span class="token punctuation">.</span>items<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>value<span class="token punctuation">,</span> <span class="token builtin">dict</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span>k<span class="token punctuation">,</span> v<span class="token punctuation">)</span> <span class="token keyword">in</span> flat_config<span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">.</span>items<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
new_config<span class="token punctuation">[</span><span class="token string-interpolation"><span class="token string">f&#39;</span><span class="token interpolation"><span class="token punctuation">{</span>key<span class="token punctuation">}</span></span><span class="token string">.</span><span class="token interpolation"><span class="token punctuation">{</span>k<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> v
<span class="token keyword">return</span> new_config
</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></div></details><h3 id="def-load-from-yaml-file-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-load-from-yaml-file-str-dict-str-any"><span><em><strong>def</strong></em> <code>load_from_yaml(file_: str) -&gt; dict[str, Any]</code></span></a></h3><p><strong></strong>: Load config from yaml file</p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L43" 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">load_from_yaml</span><span class="token punctuation">(</span>file_<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
Load config from yaml file
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Loading YAML config from </span><span class="token interpolation"><span class="token punctuation">{</span>file_<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
config <span class="token operator">=</span> yaml<span class="token punctuation">.</span>safe_load<span class="token punctuation">(</span><span class="token builtin">open</span><span class="token punctuation">(</span>file_<span class="token punctuation">,</span> <span class="token string">&#39;r&#39;</span><span class="token punctuation">,</span> encoding<span class="token operator">=</span><span class="token string">&#39;utf-8&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> flat_config<span class="token punctuation">(</span>config <span class="token keyword">if</span> config <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span> <span class="token keyword">else</span> <span class="token punctuation">{</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></div></details><h3 id="def-load-from-json-file-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-load-from-json-file-str-dict-str-any"><span><em><strong>def</strong></em> <code>load_from_json(file_: str) -&gt; dict[str, Any]</code></span></a></h3><p><strong></strong>: Load config from json file</p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L53" 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">load_from_json</span><span class="token punctuation">(</span>file_<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
Load config from json file
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Loading JSON config from </span><span class="token interpolation"><span class="token punctuation">{</span>file_<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
config <span class="token operator">=</span> json<span class="token punctuation">.</span>load<span class="token punctuation">(</span><span class="token builtin">open</span><span class="token punctuation">(</span>file_<span class="token punctuation">,</span> <span class="token string">&#39;r&#39;</span><span class="token punctuation">,</span> encoding<span class="token operator">=</span><span class="token string">&#39;utf-8&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> flat_config<span class="token punctuation">(</span>config <span class="token keyword">if</span> config <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span> <span class="token keyword">else</span> <span class="token punctuation">{</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></div></details><h3 id="def-load-from-toml-file-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-load-from-toml-file-str-dict-str-any"><span><em><strong>def</strong></em> <code>load_from_toml(file_: str) -&gt; dict[str, Any]</code></span></a></h3><p><strong></strong>: Load config from toml file</p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L62" 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">load_from_toml</span><span class="token punctuation">(</span>file_<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
Load config from toml file
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Loading TOML config from </span><span class="token interpolation"><span class="token punctuation">{</span>file_<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
config <span class="token operator">=</span> toml<span class="token punctuation">.</span>load<span class="token punctuation">(</span><span class="token builtin">open</span><span class="token punctuation">(</span>file_<span class="token punctuation">,</span> <span class="token string">&#39;r&#39;</span><span class="token punctuation">,</span> encoding<span class="token operator">=</span><span class="token string">&#39;utf-8&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> flat_config<span class="token punctuation">(</span>config <span class="token keyword">if</span> config <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span> <span class="token keyword">else</span> <span class="token punctuation">{</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></div></details><h3 id="def-load-from-files-files-str-no-warning-bool-false-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-load-from-files-files-str-no-warning-bool-false-dict-str-any"><span><em><strong>def</strong></em> <code>load_from_files(*files: str, *, no_warning: bool = False) -&gt; dict[str, Any]</code></span></a></h3><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L71" 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">load_from_files</span><span class="token punctuation">(</span><span class="token operator">*</span>files<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> no_warning<span class="token punctuation">:</span> <span class="token builtin">bool</span><span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
从指定文件加载配置项会自动识别文件格式
默认执行扁平化选项
&quot;&quot;&quot;</span>
config <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token keyword">for</span> <span class="token builtin">file</span> <span class="token keyword">in</span> files<span class="token punctuation">:</span>
<span class="token keyword">if</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists<span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token builtin">file</span><span class="token punctuation">.</span>endswith<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#39;.yaml&#39;</span><span class="token punctuation">,</span> <span class="token string">&#39;yml&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
config<span class="token punctuation">.</span>update<span class="token punctuation">(</span>load_from_yaml<span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token builtin">file</span><span class="token punctuation">.</span>endswith<span class="token punctuation">(</span><span class="token string">&#39;.json&#39;</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
config<span class="token punctuation">.</span>update<span class="token punctuation">(</span>load_from_json<span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token builtin">file</span><span class="token punctuation">.</span>endswith<span class="token punctuation">(</span><span class="token string">&#39;.toml&#39;</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
config<span class="token punctuation">.</span>update<span class="token punctuation">(</span>load_from_toml<span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token keyword">not</span> no_warning<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Unsupported config file format: </span><span class="token interpolation"><span class="token punctuation">{</span><span class="token builtin">file</span><span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token keyword">not</span> no_warning<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Config file not found: </span><span class="token interpolation"><span class="token punctuation">{</span><span class="token builtin">file</span><span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">return</span> config
</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></div></details><h3 id="def-load-configs-from-dirs-directories-str-no-waring-bool-false-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-load-configs-from-dirs-directories-str-no-waring-bool-false-dict-str-any"><span><em><strong>def</strong></em> <code>load_configs_from_dirs(*directories: str, *, no_waring: bool = False) -&gt; dict[str, Any]</code></span></a></h3><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L94" 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">load_configs_from_dirs</span><span class="token punctuation">(</span><span class="token operator">*</span>directories<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> no_waring<span class="token punctuation">:</span> <span class="token builtin">bool</span><span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
从目录下加载配置文件不递归
按照读取文件的优先级反向覆盖
默认执行扁平化选项
&quot;&quot;&quot;</span>
config <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token keyword">for</span> directory <span class="token keyword">in</span> directories<span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists<span class="token punctuation">(</span>directory<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> no_waring<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Directory not found: </span><span class="token interpolation"><span class="token punctuation">{</span>directory<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">continue</span>
<span class="token keyword">for</span> <span class="token builtin">file</span> <span class="token keyword">in</span> os<span class="token punctuation">.</span>listdir<span class="token punctuation">(</span>directory<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token builtin">file</span><span class="token punctuation">.</span>endswith<span class="token punctuation">(</span>_SUPPORTED_CONFIG_FORMATS<span class="token punctuation">)</span><span class="token punctuation">:</span>
config<span class="token punctuation">.</span>update<span class="token punctuation">(</span>load_from_files<span class="token punctuation">(</span>os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>directory<span class="token punctuation">,</span> <span class="token builtin">file</span><span class="token punctuation">)</span><span class="token punctuation">,</span> no_warning<span class="token operator">=</span>no_waring<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> config
</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></div></details><h3 id="def-load-config-in-default-no-waring-bool-false-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-load-config-in-default-no-waring-bool-false-dict-str-any"><span><em><strong>def</strong></em> <code>load_config_in_default(no_waring: bool = False) -&gt; dict[str, Any]</code></span></a></h3><p><strong></strong>: config.*config </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L116" 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">load_config_in_default</span><span class="token punctuation">(</span>no_waring<span class="token punctuation">:</span> <span class="token builtin">bool</span><span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
从一个标准的轻雪项目加载配置文件
项目目录下的config.*和config目录下的所有配置文件
项目目录下的配置文件优先
&quot;&quot;&quot;</span>
config <span class="token operator">=</span> load_configs_from_dirs<span class="token punctuation">(</span><span class="token string">&#39;config&#39;</span><span class="token punctuation">,</span> no_waring<span class="token operator">=</span>no_waring<span class="token punctuation">)</span>
config<span class="token punctuation">.</span>update<span class="token punctuation">(</span>load_from_files<span class="token punctuation">(</span><span class="token string">&#39;config.yaml&#39;</span><span class="token punctuation">,</span> <span class="token string">&#39;config.toml&#39;</span><span class="token punctuation">,</span> <span class="token string">&#39;config.json&#39;</span><span class="token punctuation">,</span> <span class="token string">&#39;config.yml&#39;</span><span class="token punctuation">,</span> no_warning<span class="token operator">=</span>no_waring<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> config
</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>`,22),c=[p,i,l];function u(r,d){return a(),t("div",null,c)}const f=s(e,[["render",u],["__file","config.html.vue"]]),g=JSON.parse('{"path":"/dev/api/config.html","title":"liteyuki.config","lang":"zh-CN","frontmatter":{"title":"liteyuki.config","lastUpdated":false,"description":"liteyuki.config : 1.: 2.: 3.: 4.: config 5....","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/config.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/config.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":"liteyuki.config"}],["meta",{"property":"og:description","content":"liteyuki.config : 1.: 2.: 3.: 4.: config 5...."}],["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.config\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def flat_config(config: dict[str, Any]) -> dict[str, Any]","slug":"def-flat-config-config-dict-str-any-dict-str-any","link":"#def-flat-config-config-dict-str-any-dict-str-any","children":[]},{"level":3,"title":"def load_from_yaml(file_: str) -> dict[str, Any]","slug":"def-load-from-yaml-file-str-dict-str-any","link":"#def-load-from-yaml-file-str-dict-str-any","children":[]},{"level":3,"title":"def load_from_json(file_: str) -> dict[str, Any]","slug":"def-load-from-json-file-str-dict-str-any","link":"#def-load-from-json-file-str-dict-str-any","children":[]},{"level":3,"title":"def load_from_toml(file_: str) -> dict[str, Any]","slug":"def-load-from-toml-file-str-dict-str-any","link":"#def-load-from-toml-file-str-dict-str-any","children":[]},{"level":3,"title":"def load_from_files(*files: str, *, no_warning: bool = False) -> dict[str, Any]","slug":"def-load-from-files-files-str-no-warning-bool-false-dict-str-any","link":"#def-load-from-files-files-str-no-warning-bool-false-dict-str-any","children":[]},{"level":3,"title":"def load_configs_from_dirs(*directories: str, *, no_waring: bool = False) -> dict[str, Any]","slug":"def-load-configs-from-dirs-directories-str-no-waring-bool-false-dict-str-any","link":"#def-load-configs-from-dirs-directories-str-no-waring-bool-false-dict-str-any","children":[]},{"level":3,"title":"def load_config_in_default(no_waring: bool = False) -> dict[str, Any]","slug":"def-load-config-in-default-no-waring-bool-false-dict-str-any","link":"#def-load-config-in-default-no-waring-bool-false-dict-str-any","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":5}]},"readingTime":{"minutes":3.29,"words":987},"filePathRelative":"dev/api/config.md","localizedDate":"2024819","autoDesc":true}');export{f as comp,g as data};

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,84 @@
import{_ as s,o as a,c as t,e as n,b as o}from"./app-BvUYPzLF.js";const e={},p=n('<h1 id="liteyuki-config" tabindex="-1"><a class="header-anchor" href="#liteyuki-config"><span>liteyuki.config</span></a></h1><p><strong>Description</strong>: 该模块用于常用配置文件的加载 多配置文件编写原则: 1.尽量不要冲突: 一个键不要多次出现 2.分工明确: 每个配置文件给一个或一类服务提供配置 3.扁平化编写: 配置文件尽量扁平化,不要出现过多的嵌套 4.注意冲突时的优先级: 项目目录下的配置文件优先级高于config目录下的配置文件 5.请不要将需要动态加载的内容写入配置文件,你应该使用其他储存方式</p><h3 id="def-flat-config-config-dict-str-any-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-flat-config-config-dict-str-any-dict-str-any"><span><em><strong>def</strong></em> <code>flat_config(config: dict[str, Any]) -&gt; dict[str, Any]</code></span></a></h3><p><strong>Description</strong>: 扁平化配置文件</p>',4),i=o("p",{"a.b.c:1":""},"{a:{b:{c:1}}} ->",-1),c=n(`<p><strong>Arguments</strong>:</p><blockquote><ul><li>config: 配置项目</li></ul></blockquote><p><strong>Return</strong>: 扁平化后的配置文件,但也包含原有的键值对</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L24" target="_blank">View on 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">flat_config</span><span class="token punctuation">(</span>config<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 operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
扁平化配置文件
{a:{b:{c:1}}} -&gt; {&quot;a.b.c&quot;: 1}
Args:
config: 配置项目
Returns:
扁平化后的配置文件但也包含原有的键值对
&quot;&quot;&quot;</span>
new_config <span class="token operator">=</span> copy<span class="token punctuation">.</span>deepcopy<span class="token punctuation">(</span>config<span class="token punctuation">)</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span>key<span class="token punctuation">,</span> value<span class="token punctuation">)</span> <span class="token keyword">in</span> config<span class="token punctuation">.</span>items<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>value<span class="token punctuation">,</span> <span class="token builtin">dict</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span>k<span class="token punctuation">,</span> v<span class="token punctuation">)</span> <span class="token keyword">in</span> flat_config<span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">.</span>items<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
new_config<span class="token punctuation">[</span><span class="token string-interpolation"><span class="token string">f&#39;</span><span class="token interpolation"><span class="token punctuation">{</span>key<span class="token punctuation">}</span></span><span class="token string">.</span><span class="token interpolation"><span class="token punctuation">{</span>k<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> v
<span class="token keyword">return</span> new_config
</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></div></details><h3 id="def-load-from-yaml-file-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-load-from-yaml-file-str-dict-str-any"><span><em><strong>def</strong></em> <code>load_from_yaml(file_: str) -&gt; dict[str, Any]</code></span></a></h3><p><strong>Description</strong>: Load config from yaml file</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L43" target="_blank">View on 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">load_from_yaml</span><span class="token punctuation">(</span>file_<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
Load config from yaml file
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Loading YAML config from </span><span class="token interpolation"><span class="token punctuation">{</span>file_<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
config <span class="token operator">=</span> yaml<span class="token punctuation">.</span>safe_load<span class="token punctuation">(</span><span class="token builtin">open</span><span class="token punctuation">(</span>file_<span class="token punctuation">,</span> <span class="token string">&#39;r&#39;</span><span class="token punctuation">,</span> encoding<span class="token operator">=</span><span class="token string">&#39;utf-8&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> flat_config<span class="token punctuation">(</span>config <span class="token keyword">if</span> config <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span> <span class="token keyword">else</span> <span class="token punctuation">{</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></div></details><h3 id="def-load-from-json-file-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-load-from-json-file-str-dict-str-any"><span><em><strong>def</strong></em> <code>load_from_json(file_: str) -&gt; dict[str, Any]</code></span></a></h3><p><strong>Description</strong>: Load config from json file</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L53" target="_blank">View on 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">load_from_json</span><span class="token punctuation">(</span>file_<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
Load config from json file
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Loading JSON config from </span><span class="token interpolation"><span class="token punctuation">{</span>file_<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
config <span class="token operator">=</span> json<span class="token punctuation">.</span>load<span class="token punctuation">(</span><span class="token builtin">open</span><span class="token punctuation">(</span>file_<span class="token punctuation">,</span> <span class="token string">&#39;r&#39;</span><span class="token punctuation">,</span> encoding<span class="token operator">=</span><span class="token string">&#39;utf-8&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> flat_config<span class="token punctuation">(</span>config <span class="token keyword">if</span> config <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span> <span class="token keyword">else</span> <span class="token punctuation">{</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></div></details><h3 id="def-load-from-toml-file-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-load-from-toml-file-str-dict-str-any"><span><em><strong>def</strong></em> <code>load_from_toml(file_: str) -&gt; dict[str, Any]</code></span></a></h3><p><strong>Description</strong>: Load config from toml file</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L62" target="_blank">View on 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">load_from_toml</span><span class="token punctuation">(</span>file_<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
Load config from toml file
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Loading TOML config from </span><span class="token interpolation"><span class="token punctuation">{</span>file_<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
config <span class="token operator">=</span> toml<span class="token punctuation">.</span>load<span class="token punctuation">(</span><span class="token builtin">open</span><span class="token punctuation">(</span>file_<span class="token punctuation">,</span> <span class="token string">&#39;r&#39;</span><span class="token punctuation">,</span> encoding<span class="token operator">=</span><span class="token string">&#39;utf-8&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> flat_config<span class="token punctuation">(</span>config <span class="token keyword">if</span> config <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span> <span class="token keyword">else</span> <span class="token punctuation">{</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></div></details><h3 id="def-load-from-files-files-str-no-warning-bool-false-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-load-from-files-files-str-no-warning-bool-false-dict-str-any"><span><em><strong>def</strong></em> <code>load_from_files(*files: str, *, no_warning: bool = False) -&gt; dict[str, Any]</code></span></a></h3><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L71" target="_blank">View on 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">load_from_files</span><span class="token punctuation">(</span><span class="token operator">*</span>files<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> no_warning<span class="token punctuation">:</span> <span class="token builtin">bool</span><span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
从指定文件加载配置项会自动识别文件格式
默认执行扁平化选项
&quot;&quot;&quot;</span>
config <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token keyword">for</span> <span class="token builtin">file</span> <span class="token keyword">in</span> files<span class="token punctuation">:</span>
<span class="token keyword">if</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists<span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token builtin">file</span><span class="token punctuation">.</span>endswith<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#39;.yaml&#39;</span><span class="token punctuation">,</span> <span class="token string">&#39;yml&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
config<span class="token punctuation">.</span>update<span class="token punctuation">(</span>load_from_yaml<span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token builtin">file</span><span class="token punctuation">.</span>endswith<span class="token punctuation">(</span><span class="token string">&#39;.json&#39;</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
config<span class="token punctuation">.</span>update<span class="token punctuation">(</span>load_from_json<span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token builtin">file</span><span class="token punctuation">.</span>endswith<span class="token punctuation">(</span><span class="token string">&#39;.toml&#39;</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
config<span class="token punctuation">.</span>update<span class="token punctuation">(</span>load_from_toml<span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token keyword">not</span> no_warning<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Unsupported config file format: </span><span class="token interpolation"><span class="token punctuation">{</span><span class="token builtin">file</span><span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> <span class="token keyword">not</span> no_warning<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Config file not found: </span><span class="token interpolation"><span class="token punctuation">{</span><span class="token builtin">file</span><span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">return</span> config
</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></div></details><h3 id="def-load-configs-from-dirs-directories-str-no-waring-bool-false-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-load-configs-from-dirs-directories-str-no-waring-bool-false-dict-str-any"><span><em><strong>def</strong></em> <code>load_configs_from_dirs(*directories: str, *, no_waring: bool = False) -&gt; dict[str, Any]</code></span></a></h3><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L94" target="_blank">View on 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">load_configs_from_dirs</span><span class="token punctuation">(</span><span class="token operator">*</span>directories<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> no_waring<span class="token punctuation">:</span> <span class="token builtin">bool</span><span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
从目录下加载配置文件不递归
按照读取文件的优先级反向覆盖
默认执行扁平化选项
&quot;&quot;&quot;</span>
config <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token keyword">for</span> directory <span class="token keyword">in</span> directories<span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists<span class="token punctuation">(</span>directory<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> no_waring<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Directory not found: </span><span class="token interpolation"><span class="token punctuation">{</span>directory<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">continue</span>
<span class="token keyword">for</span> <span class="token builtin">file</span> <span class="token keyword">in</span> os<span class="token punctuation">.</span>listdir<span class="token punctuation">(</span>directory<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token builtin">file</span><span class="token punctuation">.</span>endswith<span class="token punctuation">(</span>_SUPPORTED_CONFIG_FORMATS<span class="token punctuation">)</span><span class="token punctuation">:</span>
config<span class="token punctuation">.</span>update<span class="token punctuation">(</span>load_from_files<span class="token punctuation">(</span>os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>directory<span class="token punctuation">,</span> <span class="token builtin">file</span><span class="token punctuation">)</span><span class="token punctuation">,</span> no_warning<span class="token operator">=</span>no_waring<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> config
</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></div></details><h3 id="def-load-config-in-default-no-waring-bool-false-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-load-config-in-default-no-waring-bool-false-dict-str-any"><span><em><strong>def</strong></em> <code>load_config_in_default(no_waring: bool = False) -&gt; dict[str, Any]</code></span></a></h3><p><strong>Description</strong>: config.*config </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/config.py#L116" target="_blank">View on 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">load_config_in_default</span><span class="token punctuation">(</span>no_waring<span class="token punctuation">:</span> <span class="token builtin">bool</span><span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</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 triple-quoted-string string">&quot;&quot;&quot;
从一个标准的轻雪项目加载配置文件
项目目录下的config.*和config目录下的所有配置文件
项目目录下的配置文件优先
&quot;&quot;&quot;</span>
config <span class="token operator">=</span> load_configs_from_dirs<span class="token punctuation">(</span><span class="token string">&#39;config&#39;</span><span class="token punctuation">,</span> no_waring<span class="token operator">=</span>no_waring<span class="token punctuation">)</span>
config<span class="token punctuation">.</span>update<span class="token punctuation">(</span>load_from_files<span class="token punctuation">(</span><span class="token string">&#39;config.yaml&#39;</span><span class="token punctuation">,</span> <span class="token string">&#39;config.toml&#39;</span><span class="token punctuation">,</span> <span class="token string">&#39;config.json&#39;</span><span class="token punctuation">,</span> <span class="token string">&#39;config.yml&#39;</span><span class="token punctuation">,</span> no_warning<span class="token operator">=</span>no_waring<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> config
</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>`,22),l=[p,i,c];function u(r,d){return a(),t("div",null,l)}const f=s(e,[["render",u],["__file","config.html.vue"]]),g=JSON.parse('{"path":"/en/dev/api/config.html","title":"liteyuki.config","lang":"en-US","frontmatter":{"title":"liteyuki.config","lastUpdated":false,"description":"liteyuki.config Description: 1.: 2.: 3.: 4.: config 5....","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/config.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/config.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.config"}],["meta",{"property":"og:description","content":"liteyuki.config Description: 1.: 2.: 3.: 4.: config 5...."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.config\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def flat_config(config: dict[str, Any]) -> dict[str, Any]","slug":"def-flat-config-config-dict-str-any-dict-str-any","link":"#def-flat-config-config-dict-str-any-dict-str-any","children":[]},{"level":3,"title":"def load_from_yaml(file_: str) -> dict[str, Any]","slug":"def-load-from-yaml-file-str-dict-str-any","link":"#def-load-from-yaml-file-str-dict-str-any","children":[]},{"level":3,"title":"def load_from_json(file_: str) -> dict[str, Any]","slug":"def-load-from-json-file-str-dict-str-any","link":"#def-load-from-json-file-str-dict-str-any","children":[]},{"level":3,"title":"def load_from_toml(file_: str) -> dict[str, Any]","slug":"def-load-from-toml-file-str-dict-str-any","link":"#def-load-from-toml-file-str-dict-str-any","children":[]},{"level":3,"title":"def load_from_files(*files: str, *, no_warning: bool = False) -> dict[str, Any]","slug":"def-load-from-files-files-str-no-warning-bool-false-dict-str-any","link":"#def-load-from-files-files-str-no-warning-bool-false-dict-str-any","children":[]},{"level":3,"title":"def load_configs_from_dirs(*directories: str, *, no_waring: bool = False) -> dict[str, Any]","slug":"def-load-configs-from-dirs-directories-str-no-waring-bool-false-dict-str-any","link":"#def-load-configs-from-dirs-directories-str-no-waring-bool-false-dict-str-any","children":[]},{"level":3,"title":"def load_config_in_default(no_waring: bool = False) -> dict[str, Any]","slug":"def-load-config-in-default-no-waring-bool-false-dict-str-any","link":"#def-load-config-in-default-no-waring-bool-false-dict-str-any","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":3.19,"words":956},"filePathRelative":"en/dev/api/config.md","localizedDate":"August 21, 2024","autoDesc":true}');export{f as comp,g as data};

View File

@ -0,0 +1,47 @@
import{_ as e,r as t,o,c as p,b as n,d as s,a as c,e as i}from"./app-BvUYPzLF.js";const l={},u=i(`<h2 id="通道通信" tabindex="-1"><a class="header-anchor" href="#通道通信"><span><strong>通道通信</strong></span></a></h2><h3 id="简介" tabindex="-1"><a class="header-anchor" href="#简介"><span>简介</span></a></h3><p>轻雪运行在主进程 MainProcess 里,其他插件框架进程是伴随的子进程,因此无法通过内存共享和直接对象传递的方式进行通信,轻雪提供了一个通道<code>Channel</code>用于跨进程通信,你可以通过<code>Channel</code>发送消息给其他进程,也可以监听其他进程的消息。</p><p>例如子进程接收到用户信息需要重启机器人,这时可以通过通道对主进程发送消息,主进程接收到消息后重启对应子进程。</p><h3 id="示例" tabindex="-1"><a class="header-anchor" href="#示例"><span>示例</span></a></h3><p>通道是全双工的,有两种接收模式,但一个通道只能使用一种,即被动模式和主动模式,被动模式由<code>chan.on_receive()</code>装饰回调函数实现,主动模式需调用<code>chan.receive()</code>实现</p><ul><li>创建子进程的同时会初始化一个被动通道和一个主动通道,且通道标识为<code>{process_name}-active</code>和<code>{process_name}-passive</code></li><li>主进程中通过<code>get_channel</code>函数获取通道对象</li><li>子进程中导入单例<code>active_channel</code>及<code>passive_channel</code>即可</li></ul><blockquote><p>在轻雪插件中(主进程中)</p></blockquote><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">import</span> asyncio
<span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>comm <span class="token keyword">import</span> get_channel<span class="token punctuation">,</span> Channel
<span class="token keyword">from</span> liteyuki <span class="token keyword">import</span> get_bot
<span class="token comment"># get_channel函数获取通道对象参数为调用set_channel时的通道标识</span>
channel_passive <span class="token operator">=</span> get_channel<span class="token punctuation">(</span><span class="token string">&quot;nonebot-passive&quot;</span><span class="token punctuation">)</span> <span class="token comment"># </span>
channel_active <span class="token operator">=</span> get_channel<span class="token punctuation">(</span><span class="token string">&quot;nonebot-active&quot;</span><span class="token punctuation">)</span> <span class="token comment"># </span>
liteyuki_bot <span class="token operator">=</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment"># 注册一个函数在轻雪启动后运行</span>
<span class="token decorator annotation punctuation">@liteyuki_bot<span class="token punctuation">.</span>on_after_start</span>
<span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">send_data</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
channel_passive<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token string">&quot;I am liteyuki main process passive&quot;</span><span class="token punctuation">)</span>
channel_active<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token string">&quot;I am liteyuki main process active&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> asyncio<span class="token punctuation">.</span>sleep<span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token comment"># 3</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 class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote><p>NoneBot</p></blockquote><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">from</span> nonebot <span class="token keyword">import</span> get_driver
<span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>comm <span class="token keyword">import</span> active_channel<span class="token punctuation">,</span> passive_channel <span class="token comment"># </span>
<span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>log <span class="token keyword">import</span> logger
driver <span class="token operator">=</span> get_driver<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment"># 被动模式通过装饰器注册一个函数在接收到消息时运行每次接收到字符串数据时都会运行</span>
<span class="token decorator annotation punctuation">@passive_channel<span class="token punctuation">.</span>on_receive</span><span class="token punctuation">(</span>filter_func<span class="token operator">=</span><span class="token keyword">lambda</span> data<span class="token punctuation">:</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> <span class="token builtin">str</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">on_passive_receive</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;Passive receive: </span><span class="token interpolation"><span class="token punctuation">{</span>data<span class="token punctuation">}</span></span><span class="token string">&quot;</span></span><span class="token punctuation">)</span>
<span class="token comment"># 注册一个函数在NoneBot启动后运行</span>
<span class="token decorator annotation punctuation">@driver<span class="token punctuation">.</span>on_startup</span>
<span class="token keyword">def</span> <span class="token function">on_startup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
data <span class="token operator">=</span> active_channel<span class="token punctuation">.</span>receive<span class="token punctuation">(</span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;Active receive: </span><span class="token interpolation"><span class="token punctuation">{</span>data<span class="token punctuation">}</span></span><span class="token string">&quot;</span></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 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><blockquote><p></p></blockquote><div class="language-log line-numbers-mode" data-ext="log" data-title="log"><pre class="language-log"><code><span class="token date number">0000-00-00</span> <span class="token time number">00:00:00</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token property">Passive receive:</span> I am liteyuki main process passive
<span class="token date number">0000-00-00</span> <span class="token time number">00:00:00</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token property">Active receive:</span> I am liteyuki main process active
<span class="token date number">0000-00-00</span> <span class="token time number">00:00:03</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token property">Passive receive:</span> I am liteyuki main process passive
<span class="token date number">0000-00-00</span> <span class="token time number">00:00:03</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token property">Active receive:</span> I am liteyuki main process active
<span class="token punctuation">.</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></div><h2 id="" tabindex="-1"><a class="header-anchor" href="#"><span><strong></strong></span></a></h2><h3 id="-1" tabindex="-1"><a class="header-anchor" href="#-1"><span></span></a></h3><ul><li>使<code>storage</code></li><li>线线线</li></ul><h3 id="-1" tabindex="-1"><a class="header-anchor" href="#-1"><span></span></a></h3><blockquote><p>使</p></blockquote><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>comm<span class="token punctuation">.</span>storage <span class="token keyword">import</span> shared_memory
shared_memory<span class="token punctuation">.</span><span class="token builtin">set</span><span class="token punctuation">(</span><span class="token string">&quot;key&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;value&quot;</span><span class="token punctuation">)</span> <span class="token comment"># </span>
value <span class="token operator">=</span> shared_memory<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">&quot;key&quot;</span><span class="token punctuation">)</span> <span class="token comment"># </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></div>`,19),r={href:"https://github.com/LiteyukiStudio/LiteyukiBot/blob/main/liteyuki/comm/storage.py",target:"_blank",rel:"noopener noreferrer"};function d(k,m){const a=t("ExternalLinkIcon");return o(),p("div",null,[u,n("p",null,[s(""),n("a",r,[s("liteyuki/comm/storage.py"),c(a)])])])}const h=e(l,[["render",d],["__file","dev_comm.html.vue"]]),b=JSON.parse('{"path":"/dev/dev_comm.html","title":"","lang":"zh-CN","frontmatter":{"title":"","icon":"exchange-alt","order":4,"category":"","description":" MainProcess ChannelChannel ...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/dev_comm.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/dev_comm.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":""}],["meta",{"property":"og:description","content":" MainProcess ChannelChannel ..."}],["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:23:13.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:23:13.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:23:13.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":2,"title":"","slug":"","link":"#","children":[{"level":3,"title":"","slug":"","link":"#","children":[]},{"level":3,"title":"","slug":"","link":"#","children":[]}]},{"level":2,"title":"","slug":"","link":"#","children":[{"level":3,"title":"","slug":"-1","link":"#-1","children":[]},{"level":3,"title":"","slug":"-1","link":"#-1","children":[]}]}],"git":{"createdTime":1723413012000,"updatedTime":1724912593000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":6},{"name":"Snowykami","email":"snowykami@outlook.com","commits":1}]},"readingTime":{"minutes":2.52,"words":757},"filePathRelative":"dev/dev_comm.md","localizedDate":"2024811","autoDesc":true}');export{h as comp,b as data};

View File

@ -0,0 +1,47 @@
import{_ as e,r as t,o,c as p,b as n,d as s,a as c,e as i}from"./app-BvUYPzLF.js";const l={},u=i(`<h2 id="通道通信" tabindex="-1"><a class="header-anchor" href="#通道通信"><span><strong>通道通信</strong></span></a></h2><h3 id="简介" tabindex="-1"><a class="header-anchor" href="#简介"><span>简介</span></a></h3><p>轻雪运行在主进程 MainProcess 里,其他插件框架进程是伴随的子进程,因此无法通过内存共享和直接对象传递的方式进行通信,轻雪提供了一个通道<code>Channel</code>用于跨进程通信,你可以通过<code>Channel</code>发送消息给其他进程,也可以监听其他进程的消息。</p><p>例如子进程接收到用户信息需要重启机器人,这时可以通过通道对主进程发送消息,主进程接收到消息后重启对应子进程。</p><h3 id="示例" tabindex="-1"><a class="header-anchor" href="#示例"><span>示例</span></a></h3><p>通道是全双工的,有两种接收模式,但一个通道只能使用一种,即被动模式和主动模式,被动模式由<code>chan.on_receive()</code>装饰回调函数实现,主动模式需调用<code>chan.receive()</code>实现</p><ul><li>创建子进程的同时会初始化一个被动通道和一个主动通道,且通道标识为<code>{process_name}-active</code>和<code>{process_name}-passive</code></li><li>主进程中通过<code>get_channel</code>函数获取通道对象</li><li>子进程中导入单例<code>active_channel</code>及<code>passive_channel</code>即可</li></ul><blockquote><p>在轻雪插件中(主进程中)</p></blockquote><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">import</span> asyncio
<span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>comm <span class="token keyword">import</span> get_channel<span class="token punctuation">,</span> Channel
<span class="token keyword">from</span> liteyuki <span class="token keyword">import</span> get_bot
<span class="token comment"># get_channel函数获取通道对象参数为调用set_channel时的通道标识</span>
channel_passive <span class="token operator">=</span> get_channel<span class="token punctuation">(</span><span class="token string">&quot;nonebot-passive&quot;</span><span class="token punctuation">)</span> <span class="token comment"># </span>
channel_active <span class="token operator">=</span> get_channel<span class="token punctuation">(</span><span class="token string">&quot;nonebot-active&quot;</span><span class="token punctuation">)</span> <span class="token comment"># </span>
liteyuki_bot <span class="token operator">=</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment"># 注册一个函数在轻雪启动后运行</span>
<span class="token decorator annotation punctuation">@liteyuki_bot<span class="token punctuation">.</span>on_after_start</span>
<span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">send_data</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
channel_passive<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token string">&quot;I am liteyuki main process passive&quot;</span><span class="token punctuation">)</span>
channel_active<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token string">&quot;I am liteyuki main process active&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> asyncio<span class="token punctuation">.</span>sleep<span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token comment"># 3</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 class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote><p>NoneBot</p></blockquote><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">from</span> nonebot <span class="token keyword">import</span> get_driver
<span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>comm <span class="token keyword">import</span> active_channel<span class="token punctuation">,</span> passive_channel <span class="token comment"># </span>
<span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>log <span class="token keyword">import</span> logger
driver <span class="token operator">=</span> get_driver<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment"># 被动模式通过装饰器注册一个函数在接收到消息时运行每次接收到字符串数据时都会运行</span>
<span class="token decorator annotation punctuation">@passive_channel<span class="token punctuation">.</span>on_receive</span><span class="token punctuation">(</span>filter_func<span class="token operator">=</span><span class="token keyword">lambda</span> data<span class="token punctuation">:</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> <span class="token builtin">str</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">on_passive_receive</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;Passive receive: </span><span class="token interpolation"><span class="token punctuation">{</span>data<span class="token punctuation">}</span></span><span class="token string">&quot;</span></span><span class="token punctuation">)</span>
<span class="token comment"># 注册一个函数在NoneBot启动后运行</span>
<span class="token decorator annotation punctuation">@driver<span class="token punctuation">.</span>on_startup</span>
<span class="token keyword">def</span> <span class="token function">on_startup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
data <span class="token operator">=</span> active_channel<span class="token punctuation">.</span>receive<span class="token punctuation">(</span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;Active receive: </span><span class="token interpolation"><span class="token punctuation">{</span>data<span class="token punctuation">}</span></span><span class="token string">&quot;</span></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 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><blockquote><p></p></blockquote><div class="language-log line-numbers-mode" data-ext="log" data-title="log"><pre class="language-log"><code><span class="token date number">0000-00-00</span> <span class="token time number">00:00:00</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token property">Passive receive:</span> I am liteyuki main process passive
<span class="token date number">0000-00-00</span> <span class="token time number">00:00:00</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token property">Active receive:</span> I am liteyuki main process active
<span class="token date number">0000-00-00</span> <span class="token time number">00:00:03</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token property">Passive receive:</span> I am liteyuki main process passive
<span class="token date number">0000-00-00</span> <span class="token time number">00:00:03</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token property">Active receive:</span> I am liteyuki main process active
<span class="token punctuation">.</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></div><h2 id="" tabindex="-1"><a class="header-anchor" href="#"><span><strong></strong></span></a></h2><h3 id="-1" tabindex="-1"><a class="header-anchor" href="#-1"><span></span></a></h3><ul><li>使<code>storage</code></li><li>线线线</li></ul><h3 id="-1" tabindex="-1"><a class="header-anchor" href="#-1"><span></span></a></h3><blockquote><p>使</p></blockquote><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>comm<span class="token punctuation">.</span>storage <span class="token keyword">import</span> shared_memory
shared_memory<span class="token punctuation">.</span><span class="token builtin">set</span><span class="token punctuation">(</span><span class="token string">&quot;key&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;value&quot;</span><span class="token punctuation">)</span> <span class="token comment"># </span>
value <span class="token operator">=</span> shared_memory<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">&quot;key&quot;</span><span class="token punctuation">)</span> <span class="token comment"># </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></div>`,19),r={href:"https://github.com/LiteyukiStudio/LiteyukiBot/blob/main/liteyuki/comm/storage.py",target:"_blank",rel:"noopener noreferrer"};function d(k,m){const a=t("ExternalLinkIcon");return o(),p("div",null,[u,n("p",null,[s(""),n("a",r,[s("liteyuki/comm/storage.py"),c(a)])])])}const h=e(l,[["render",d],["__file","dev_comm.html.vue"]]),b=JSON.parse('{"path":"/en/dev/dev_comm.html","title":"","lang":"en-US","frontmatter":{"title":"","icon":"exchange-alt","order":4,"category":"","description":" MainProcess ChannelChannel ...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/dev_comm.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/dev_comm.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":""}],["meta",{"property":"og:description","content":" MainProcess ChannelChannel ..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-29T06:23:13.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:23:13.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:23:13.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":2,"title":"","slug":"","link":"#","children":[{"level":3,"title":"","slug":"","link":"#","children":[]},{"level":3,"title":"","slug":"","link":"#","children":[]}]},{"level":2,"title":"","slug":"","link":"#","children":[{"level":3,"title":"","slug":"-1","link":"#-1","children":[]},{"level":3,"title":"","slug":"-1","link":"#-1","children":[]}]}],"git":{"createdTime":1723829277000,"updatedTime":1724912593000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":4}]},"readingTime":{"minutes":2.52,"words":757},"filePathRelative":"en/dev/dev_comm.md","localizedDate":"August 16, 2024","autoDesc":true}');export{h as comp,b as data};

View File

@ -0,0 +1,24 @@
import{_ as t,r as o,o as i,c as l,b as n,d as e,a as s,e as c}from"./app-BvUYPzLF.js";const p={},r=c(`<h2 id="轻雪函数" tabindex="-1"><a class="header-anchor" href="#轻雪函数"><span><strong>轻雪函数</strong></span></a></h2><p>轻雪函数 Liteyuki Function 是轻雪的一个功能它允许你在轻雪中运行一些自定义的由数据驱动的命令类似于Minecraft的mcfunction属于资源包的一部分但需单独起篇幅.</p><h3 id="函数文件" tabindex="-1"><a class="header-anchor" href="#函数文件"><span><strong>函数文件</strong></span></a></h3><p>函数文件放在资源包的<code>functions</code>目录下,文件名以<code>.mcfunction</code> <code>.lyfunction</code> <code>.lyf</code>结尾,例如<code>test.mcfunction</code>,文件内容为一系列的命令,每行一个命令,支持单行注释<code>#</code>(编辑时的语法高亮可采取<code>shell</code>格式),例如:</p><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code><span class="token comment"># 在发信器输出&quot;hello world&quot;</span>
cmd <span class="token builtin class-name">echo</span> hello world
<span class="token comment"># 如果你想同时输出多行内容可以尝试换行符(Python格式)</span>
cmd <span class="token builtin class-name">echo</span> hello world<span class="token punctuation">\\</span>nLiteyuki bot
</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></div><p></p><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code>cmd <span class="token builtin class-name">echo</span> hello world <span class="token comment"># &quot;hello world&quot;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="" tabindex="-1"><a class="header-anchor" href="#"><span><strong></strong></span></a></h3><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code>var <span class="token operator">&lt;</span>var1<span class="token operator">=</span>value<span class="token operator"><span class="token file-descriptor important">1</span>&gt;</span> <span class="token punctuation">[</span>var2<span class="token operator">=</span>value2<span class="token punctuation">]</span> <span class="token punctuation">..</span>. <span class="token comment"># </span>
cmd <span class="token operator">&lt;</span>command<span class="token operator">&gt;</span> <span class="token comment"># </span>
api <span class="token operator">&lt;</span>api_name<span class="token operator">&gt;</span> <span class="token punctuation">[</span>var<span class="token operator">=</span>value<span class="token punctuation">..</span>.<span class="token punctuation">]</span> <span class="token comment"># Bot API</span>
<span class="token keyword">function</span> <span class="token operator">&lt;</span>func_name<span class="token operator">&gt;</span> <span class="token comment"># </span>
<span class="token function">sleep</span> <span class="token operator">&lt;</span>time<span class="token operator">&gt;</span> <span class="token comment"># s</span>
<span class="token function">nohup</span> <span class="token operator">&lt;</span>command<span class="token operator">&gt;</span> <span class="token comment"># 使task</span>
end <span class="token comment"># 结束函数关键字包括子task</span>
await <span class="token comment"># 等待所有异步任务结束若函数中启动了其他task需要在最后调用否则task对象会被销毁</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></div><h4 id="" tabindex="-1"><a class="header-anchor" href="#"><span><strong></strong></span></a></h4><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code><span class="token comment"># </span>
<span class="token comment"># 使用 /function poke user_id=123456 执行</span>
<span class="token comment"># 每隔0.2s戳两次无限戳会触发最大递归深度限制</span>
<span class="token comment"># 若要戳20s后停止则需要删除await添加sleep 20和end</span>
api friend_poke <span class="token assign-left variable">user_id</span><span class="token operator">=</span>user_id
api friend_poke <span class="token assign-left variable">user_id</span><span class="token operator">=</span>user_id
<span class="token function">sleep</span> <span class="token number">0.2</span>
<span class="token function">nohup</span> <span class="token keyword">function</span> poke
await
</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><h3 id="api" tabindex="-1"><a class="header-anchor" href="#api"><span><strong>API</strong></span></a></h3><p>onebotv11apiAdapter api.</p>`,13),d={href:"https://283375.github.io/onebot_v11_vitepress/api/index.html",target:"_blank",rel:"noopener noreferrer"},u=n("h3",{id:"",tabindex:"-1"},[n("a",{class:"header-anchor",href:"#"},[n("span",null,[n("strong",null,"")])])],-1),m=n("p",null,'LiteyukiBot, lyfunction"线".',-1),h=n("p",null,[n("code",null,"await"),e(" function")],-1),v=n("div",{class:"hint-container warning"},[n("p",{class:"hint-container-title"},"Warning"),n("p",null,"functiontaskawaittask")],-1),k={class:"hint-container tip"},f=n("p",{class:"hint-container-title"},"Tips",-1),g={href:"https://github.com/LiteyukiStudio/lyfunctionTextmate",target:"_blank",rel:"noopener noreferrer"};function b(_,y){const a=o("ExternalLinkIcon");return i(),l("div",null,[r,n("p",null,[n("a",d,[e("Onebot v11 API"),s(a)])]),u,m,h,v,n("div",k,[f,n("p",null,[e("使VS Code"),n("a",g,[e("Liteyuki Function"),s(a)]),e("")])])])}const w=t(p,[["render",b],["__file","dev_lyfunc.html.vue"]]),L=JSON.parse('{"path":"/en/dev/dev_lyfunc.html","title":"","lang":"en-US","frontmatter":{"title":"","icon":"code","order":2,"category":"","description":" Liteyuki Function Minecraftmcfunction. functions.mcfunction .lyfunction .lyftest.mc...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/dev_lyfunc.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/dev_lyfunc.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":""}],["meta",{"property":"og:description","content":" Liteyuki Function Minecraftmcfunction. functions.mcfunction .lyfunction .lyftest.mc..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-29T06:23:13.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:23:13.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:23:13.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":2,"title":"","slug":"","link":"#","children":[{"level":3,"title":"","slug":"","link":"#","children":[]},{"level":3,"title":"","slug":"","link":"#","children":[]},{"level":3,"title":"API","slug":"api","link":"#api","children":[]},{"level":3,"title":"","slug":"","link":"#","children":[]}]}],"git":{"createdTime":1723829277000,"updatedTime":1724912593000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":4}]},"readingTime":{"minutes":1.89,"words":566},"filePathRelative":"en/dev/dev_lyfunc.md","localizedDate":"August 16, 2024","autoDesc":true}');export{w as comp,L as data};

View File

@ -0,0 +1,24 @@
import{_ as t,r as o,o as i,c as l,b as n,d as e,a as s,e as c}from"./app-BvUYPzLF.js";const p={},r=c(`<h2 id="轻雪函数" tabindex="-1"><a class="header-anchor" href="#轻雪函数"><span><strong>轻雪函数</strong></span></a></h2><p>轻雪函数 Liteyuki Function 是轻雪的一个功能它允许你在轻雪中运行一些自定义的由数据驱动的命令类似于Minecraft的mcfunction属于资源包的一部分但需单独起篇幅.</p><h3 id="函数文件" tabindex="-1"><a class="header-anchor" href="#函数文件"><span><strong>函数文件</strong></span></a></h3><p>函数文件放在资源包的<code>functions</code>目录下,文件名以<code>.mcfunction</code> <code>.lyfunction</code> <code>.lyf</code>结尾,例如<code>test.mcfunction</code>,文件内容为一系列的命令,每行一个命令,支持单行注释<code>#</code>(编辑时的语法高亮可采取<code>shell</code>格式),例如:</p><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code><span class="token comment"># 在发信器输出&quot;hello world&quot;</span>
cmd <span class="token builtin class-name">echo</span> hello world
<span class="token comment"># 如果你想同时输出多行内容可以尝试换行符(Python格式)</span>
cmd <span class="token builtin class-name">echo</span> hello world<span class="token punctuation">\\</span>nLiteyuki bot
</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></div><p></p><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code>cmd <span class="token builtin class-name">echo</span> hello world <span class="token comment"># &quot;hello world&quot;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="" tabindex="-1"><a class="header-anchor" href="#"><span><strong></strong></span></a></h3><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code>var <span class="token operator">&lt;</span>var1<span class="token operator">=</span>value<span class="token operator"><span class="token file-descriptor important">1</span>&gt;</span> <span class="token punctuation">[</span>var2<span class="token operator">=</span>value2<span class="token punctuation">]</span> <span class="token punctuation">..</span>. <span class="token comment"># </span>
cmd <span class="token operator">&lt;</span>command<span class="token operator">&gt;</span> <span class="token comment"># </span>
api <span class="token operator">&lt;</span>api_name<span class="token operator">&gt;</span> <span class="token punctuation">[</span>var<span class="token operator">=</span>value<span class="token punctuation">..</span>.<span class="token punctuation">]</span> <span class="token comment"># Bot API</span>
<span class="token keyword">function</span> <span class="token operator">&lt;</span>func_name<span class="token operator">&gt;</span> <span class="token comment"># </span>
<span class="token function">sleep</span> <span class="token operator">&lt;</span>time<span class="token operator">&gt;</span> <span class="token comment"># s</span>
<span class="token function">nohup</span> <span class="token operator">&lt;</span>command<span class="token operator">&gt;</span> <span class="token comment"># 使task</span>
end <span class="token comment"># 结束函数关键字包括子task</span>
await <span class="token comment"># 等待所有异步任务结束若函数中启动了其他task需要在最后调用否则task对象会被销毁</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></div><h4 id="" tabindex="-1"><a class="header-anchor" href="#"><span><strong></strong></span></a></h4><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code><span class="token comment"># </span>
<span class="token comment"># 使用 /function poke user_id=123456 执行</span>
<span class="token comment"># 每隔0.2s戳两次无限戳会触发最大递归深度限制</span>
<span class="token comment"># 若要戳20s后停止则需要删除await添加sleep 20和end</span>
api friend_poke <span class="token assign-left variable">user_id</span><span class="token operator">=</span>user_id
api friend_poke <span class="token assign-left variable">user_id</span><span class="token operator">=</span>user_id
<span class="token function">sleep</span> <span class="token number">0.2</span>
<span class="token function">nohup</span> <span class="token keyword">function</span> poke
await
</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><h3 id="api" tabindex="-1"><a class="header-anchor" href="#api"><span><strong>API</strong></span></a></h3><p>onebotv11apiAdapter api.</p>`,13),d={href:"https://283375.github.io/onebot_v11_vitepress/api/index.html",target:"_blank",rel:"noopener noreferrer"},u=n("h3",{id:"",tabindex:"-1"},[n("a",{class:"header-anchor",href:"#"},[n("span",null,[n("strong",null,"")])])],-1),m=n("p",null,'LiteyukiBot, lyfunction"线".',-1),h=n("p",null,[n("code",null,"await"),e(" function")],-1),v=n("div",{class:"hint-container warning"},[n("p",{class:"hint-container-title"},""),n("p",null,"functiontaskawaittask")],-1),k={class:"hint-container tip"},f=n("p",{class:"hint-container-title"},"",-1),b={href:"https://github.com/LiteyukiStudio/lyfunctionTextmate",target:"_blank",rel:"noopener noreferrer"};function g(_,y){const a=o("ExternalLinkIcon");return i(),l("div",null,[r,n("p",null,[n("a",d,[e("Onebot v11 API"),s(a)])]),u,m,h,v,n("div",k,[f,n("p",null,[e("使VS Code"),n("a",b,[e("Liteyuki Function"),s(a)]),e("")])])])}const w=t(p,[["render",g],["__file","dev_lyfunc.html.vue"]]),L=JSON.parse('{"path":"/dev/dev_lyfunc.html","title":"","lang":"zh-CN","frontmatter":{"title":"","icon":"code","order":2,"category":"","description":" Liteyuki Function Minecraftmcfunction. functions.mcfunction .lyfunction .lyftest.mc...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/dev_lyfunc.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/dev_lyfunc.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":""}],["meta",{"property":"og:description","content":" Liteyuki Function Minecraftmcfunction. functions.mcfunction .lyfunction .lyftest.mc..."}],["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:23:13.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:23:13.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:23:13.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":2,"title":"","slug":"","link":"#","children":[{"level":3,"title":"","slug":"","link":"#","children":[]},{"level":3,"title":"","slug":"","link":"#","children":[]},{"level":3,"title":"API","slug":"api","link":"#api","children":[]},{"level":3,"title":"","slug":"","link":"#","children":[]}]}],"git":{"createdTime":1723411596000,"updatedTime":1724912593000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":3}]},"readingTime":{"minutes":1.89,"words":566},"filePathRelative":"dev/dev_lyfunc.md","localizedDate":"2024811","autoDesc":true}');export{w as comp,L as data};

View File

@ -0,0 +1,35 @@
import{_ as n,o as s,c as a,e}from"./app-BvUYPzLF.js";const t={},p=e(`<h2 id="简介" tabindex="-1"><a class="header-anchor" href="#简介"><span>简介</span></a></h2><p>轻雪插件是轻雪内置的一部分功能,运行在主进程中,可以很高程度地扩展轻雪的功能</p><h2 id="开始" tabindex="-1"><a class="header-anchor" href="#开始"><span>开始</span></a></h2><h3 id="创建插件" tabindex="-1"><a class="header-anchor" href="#创建插件"><span>创建插件</span></a></h3><p>一个<code>.py</code>文件或一个包含<code>__init__.py</code>的文件夹即可被识别为插件</p><p>首先创建一个文件夹,例如<code>watchdog_plugin</code>,并在其中创建一个<code>__init__.py</code>文件,即可创建一个插件</p><p><code>__init__.py</code></p><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>plugin <span class="token keyword">import</span> PluginMetadata<span class="token punctuation">,</span> PluginType
<span class="token keyword">from</span> <span class="token punctuation">.</span>watch_dog <span class="token keyword">import</span> <span class="token operator">*</span> <span class="token comment"># </span>
<span class="token comment"># 定义插件元数据</span>
__plugin_meta__ <span class="token operator">=</span> PluginMetadata<span class="token punctuation">(</span>
name<span class="token operator">=</span><span class="token string">&quot;NoneDog&quot;</span><span class="token punctuation">,</span> <span class="token comment"># </span>
version<span class="token operator">=</span><span class="token string">&quot;1.0.0&quot;</span><span class="token punctuation">,</span> <span class="token comment"># </span>
description<span class="token operator">=</span><span class="token string">&quot;A simple plugin for nonebot developer&quot;</span><span class="token punctuation">,</span> <span class="token comment"># </span>
<span class="token builtin">type</span><span class="token operator">=</span>PluginType<span class="token punctuation">.</span>SERVICE <span class="token comment"># </span>
<span class="token punctuation">)</span>
<span class="token comment"># 你的插件代码</span>
<span class="token punctuation">.</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 class="line-number"></div></div></div><h3 id="" tabindex="-1"><a class="header-anchor" href="#"><span></span></a></h3><p> NoneBot <code>watch_dog.py</code></p><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">import</span> os
<span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>dev <span class="token keyword">import</span> observer <span class="token comment"># </span>
<span class="token keyword">from</span> liteyuki <span class="token keyword">import</span> get_bot<span class="token punctuation">,</span> logger <span class="token comment"># Bot</span>
<span class="token keyword">from</span> watchdog<span class="token punctuation">.</span>events <span class="token keyword">import</span> FileSystemEvent <span class="token comment"># </span>
liteyuki <span class="token operator">=</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment"># Bot</span>
exclude_extensions <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token string">&quot;.pyc&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;.pyo&quot;</span><span class="token punctuation">)</span> <span class="token comment"># </span>
<span class="token comment"># 用observer的on_file_system_event装饰器监听文件系统事件</span>
<span class="token decorator annotation punctuation">@observer<span class="token punctuation">.</span>on_file_system_event</span><span class="token punctuation">(</span>
directories<span class="token operator">=</span><span class="token punctuation">(</span><span class="token string">&quot;src/nonebot_plugins&quot;</span><span class="token punctuation">,</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
event_filter<span class="token operator">=</span><span class="token keyword">lambda</span> event<span class="token punctuation">:</span> <span class="token keyword">not</span> event<span class="token punctuation">.</span>src_path<span class="token punctuation">.</span>endswith<span class="token punctuation">(</span>exclude_extensions<span class="token punctuation">)</span> <span class="token keyword">and</span> <span class="token punctuation">(</span><span class="token string">&quot;__pycache__&quot;</span> <span class="token keyword">not</span> <span class="token keyword">in</span> event<span class="token punctuation">.</span>src_path<span class="token punctuation">)</span> <span class="token keyword">and</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>isfile<span class="token punctuation">(</span>event<span class="token punctuation">.</span>src_path<span class="token punctuation">)</span>
<span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">restart_nonebot_process</span><span class="token punctuation">(</span>event<span class="token punctuation">:</span> FileSystemEvent<span class="token punctuation">)</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;File </span><span class="token interpolation"><span class="token punctuation">{</span>event<span class="token punctuation">.</span>src_path<span class="token punctuation">}</span></span><span class="token string"> changed, reloading nonebot...&quot;</span></span><span class="token punctuation">)</span>
liteyuki<span class="token punctuation">.</span>restart_process<span class="token punctuation">(</span><span class="token string">&quot;nonebot&quot;</span><span class="token punctuation">)</span> <span class="token comment"># </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 class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="" tabindex="-1"><a class="header-anchor" href="#"><span></span></a></h3><h4 id="1" tabindex="-1"><a class="header-anchor" href="#1"><span>1</span></a></h4><ul><li><code>liteyuki.plugins</code><code>watchdog_plugin</code></li></ul><h4 id="2" tabindex="-1"><a class="header-anchor" href="#2"><span>2</span></a></h4><ul><li>使</li><li><code>main.py</code></li></ul><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>dev<span class="token punctuation">.</span>plugin <span class="token keyword">import</span> run_plugins
run_plugins<span class="token punctuation">(</span><span class="token string">&quot;watchdog_plugin&quot;</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></div><p><code>python main.py</code></p><p>src/nonebot_plugins<code>test.py</code>NoneBot</p>`,19),o=[p];function i(c,l){return s(),a("div",null,o)}const d=n(t,[["render",i],["__file","dev_lyplugin.html.vue"]]),r=JSON.parse('{"path":"/en/dev/dev_lyplugin.html","title":"","lang":"en-US","frontmatter":{"title":"","icon":"laptop-code","order":3,"category":"","description":" .py__init__.py watchdog_plugin__init__.py __init__.py ...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/dev_lyplugin.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/dev_lyplugin.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":""}],["meta",{"property":"og:description","content":" .py__init__.py watchdog_plugin__init__.py __init__.py ..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-29T06:23:13.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:23:13.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:23:13.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":2,"title":"","slug":"","link":"#","children":[]},{"level":2,"title":"","slug":"","link":"#","children":[{"level":3,"title":"","slug":"","link":"#","children":[]},{"level":3,"title":"","slug":"","link":"#","children":[]},{"level":3,"title":"","slug":"","link":"#","children":[]}]}],"git":{"createdTime":1723829277000,"updatedTime":1724912593000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":4}]},"readingTime":{"minutes":1.68,"words":504},"filePathRelative":"en/dev/dev_lyplugin.md","localizedDate":"August 16, 2024","autoDesc":true}');export{d as comp,r as data};

View File

@ -0,0 +1,35 @@
import{_ as n,o as s,c as a,e}from"./app-BvUYPzLF.js";const t={},p=e(`<h2 id="简介" tabindex="-1"><a class="header-anchor" href="#简介"><span>简介</span></a></h2><p>轻雪插件是轻雪内置的一部分功能,运行在主进程中,可以很高程度地扩展轻雪的功能</p><h2 id="开始" tabindex="-1"><a class="header-anchor" href="#开始"><span>开始</span></a></h2><h3 id="创建插件" tabindex="-1"><a class="header-anchor" href="#创建插件"><span>创建插件</span></a></h3><p>一个<code>.py</code>文件或一个包含<code>__init__.py</code>的文件夹即可被识别为插件</p><p>首先创建一个文件夹,例如<code>watchdog_plugin</code>,并在其中创建一个<code>__init__.py</code>文件,即可创建一个插件</p><p><code>__init__.py</code></p><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>plugin <span class="token keyword">import</span> PluginMetadata<span class="token punctuation">,</span> PluginType
<span class="token keyword">from</span> <span class="token punctuation">.</span>watch_dog <span class="token keyword">import</span> <span class="token operator">*</span> <span class="token comment"># </span>
<span class="token comment"># 定义插件元数据</span>
__plugin_meta__ <span class="token operator">=</span> PluginMetadata<span class="token punctuation">(</span>
name<span class="token operator">=</span><span class="token string">&quot;NoneDog&quot;</span><span class="token punctuation">,</span> <span class="token comment"># </span>
version<span class="token operator">=</span><span class="token string">&quot;1.0.0&quot;</span><span class="token punctuation">,</span> <span class="token comment"># </span>
description<span class="token operator">=</span><span class="token string">&quot;A simple plugin for nonebot developer&quot;</span><span class="token punctuation">,</span> <span class="token comment"># </span>
<span class="token builtin">type</span><span class="token operator">=</span>PluginType<span class="token punctuation">.</span>SERVICE <span class="token comment"># </span>
<span class="token punctuation">)</span>
<span class="token comment"># 你的插件代码</span>
<span class="token punctuation">.</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 class="line-number"></div></div></div><h3 id="" tabindex="-1"><a class="header-anchor" href="#"><span></span></a></h3><p> NoneBot <code>watch_dog.py</code></p><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">import</span> os
<span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>dev <span class="token keyword">import</span> observer <span class="token comment"># </span>
<span class="token keyword">from</span> liteyuki <span class="token keyword">import</span> get_bot<span class="token punctuation">,</span> logger <span class="token comment"># Bot</span>
<span class="token keyword">from</span> watchdog<span class="token punctuation">.</span>events <span class="token keyword">import</span> FileSystemEvent <span class="token comment"># </span>
liteyuki <span class="token operator">=</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment"># Bot</span>
exclude_extensions <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token string">&quot;.pyc&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;.pyo&quot;</span><span class="token punctuation">)</span> <span class="token comment"># </span>
<span class="token comment"># 用observer的on_file_system_event装饰器监听文件系统事件</span>
<span class="token decorator annotation punctuation">@observer<span class="token punctuation">.</span>on_file_system_event</span><span class="token punctuation">(</span>
directories<span class="token operator">=</span><span class="token punctuation">(</span><span class="token string">&quot;src/nonebot_plugins&quot;</span><span class="token punctuation">,</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
event_filter<span class="token operator">=</span><span class="token keyword">lambda</span> event<span class="token punctuation">:</span> <span class="token keyword">not</span> event<span class="token punctuation">.</span>src_path<span class="token punctuation">.</span>endswith<span class="token punctuation">(</span>exclude_extensions<span class="token punctuation">)</span> <span class="token keyword">and</span> <span class="token punctuation">(</span><span class="token string">&quot;__pycache__&quot;</span> <span class="token keyword">not</span> <span class="token keyword">in</span> event<span class="token punctuation">.</span>src_path<span class="token punctuation">)</span> <span class="token keyword">and</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>isfile<span class="token punctuation">(</span>event<span class="token punctuation">.</span>src_path<span class="token punctuation">)</span>
<span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">restart_nonebot_process</span><span class="token punctuation">(</span>event<span class="token punctuation">:</span> FileSystemEvent<span class="token punctuation">)</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;File </span><span class="token interpolation"><span class="token punctuation">{</span>event<span class="token punctuation">.</span>src_path<span class="token punctuation">}</span></span><span class="token string"> changed, reloading nonebot...&quot;</span></span><span class="token punctuation">)</span>
liteyuki<span class="token punctuation">.</span>restart_process<span class="token punctuation">(</span><span class="token string">&quot;nonebot&quot;</span><span class="token punctuation">)</span> <span class="token comment"># </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 class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="" tabindex="-1"><a class="header-anchor" href="#"><span></span></a></h3><h4 id="1" tabindex="-1"><a class="header-anchor" href="#1"><span>1</span></a></h4><ul><li><code>liteyuki.plugins</code><code>watchdog_plugin</code></li></ul><h4 id="2" tabindex="-1"><a class="header-anchor" href="#2"><span>2</span></a></h4><ul><li>使</li><li><code>main.py</code></li></ul><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">from</span> liteyuki<span class="token punctuation">.</span>dev<span class="token punctuation">.</span>plugin <span class="token keyword">import</span> run_plugins
run_plugins<span class="token punctuation">(</span><span class="token string">&quot;watchdog_plugin&quot;</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></div><p><code>python main.py</code></p><p>src/nonebot_plugins<code>test.py</code>NoneBot</p>`,19),o=[p];function i(c,l){return s(),a("div",null,o)}const d=n(t,[["render",i],["__file","dev_lyplugin.html.vue"]]),r=JSON.parse('{"path":"/dev/dev_lyplugin.html","title":"","lang":"zh-CN","frontmatter":{"title":"","icon":"laptop-code","order":3,"category":"","description":" .py__init__.py watchdog_plugin__init__.py __init__.py ...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/dev_lyplugin.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/dev_lyplugin.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":""}],["meta",{"property":"og:description","content":" .py__init__.py watchdog_plugin__init__.py __init__.py ..."}],["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:23:13.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:23:13.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:23:13.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":2,"title":"","slug":"","link":"#","children":[]},{"level":2,"title":"","slug":"","link":"#","children":[{"level":3,"title":"","slug":"","link":"#","children":[]},{"level":3,"title":"","slug":"","link":"#","children":[]},{"level":3,"title":"","slug":"","link":"#","children":[]}]}],"git":{"createdTime":1723411596000,"updatedTime":1724912593000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":6}]},"readingTime":{"minutes":1.68,"words":504},"filePathRelative":"dev/dev_lyplugin.md","localizedDate":"2024811","autoDesc":true}');export{d as comp,r as data};

View File

@ -0,0 +1,15 @@
import{_ as a,r as s,o as l,c as o,b as e,a as i,w as c,d as t,e as d}from"./app-BvUYPzLF.js";const r={},p=e("h2",{id:"简介",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#简介"},[e("span",null,"简介")])],-1),u=e("p",null,"资源包,亦可根据用途称为主题包、字体包、语言包等,它允许你一定程度上自定义轻雪的外观,并且不用修改源代码",-1),m=e("li",null,[t("资源包的制作很简单,如果你接触过"),e("code",null,"Minecraft"),t("的资源包,那么你能够很快就上手,仅需按照原有路径进行文件替换即可,讲起打包成一个新的资源包。")],-1),h=e("li",null,[t("部分内容制作需要一点点前端基础,例如"),e("code",null,"html"),t(""),e("code",null,"css")],-1),v=e("li",null,[t("轻雪原版资源包请查看"),e("code",null,"LiteyukiBot/liteyuki/resources"),t(",可以在此基础上进行修改")],-1),_=e("li",null,"欢迎各位投稿资源包到轻雪资源商店",-1),k=d(`<p>请注意主题包中的html渲染使用Js来规定数据的渲染位置请确保您所编写的html代码能被Bot解析否则会导致渲染失败或渲染结果不理想/异常/错位等无法预料的事情发生。推荐在编写html时同时更改对应Js代码以避免出现无法预料的问题。</p><hr><h2 id="加载资源包" tabindex="-1"><a class="header-anchor" href="#加载资源包"><span>加载资源包</span></a></h2><ul><li>资源包通常是以<code>.zip</code>格式压缩的,只需要将其解压到根目录<code>resources</code>目录下即可,注意不要嵌套文件夹,正常的路径应该是这样的</li></ul><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code>main.py
resources
resource_pack_1
metadata.yml
templates
<span class="token punctuation">..</span>.
resource_pack_2
metadata.yml
<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></div><ul><li>,<code>metadata.yml</code></li><li><code>metadata.yml</code></li></ul><div class="language-yaml line-numbers-mode" data-ext="yml" data-title="yml"><pre class="language-yaml"><code><span class="token key atrule">name</span><span class="token punctuation">:</span> <span class="token string">&quot;&quot;</span>
<span class="token key atrule">version</span><span class="token punctuation">:</span> <span class="token string">&quot;1.0.0&quot;</span>
<span class="token key atrule">description</span><span class="token punctuation">:</span> <span class="token string">&quot;&quot;</span>
<span class="token comment"># 你可以自定义一些信息,但请保证以上三个字段</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></div><ul><li>A<code>index.html</code>B<code>index.html</code>BA<code>index.html</code></li><li>A<code>templates/index.html</code>B<code>templates/style.css</code>A<code>index.html</code><code>./style.css</code>Bcss</li></ul><div class="hint-container tip"><p class="hint-container-title"></p><p></p></div>`,9);function y(g,b){const n=s("RouteLink");return l(),o("div",null,[p,u,e("ul",null,[e("li",null,[i(n,{to:"/store/"},{default:c(()=>[t("/")]),_:1}),t("")]),m,h,v,_]),k])}const x=a(r,[["render",y],["__file","dev_resource_pack.html.vue"]]),B=JSON.parse('{"path":"/dev/dev_resource_pack.html","title":"","lang":"zh-CN","frontmatter":{"title":"","icon":"box","order":1,"category":"","description":" ,, Minecraft ,htmlc...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/dev_resource_pack.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/dev_resource_pack.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":""}],["meta",{"property":"og:description","content":" ,, Minecraft ,htmlc..."}],["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:23:13.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:23:13.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:23:13.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":2,"title":"","slug":"","link":"#","children":[]},{"level":2,"title":"","slug":"","link":"#","children":[]}],"git":{"createdTime":1723411596000,"updatedTime":1724912593000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":3}]},"readingTime":{"minutes":2.15,"words":644},"filePathRelative":"dev/dev_resource_pack.md","localizedDate":"2024811","autoDesc":true}');export{x as comp,B as data};

View File

@ -0,0 +1,15 @@
import{_ as a,r as s,o as l,c as o,b as e,a as i,w as c,d as t,e as d}from"./app-BvUYPzLF.js";const r={},p=e("h2",{id:"简介",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#简介"},[e("span",null,"简介")])],-1),u=e("p",null,"资源包,亦可根据用途称为主题包、字体包、语言包等,它允许你一定程度上自定义轻雪的外观,并且不用修改源代码",-1),m=e("li",null,[t("资源包的制作很简单,如果你接触过"),e("code",null,"Minecraft"),t("的资源包,那么你能够很快就上手,仅需按照原有路径进行文件替换即可,讲起打包成一个新的资源包。")],-1),h=e("li",null,[t("部分内容制作需要一点点前端基础,例如"),e("code",null,"html"),t(""),e("code",null,"css")],-1),v=e("li",null,[t("轻雪原版资源包请查看"),e("code",null,"LiteyukiBot/liteyuki/resources"),t(",可以在此基础上进行修改")],-1),_=e("li",null,"欢迎各位投稿资源包到轻雪资源商店",-1),k=d(`<p>请注意主题包中的html渲染使用Js来规定数据的渲染位置请确保您所编写的html代码能被Bot解析否则会导致渲染失败或渲染结果不理想/异常/错位等无法预料的事情发生。推荐在编写html时同时更改对应Js代码以避免出现无法预料的问题。</p><hr><h2 id="加载资源包" tabindex="-1"><a class="header-anchor" href="#加载资源包"><span>加载资源包</span></a></h2><ul><li>资源包通常是以<code>.zip</code>格式压缩的,只需要将其解压到根目录<code>resources</code>目录下即可,注意不要嵌套文件夹,正常的路径应该是这样的</li></ul><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code>main.py
resources
resource_pack_1
metadata.yml
templates
<span class="token punctuation">..</span>.
resource_pack_2
metadata.yml
<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></div><ul><li>,<code>metadata.yml</code></li><li><code>metadata.yml</code></li></ul><div class="language-yaml line-numbers-mode" data-ext="yml" data-title="yml"><pre class="language-yaml"><code><span class="token key atrule">name</span><span class="token punctuation">:</span> <span class="token string">&quot;&quot;</span>
<span class="token key atrule">version</span><span class="token punctuation">:</span> <span class="token string">&quot;1.0.0&quot;</span>
<span class="token key atrule">description</span><span class="token punctuation">:</span> <span class="token string">&quot;&quot;</span>
<span class="token comment"># 你可以自定义一些信息,但请保证以上三个字段</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></div><ul><li>A<code>index.html</code>B<code>index.html</code>BA<code>index.html</code></li><li>A<code>templates/index.html</code>B<code>templates/style.css</code>A<code>index.html</code><code>./style.css</code>Bcss</li></ul><div class="hint-container tip"><p class="hint-container-title">Tips</p><p></p></div>`,9);function y(g,b){const n=s("RouteLink");return l(),o("div",null,[p,u,e("ul",null,[e("li",null,[i(n,{to:"/store/"},{default:c(()=>[t("/")]),_:1}),t("")]),m,h,v,_]),k])}const x=a(r,[["render",y],["__file","dev_resource_pack.html.vue"]]),B=JSON.parse('{"path":"/en/dev/dev_resource_pack.html","title":"","lang":"en-US","frontmatter":{"title":"","icon":"box","order":1,"category":"","description":" ,, Minecraft ,htmlc...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/dev_resource_pack.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/dev_resource_pack.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":""}],["meta",{"property":"og:description","content":" ,, Minecraft ,htmlc..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-29T06:23:13.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:23:13.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:23:13.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":2,"title":"","slug":"","link":"#","children":[]},{"level":2,"title":"","slug":"","link":"#","children":[]}],"git":{"createdTime":1723829277000,"updatedTime":1724912593000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":4}]},"readingTime":{"minutes":2.15,"words":644},"filePathRelative":"en/dev/dev_resource_pack.md","localizedDate":"August 16, 2024","autoDesc":true}');export{x as comp,B as data};

View File

@ -0,0 +1,38 @@
import{_ as s,o as n,c as a,e}from"./app-BvUYPzLF.js";const t={},p=e(`<h1 id="liteyuki-message-event" tabindex="-1"><a class="header-anchor" href="#liteyuki-message-event"><span>liteyuki.message.event</span></a></h1><p><strong>Description</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/8/19 下午10:47 @Author : snowykami @Email : snowykami@outlook.com @File : event.py @Software: PyCharm</p><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><h4 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-optional-channel-messageevent-none-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-optional-channel-messageevent-none-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: Optional[Channel[MessageEvent]] = None, data: Optional[dict[str, Any]] = None)</code></span></a></h4><p><strong>Description</strong>: 轻雪抽象消息事件</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/message/event.py#L18" target="_blank">View on 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> 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> Optional<span class="token punctuation">[</span>Channel<span class="token punctuation">[</span><span class="token string">&#39;MessageEvent&#39;</span><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> 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>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
轻雪抽象消息事件
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: 附加数据
&quot;&quot;&quot;</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
self<span class="token punctuation">.</span>user_id <span class="token operator">=</span> user_id
self<span class="token punctuation">.</span>receive_channel <span class="token operator">=</span> receive_channel
</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><h4 id="def-reply-self-message-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-reply-self-message-str-dict-str-any"><span><em><strong>def</strong></em> <code>reply(self, message: str | dict[str, Any])</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>message:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/message/event.py#L66" target="_blank">View on 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">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">&quot;&quot;&quot;
回复消息
Args:
message:
Returns:
&quot;&quot;&quot;</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">&#39;&#39;</span><span class="token punctuation">,</span> data<span class="token operator">=</span><span class="token punctuation">{</span><span class="token string">&#39;message&#39;</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> user_id<span class="token operator">=</span>self<span class="token punctuation">.</span>user_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 boolean">None</span><span class="token punctuation">)</span>
<span class="token keyword">if</span> self<span class="token punctuation">.</span>receive_channel<span class="token punctuation">:</span>
self<span class="token punctuation">.</span>receive_channel<span class="token punctuation">.</span>send<span class="token punctuation">(</span>reply_event<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></div></details>`,12),o=[p];function i(l,c){return n(),a("div",null,o)}const u=s(t,[["render",i],["__file","event.html.vue"]]),d=JSON.parse('{"path":"/en/dev/api/message/event.html","title":"liteyuki.message.event","lang":"en-US","frontmatter":{"title":"liteyuki.message.event","lastUpdated":false,"description":"liteyuki.message.event Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/19 10:47 @Author : snowykami @Email : snowykami@outlook.com @Fil...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/message/event.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/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":"liteyuki.message.event Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/19 10:47 @Author : snowykami @Email : snowykami@outlook.com @Fil..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.event\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class MessageEvent","slug":"class-messageevent","link":"#class-messageevent","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":1.05,"words":314},"filePathRelative":"en/dev/api/message/event.md","localizedDate":"August 21, 2024","autoDesc":true}');export{u as comp,d as data};

View File

@ -0,0 +1,4 @@
import{_ as e,o as t,c as n,e as a}from"./app-BvUYPzLF.js";const s={},o=a(`<h1 id="liteyuki-comm-event" tabindex="-1"><a class="header-anchor" href="#liteyuki-comm-event"><span>liteyuki.comm.event</span></a></h1><p><strong>Description</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/7/26 下午10:47 @Author : snowykami @Email : snowykami@outlook.com @File : event.py @Software: PyCharm</p><h3 id="class-event" tabindex="-1"><a class="header-anchor" href="#class-event"><span><em><strong>class</strong></em> <code>Event</code></span></a></h3><h4 id="def-init-self-name-str-data-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-init-self-name-str-data-dict-str-any"><span><em><strong>def</strong></em> <code>__init__(self, name: str, data: dict[str, Any])</code></span></a></h4><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/event.py#L19" target="_blank">View on 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> name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> data<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 punctuation">:</span>
self<span class="token punctuation">.</span>name <span class="token operator">=</span> name
self<span class="token punctuation">.</span>data <span class="token operator">=</span> data
</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></div></details>`,6),i=[o];function c(p,l){return t(),n("div",null,i)}const m=e(s,[["render",c],["__file","event.html.vue"]]),d=JSON.parse('{"path":"/en/dev/api/comm/event.html","title":"liteyuki.comm.event","lang":"en-US","frontmatter":{"title":"liteyuki.comm.event","lastUpdated":false,"description":"liteyuki.comm.event Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/26 10:47 @Author : snowykami @Email : snowykami@outlook.com @File :...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/comm/event.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/comm/event.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.comm.event"}],["meta",{"property":"og:description","content":"liteyuki.comm.event Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/26 10:47 @Author : snowykami @Email : snowykami@outlook.com @File :..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.comm.event\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class Event","slug":"class-event","link":"#class-event","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.24,"words":73},"filePathRelative":"en/dev/api/comm/event.md","localizedDate":"August 21, 2024","autoDesc":true}');export{m as comp,d as data};

View File

@ -0,0 +1,4 @@
import{_ as e,o as t,c as n,e as a}from"./app-BvUYPzLF.js";const s={},o=a(`<h1 id="liteyuki-comm-event" tabindex="-1"><a class="header-anchor" href="#liteyuki-comm-event"><span>liteyuki.comm.event</span></a></h1><p><strong>说明</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/7/26 下午10:47 @Author : snowykami @Email : snowykami@outlook.com @File : event.py @Software: PyCharm</p><h3 id="class-event" tabindex="-1"><a class="header-anchor" href="#class-event"><span><em><strong>class</strong></em> <code>Event</code></span></a></h3><h4 id="def-init-self-name-str-data-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-init-self-name-str-data-dict-str-any"><span><em><strong>def</strong></em> <code>__init__(self, name: str, data: dict[str, Any])</code></span></a></h4><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/comm/event.py#L19" 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> name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> data<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 punctuation">:</span>
self<span class="token punctuation">.</span>name <span class="token operator">=</span> name
self<span class="token punctuation">.</span>data <span class="token operator">=</span> data
</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></div></details>`,6),i=[o];function p(c,l){return t(),n("div",null,i)}const m=e(s,[["render",p],["__file","event.html.vue"]]),d=JSON.parse('{"path":"/dev/api/comm/event.html","title":"liteyuki.comm.event","lang":"zh-CN","frontmatter":{"title":"liteyuki.comm.event","lastUpdated":false,"description":"liteyuki.comm.event : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/26 10:47 @Author : snowykami @Email : snowykami@outlook.com @File : event.py...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/comm/event.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/comm/event.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":"liteyuki.comm.event"}],["meta",{"property":"og:description","content":"liteyuki.comm.event : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/26 10:47 @Author : snowykami @Email : snowykami@outlook.com @File : event.py..."}],["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.comm.event\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class Event","slug":"class-event","link":"#class-event","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":4}]},"readingTime":{"minutes":0.26,"words":77},"filePathRelative":"dev/api/comm/event.md","localizedDate":"2024819","autoDesc":true}');export{m as comp,d as data};

View File

@ -0,0 +1,38 @@
import{_ as s,o as n,c as a,e}from"./app-BvUYPzLF.js";const t={},p=e(`<h1 id="liteyuki-message-event" tabindex="-1"><a class="header-anchor" href="#liteyuki-message-event"><span>liteyuki.message.event</span></a></h1><p><strong>说明</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/8/19 下午10:47 @Author : snowykami @Email : snowykami@outlook.com @File : event.py @Software: PyCharm</p><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><h4 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-optional-channel-messageevent-none-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-optional-channel-messageevent-none-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: Optional[Channel[MessageEvent]] = None, data: Optional[dict[str, Any]] = None)</code></span></a></h4><p><strong>说明</strong>: 轻雪抽象消息事件</p><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/message/event.py#L18" 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> 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> Optional<span class="token punctuation">[</span>Channel<span class="token punctuation">[</span><span class="token string">&#39;MessageEvent&#39;</span><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> 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>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
轻雪抽象消息事件
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: 附加数据
&quot;&quot;&quot;</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
self<span class="token punctuation">.</span>user_id <span class="token operator">=</span> user_id
self<span class="token punctuation">.</span>receive_channel <span class="token operator">=</span> receive_channel
</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><h4 id="def-reply-self-message-str-dict-str-any" tabindex="-1"><a class="header-anchor" href="#def-reply-self-message-str-dict-str-any"><span><em><strong>def</strong></em> <code>reply(self, message: str | dict[str, Any])</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>message:</li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/message/event.py#L66" 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">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">&quot;&quot;&quot;
回复消息
Args:
message:
Returns:
&quot;&quot;&quot;</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">&#39;&#39;</span><span class="token punctuation">,</span> data<span class="token operator">=</span><span class="token punctuation">{</span><span class="token string">&#39;message&#39;</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> user_id<span class="token operator">=</span>self<span class="token punctuation">.</span>user_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 boolean">None</span><span class="token punctuation">)</span>
<span class="token keyword">if</span> self<span class="token punctuation">.</span>receive_channel<span class="token punctuation">:</span>
self<span class="token punctuation">.</span>receive_channel<span class="token punctuation">.</span>send<span class="token punctuation">(</span>reply_event<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></div></details>`,12),o=[p];function i(l,c){return n(),a("div",null,o)}const r=s(t,[["render",i],["__file","event.html.vue"]]),d=JSON.parse('{"path":"/dev/api/message/event.html","title":"liteyuki.message.event","lang":"zh-CN","frontmatter":{"title":"liteyuki.message.event","lastUpdated":false,"description":"liteyuki.message.event : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/19 10:47 @Author : snowykami @Email : snowykami@outlook.com @File : event...","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":"liteyuki.message.event : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/19 10:47 @Author : snowykami @Email : snowykami@outlook.com @File : event..."}],["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.event\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class MessageEvent","slug":"class-messageevent","link":"#class-messageevent","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":1.08,"words":324},"filePathRelative":"dev/api/message/event.md","localizedDate":"2024821","autoDesc":true}');export{r as comp,d as data};

View File

@ -0,0 +1 @@
import{_ as i,o,c as n,b as e,d as t}from"./app-BvUYPzLF.js";const c={},a=e("h1",{id:"liteyuki-exception",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#liteyuki-exception"},[e("span",null,"liteyuki.exception")])],-1),p=e("p",null,[e("strong",null,"说明"),t(": exception模块包含了liteyuki运行中的所有错误")],-1),l=e("h3",{id:"class-liteyukiexception-baseexception",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#class-liteyukiexception-baseexception"},[e("span",null,[e("em",null,[e("strong",null,"class")]),t(),e("code",null,"LiteyukiException(BaseException)")])])],-1),s=[a,p,l];function r(d,u){return o(),n("div",null,s)}const x=i(c,[["render",r],["__file","exception.html.vue"]]),h=JSON.parse('{"path":"/dev/api/exception.html","title":"liteyuki.exception","lang":"zh-CN","frontmatter":{"title":"liteyuki.exception","lastUpdated":false,"description":"liteyuki.exception 说明: exception模块包含了liteyuki运行中的所有错误 class LiteyukiException(BaseException)","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/exception.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/exception.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki.exception"}],["meta",{"property":"og:description","content":"liteyuki.exception 说明: exception模块包含了liteyuki运行中的所有错误 class LiteyukiException(BaseException)"}],["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.exception\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class LiteyukiException(BaseException)","slug":"class-liteyukiexception-baseexception","link":"#class-liteyukiexception-baseexception","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.08,"words":25},"filePathRelative":"dev/api/exception.md","localizedDate":"2024年8月19日","autoDesc":true}');export{x as comp,h as data};

View File

@ -0,0 +1 @@
import{_ as i,o,c as n,b as e,d as t}from"./app-BvUYPzLF.js";const c={},a=e("h1",{id:"liteyuki-exception",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#liteyuki-exception"},[e("span",null,"liteyuki.exception")])],-1),p=e("p",null,[e("strong",null,"Description"),t(": exception模块包含了liteyuki运行中的所有错误")],-1),l=e("h3",{id:"class-liteyukiexception-baseexception",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#class-liteyukiexception-baseexception"},[e("span",null,[e("em",null,[e("strong",null,"class")]),t(),e("code",null,"LiteyukiException(BaseException)")])])],-1),s=[a,p,l];function r(d,u){return o(),n("div",null,s)}const x=i(c,[["render",r],["__file","exception.html.vue"]]),h=JSON.parse('{"path":"/en/dev/api/exception.html","title":"liteyuki.exception","lang":"en-US","frontmatter":{"title":"liteyuki.exception","lastUpdated":false,"description":"liteyuki.exception Description: exception模块包含了liteyuki运行中的所有错误 class LiteyukiException(BaseException)","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/exception.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/exception.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.exception"}],["meta",{"property":"og:description","content":"liteyuki.exception Description: exception模块包含了liteyuki运行中的所有错误 class LiteyukiException(BaseException)"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.exception\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class LiteyukiException(BaseException)","slug":"class-liteyukiexception-baseexception","link":"#class-liteyukiexception-baseexception","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.08,"words":24},"filePathRelative":"en/dev/api/exception.md","localizedDate":"August 21, 2024","autoDesc":true}');export{x as comp,h as data};

View File

@ -0,0 +1,5 @@
import{_ as t,o as e,c as a,e as n}from"./app-BvUYPzLF.js";const s={},r=n(`<h2 id="功能插件命令" tabindex="-1"><a class="header-anchor" href="#功能插件命令"><span>功能插件命令</span></a></h2><h3 id="轻雪天气liteyuki-weather" tabindex="-1"><a class="header-anchor" href="#轻雪天气liteyuki-weather"><span><strong>轻雪天气<code>liteyuki_weather</code></strong></span></a></h3><p>查询实时天气,支持绑定城市,支持中英文城市名,支持多个关键词查询。</p><p>配置项</p><div class="language-yaml line-numbers-mode" data-ext="yml" data-title="yml"><pre class="language-yaml"><code><span class="token key atrule">weather_key</span><span class="token punctuation">:</span> <span class="token string">&quot;&quot;</span> <span class="token comment"># 和风天气的天气key会自动判断key版本</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p></p><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code>weather <span class="token operator">&lt;</span>keywords<span class="token punctuation">..</span>.<span class="token operator">&gt;</span> <span class="token comment"># Keywords</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>&quot; &quot;, &quot;weather Tokyo Shinjuku&quot;</p><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code>bind-city <span class="token operator">&lt;</span>keywords<span class="token punctuation">..</span>.<span class="token operator">&gt;</span> <span class="token comment"># Keywords</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p></p><h4 id="" tabindex="-1"><a class="header-anchor" href="#"><span></span></a></h4><table><thead><tr><th style="text-align:center;"></th><th style="text-align:left;"></th></tr></thead><tbody><tr><td style="text-align:center;">weather</td><td style="text-align:left;"></td></tr><tr><td style="text-align:center;">bind-city</td><td style="text-align:left;"></td></tr></tbody></table><hr><h3 id="liteyuki-statistics" tabindex="-1"><a class="header-anchor" href="#liteyuki-statistics"><span><strong><code>liteyuki_statistics</code></strong></span></a></h3><p> </p><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code>statistic message <span class="token parameter variable">--duration</span> <span class="token operator">&lt;</span>duration<span class="token operator">&gt;</span> <span class="token parameter variable">--period</span> <span class="token operator">&lt;</span>period<span class="token operator">&gt;</span> <span class="token parameter variable">--group</span> <span class="token punctuation">[</span>current<span class="token operator">|</span>group_id<span class="token punctuation">]</span> <span class="token parameter variable">--bot</span> <span class="token punctuation">[</span>current<span class="token operator">|</span>bot_id<span class="token punctuation">]</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>: Bot, <code>period</code>, <code>duration</code></p><table><thead><tr><th style="text-align:center;"></th><th style="text-align:center;"></th></tr></thead><tbody><tr><td style="text-align:center;">duration</td><td style="text-align:center;">使: <code>1d</code>(), <code>1h</code>(), <code>45m</code>(), <code>14s</code>()</td></tr><tr><td style="text-align:center;">period</td><td style="text-align:center;">使: <code>1d</code>(), <code>1h</code>(), <code>45m</code>(), <code>14s</code>()</td></tr><tr><td style="text-align:center;">group</td><td style="text-align:center;"><code>current</code> () <code>group_id</code> (QQ)</td></tr><tr><td style="text-align:center;">bot</td><td style="text-align:center;"><code>current</code> (Bot) <code>bot_id</code></td></tr></tbody></table><h4 id="-1" tabindex="-1"><a class="header-anchor" href="#-1"><span></span></a></h4><table><thead><tr><th style="text-align:center;"></th><th style="text-align:center;"></th></tr></thead><tbody><tr><td style="text-align:center;"><code>statistic</code></td><td style="text-align:center;">stat</td></tr><tr><td style="text-align:center;"><code>message</code></td><td style="text-align:center;">m</td></tr><tr><td style="text-align:center;"><code>--duration</code></td><td style="text-align:center;">-d</td></tr><tr><td style="text-align:center;">--period\`</td><td style="text-align:center;">-p</td></tr><tr><td style="text-align:center;"><code>--group</code></td><td style="text-align:center;">-g</td></tr><tr><td style="text-align:center;"><code>--bot</code></td><td style="text-align:center;">-b</td></tr><tr><td style="text-align:center;"><code>current</code></td><td style="text-align:center;">c</td></tr></tbody></table>`,20),o=[r];function d(i,l){return e(),a("div",null,o)}const p=t(s,[["render",d],["__file","extra_command.html.vue"]]),u=JSON.parse('{"path":"/usage/extra_command.html","title":"","lang":"zh-CN","frontmatter":{"title":"","icon":"comment","order":2,"category":"使","description":" liteyuki_weather \\" \\", \\"weather Tokyo Shinjuku\\" liteyuki_statistics : ...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/usage/extra_command.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/usage/extra_command.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":""}],["meta",{"property":"og:description","content":" liteyuki_weather \\" \\", \\"weather Tokyo Shinjuku\\" liteyuki_statistics : ..."}],["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-07-01T08:00:46.000Z"}],["meta",{"property":"article:modified_time","content":"2024-07-01T08:00:46.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-07-01T08:00:46.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":2,"title":"","slug":"","link":"#","children":[{"level":3,"title":"liteyuki_weather","slug":"liteyuki-weather","link":"#liteyuki-weather","children":[]},{"level":3,"title":"liteyuki_statistics","slug":"liteyuki-statistics","link":"#liteyuki-statistics","children":[]}]}],"git":{"createdTime":1711598703000,"updatedTime":1719820846000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":8},{"name":"Nanaloveyuki","email":"136328617+Nanaloveyuki@users.noreply.github.com","commits":1}]},"readingTime":{"minutes":0.95,"words":286},"filePathRelative":"usage/extra_command.md","localizedDate":"2024328","autoDesc":true}');export{p as comp,u as data};

View File

@ -0,0 +1,5 @@
import{_ as t,o as e,c as a,e as n}from"./app-BvUYPzLF.js";const s={},r=n(`<h2 id="功能插件命令" tabindex="-1"><a class="header-anchor" href="#功能插件命令"><span>功能插件命令</span></a></h2><h3 id="轻雪天气liteyuki-weather" tabindex="-1"><a class="header-anchor" href="#轻雪天气liteyuki-weather"><span><strong>轻雪天气<code>liteyuki_weather</code></strong></span></a></h3><p>查询实时天气,支持绑定城市,支持中英文城市名,支持多个关键词查询。</p><p>配置项</p><div class="language-yaml line-numbers-mode" data-ext="yml" data-title="yml"><pre class="language-yaml"><code><span class="token key atrule">weather_key</span><span class="token punctuation">:</span> <span class="token string">&quot;&quot;</span> <span class="token comment"># 和风天气的天气key会自动判断key版本</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p></p><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code>weather <span class="token operator">&lt;</span>keywords<span class="token punctuation">..</span>.<span class="token operator">&gt;</span> <span class="token comment"># Keywords</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>&quot; &quot;, &quot;weather Tokyo Shinjuku&quot;</p><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code>bind-city <span class="token operator">&lt;</span>keywords<span class="token punctuation">..</span>.<span class="token operator">&gt;</span> <span class="token comment"># Keywords</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p></p><h4 id="" tabindex="-1"><a class="header-anchor" href="#"><span></span></a></h4><table><thead><tr><th style="text-align:center;"></th><th style="text-align:left;"></th></tr></thead><tbody><tr><td style="text-align:center;">weather</td><td style="text-align:left;"></td></tr><tr><td style="text-align:center;">bind-city</td><td style="text-align:left;"></td></tr></tbody></table><hr><h3 id="liteyuki-statistics" tabindex="-1"><a class="header-anchor" href="#liteyuki-statistics"><span><strong><code>liteyuki_statistics</code></strong></span></a></h3><p> </p><div class="language-bash line-numbers-mode" data-ext="sh" data-title="sh"><pre class="language-bash"><code>statistic message <span class="token parameter variable">--duration</span> <span class="token operator">&lt;</span>duration<span class="token operator">&gt;</span> <span class="token parameter variable">--period</span> <span class="token operator">&lt;</span>period<span class="token operator">&gt;</span> <span class="token parameter variable">--group</span> <span class="token punctuation">[</span>current<span class="token operator">|</span>group_id<span class="token punctuation">]</span> <span class="token parameter variable">--bot</span> <span class="token punctuation">[</span>current<span class="token operator">|</span>bot_id<span class="token punctuation">]</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>: Bot, <code>period</code>, <code>duration</code></p><table><thead><tr><th style="text-align:center;"></th><th style="text-align:center;"></th></tr></thead><tbody><tr><td style="text-align:center;">duration</td><td style="text-align:center;">使: <code>1d</code>(), <code>1h</code>(), <code>45m</code>(), <code>14s</code>()</td></tr><tr><td style="text-align:center;">period</td><td style="text-align:center;">使: <code>1d</code>(), <code>1h</code>(), <code>45m</code>(), <code>14s</code>()</td></tr><tr><td style="text-align:center;">group</td><td style="text-align:center;"><code>current</code> () <code>group_id</code> (QQ)</td></tr><tr><td style="text-align:center;">bot</td><td style="text-align:center;"><code>current</code> (Bot) <code>bot_id</code></td></tr></tbody></table><h4 id="-1" tabindex="-1"><a class="header-anchor" href="#-1"><span></span></a></h4><table><thead><tr><th style="text-align:center;"></th><th style="text-align:center;"></th></tr></thead><tbody><tr><td style="text-align:center;"><code>statistic</code></td><td style="text-align:center;">stat</td></tr><tr><td style="text-align:center;"><code>message</code></td><td style="text-align:center;">m</td></tr><tr><td style="text-align:center;"><code>--duration</code></td><td style="text-align:center;">-d</td></tr><tr><td style="text-align:center;">--period\`</td><td style="text-align:center;">-p</td></tr><tr><td style="text-align:center;"><code>--group</code></td><td style="text-align:center;">-g</td></tr><tr><td style="text-align:center;"><code>--bot</code></td><td style="text-align:center;">-b</td></tr><tr><td style="text-align:center;"><code>current</code></td><td style="text-align:center;">c</td></tr></tbody></table>`,20),o=[r];function d(i,l){return e(),a("div",null,o)}const p=t(s,[["render",d],["__file","extra_command.html.vue"]]),h=JSON.parse('{"path":"/en/usage/extra_command.html","title":"Extra Commands","lang":"en-US","frontmatter":{"title":"Extra Commands","icon":"comment","order":2,"category":"usage","description":" liteyuki_weather \\" \\", \\"weather Tokyo Shinjuku\\" liteyuki_statistics : ...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/usage/extra_command.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/usage/extra_command.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"Extra Commands"}],["meta",{"property":"og:description","content":" liteyuki_weather \\" \\", \\"weather Tokyo Shinjuku\\" liteyuki_statistics : ..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-16T18:24:25.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-16T18:24:25.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"Extra Commands\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-16T18:24:25.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":2,"title":"","slug":"","link":"#","children":[{"level":3,"title":"liteyuki_weather","slug":"liteyuki-weather","link":"#liteyuki-weather","children":[]},{"level":3,"title":"liteyuki_statistics","slug":"liteyuki-statistics","link":"#liteyuki-statistics","children":[]}]}],"git":{"createdTime":1723829277000,"updatedTime":1723832665000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.94,"words":281},"filePathRelative":"en/usage/extra_command.md","localizedDate":"August 16, 2024","autoDesc":true}');export{p as comp,h as data};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

BIN
assets/fonts/ColorTube.woff Normal file

Binary file not shown.

66
assets/giscus-7BMGhbDA.js Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
assets/icon/chrome-192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
assets/icon/chrome-512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
assets/icon/ms-icon-144.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 26 KiB

1
assets/image/blog.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.8 KiB

1
assets/image/box.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" class="icon" viewBox="0 0 1024 1024"><path fill="#FDD7AD" d="M512 0 335.448 88.272l-70.616 35.312-70.624 35.312-176.552 88.28v529.648L512 1024l494.344-247.176V247.176z"/><path fill="#CBB292" d="m759.176 370.76-70.624 35.304-494.344-247.168 70.624-35.312zM512 494.344V1024L17.656 776.824V247.176z"/><path fill="#7F6E5D" d="M1006.344 247.168v529.656L512 1024V494.344l176.552-88.28v70.624l141.24-70.624v-70.616z"/><path fill="#7F5B53" d="M829.792 335.448v70.624L688.56 476.68v-70.624z"/><path fill="#CBB292" d="m829.792 335.448-70.624 35.312-494.344-247.176 70.624-35.312z"/><path fill="#2C3E50" d="m682.52 550.32 157.032-78.512a17.656 17.656 0 0 1 25.552 15.792v9.32a52.96 52.96 0 0 1-29.28 47.376L678.8 622.8a17.656 17.656 0 0 1-25.552-15.792v-9.312a52.96 52.96 0 0 1 29.28-47.376z"/></svg>

After

Width:  |  Height:  |  Size: 854 B

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024"><defs><linearGradient id="a" x1="522.593" x2="522.593" y1="-70.302" y2="-335.937" gradientUnits="userSpaceOnUse" spreadMethod="pad"><stop offset="0" stop-color="#fe5d5a" stop-opacity=".1"/><stop offset=".908" stop-color="#ef1220" stop-opacity=".5"/></linearGradient><linearGradient id="b" x1="107.12" x2="935.038" y1="-373.67" y2="-373.67" gradientUnits="userSpaceOnUse" spreadMethod="pad"><stop offset="0" stop-color="#ff5e59"/><stop offset="1" stop-color="#f01422"/></linearGradient><linearGradient id="c" x1="519.405" x2="519.405" y1="-195.547" y2="-726.816" gradientUnits="userSpaceOnUse" spreadMethod="pad"><stop offset="0" stop-color="#ffe2e2"/><stop offset=".888" stop-color="#ff8e8e"/></linearGradient><linearGradient id="d" x1="191.5" x2="483.9" y1="-564.9" y2="-564.9" gradientUnits="userSpaceOnUse" spreadMethod="pad"><stop offset="0" stop-color="#e92700" stop-opacity=".3"/><stop offset=".013" stop-color="#ef1220" stop-opacity=".2"/></linearGradient><linearGradient id="e" x1="403.502" x2="253.121" y1="-847.32" y2="-586.853" gradientUnits="userSpaceOnUse" spreadMethod="pad"><stop offset="0" stop-color="#ff5e59"/><stop offset=".201" stop-color="#f01422"/></linearGradient><linearGradient id="f" x1="330.485" x2="330.485" y1="-801.787" y2="-625.789" gradientUnits="userSpaceOnUse" spreadMethod="pad"><stop offset="0" stop-color="#ff5e59"/><stop offset=".201" stop-color="#f01422"/></linearGradient><linearGradient id="g" x1="397.351" x2="256.845" y1="-647.231" y2="-890.596" gradientUnits="userSpaceOnUse" spreadMethod="pad"><stop offset="0" stop-color="#ffa6a6"/><stop offset=".908" stop-color="#ff6b5d"/></linearGradient></defs><path fill="url(#a)" d="M501.2 662.3 327.6 763.8c-13.9 8.1-14.2 28.1-.5 36.7l179.1 97.7c10.9 5.9 24.1 5.9 34.9-.1l177-97.9c13.6-8.5 13.4-28.3-.3-36.5l-168.4-101c-14.8-9-33.3-9.1-48.2-.4Z"/><path fill="#f63037" d="m110.2 525.7-3.1 77.6 57.5 18.5L184 519.4Z"/><path fill="url(#b)" d="m476.6 363.5-328 154.6c-21 42.7-55.4 65.4-35.5 103.5 4.2 8 9.4 14.4 15.4 18.1l358.2 195.5c21.8 11.9 48.1 11.8 69.8-.2l354-195.8c27.2-16.9 34.8-90.3 7.3-106.8L573 364.1c-29.7-17.8-66.6-18-96.4-.6Z"/><path fill="url(#c)" d="M476.6 298.7 129.4 501.6c-27.8 16.3-28.4 56.3-1 73.3l358.2 195.5c21.8 11.9 48.1 11.8 69.8-.2l354-195.8c27.2-16.9 26.9-56.6-.6-73.1L573 299.3c-29.7-17.8-66.6-18-96.4-.6Z"/><path fill="#ff8989" fill-opacity=".31" d="m481.2 387.8 39.4 123.4c1.1 3.4 4 6 7.6 6.6l173.4 30.4-33-118.3c-.9-3.3-3.6-5.8-7-6.5l-180.4-35.6ZM327 499.2l40.4 101.1L496.7 525c2.5-1.5 3.7-4.5 2.7-7.3l-36-106.8-127.6 65c-8.6 4.3-12.4 14.4-8.8 23.3ZM523.8 540.5l-140.3 77.2L567.2 659c3.2.7 6.6.1 9.3-1.6l134.6-85-174.7-33.8c-4.3-1-8.7-.3-12.6 1.9Z"/><path fill="url(#d)" d="M483.9 406.1c0 35.46-65.46 64.2-146.2 64.2s-146.2-28.74-146.2-64.2c0-35.46 65.46-64.2 146.2-64.2s146.2 28.74 146.2 64.2Z"/><path fill="url(#e)" d="m254.2 188.4-123 83.1c-1.8 1.3-2.6 3.6-1.8 5.7l39.1 110.6c.6 1.7 2 2.9 3.8 3.2l221.8 40.5c1.3.3 2.7-.1 3.7-.8l131.7-93.6c1.9-1.4 2.6-3.9 1.7-6.1l-49.4-107c-.6-1.5-2.1-2.6-3.7-2.8l-220.3-33.5c-1.3-.2-2.6.1-3.6.7Z"/><path fill="url(#f)" d="m528.6 274.5 3 59.1-205 65.6-177.2-72.7-20-49.2 1.9-54.1Z"/><path fill="url(#g)" d="m250.6 138-112.3 76c-6 4.1-8.5 11.7-6.1 18.5l34.2 96.6c1.9 5.4 6.6 9.3 12.1 10.4l211 38.5c4.3.7 8.6-.2 12.1-2.7l120.5-85.5c6.3-4.4 8.4-12.7 5.3-19.7l-43.1-93.5c-2.2-4.9-6.8-8.3-12.1-9.1L262 135.6c-4-.7-8 .2-11.4 2.4Z"/><path fill="#fff" d="m419.8 252.8-79-11-29-57.7c-3.8-7.6-13.2-10.7-20.8-6.9-7.6 3.8-10.7 13.2-6.9 20.8l26.6 52.9-61.8 42.2c-7.1 4.8-8.9 14.5-4.1 21.5 3 4.4 7.9 6.8 12.8 6.8 3 0 6-.9 8.7-2.7l68-46.4 81.1 11.2c.7.1 1.4.1 2.1.1 7.6 0 14.3-5.6 15.3-13.4 1.4-8.4-4.5-16.2-13-17.4Z"/></svg>

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -0,0 +1 @@
<svg width="98" height="96" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="#24292f"/></svg>

After

Width:  |  Height:  |  Size: 963 B

View File

@ -0,0 +1 @@
<svg width="98" height="96" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 960 B

1
assets/image/layout.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" class="icon" viewBox="0 0 1536 1024"><path fill="#1296db" d="M1425.067.256H110.933A110.933 110.933 0 0 0 0 110.848v723.627a110.933 110.933 0 0 0 110.933 110.933h1314.39c61.269 0 110.933-49.75 110.677-110.677V110.848A110.933 110.933 0 0 0 1425.067.256z" class="selected" data-spm-anchor-id="a313x.7781069.0.i4"/><path fill="#FFF" d="M664.747 723.797V435.883L517.12 620.373l-147.456-184.49v288l-148.053-67.158V221.781h147.626l147.627 184.576 147.541-184.576h147.627v565.76z"/><path d="M1024 0h426.667A85.333 85.333 0 0 1 1536 85.333v768a85.333 85.333 0 0 1-85.333 85.334H1024V0z" opacity=".1"/><path fill="#FFF" d="m1256.96 731.307-170.667-216.491h113.75V304.64h113.749v210.176h113.835z" opacity=".5"/></svg>

After

Width:  |  Height:  |  Size: 771 B

61
assets/index-Cw_AvLww.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
import{_ as t,r as n,o,c as a,a as s}from"./app-BvUYPzLF.js";const p={};function l(r,i){const e=n("Catalog");return o(),a("div",null,[s(e)])}const m=t(p,[["render",l],["__file","index.html.vue"]]),g=JSON.parse('{"path":"/en/dev/api/plugins/","title":"Plugins","lang":"zh-CN","frontmatter":{"title":"Plugins","article":false,"feed":false,"sitemap":false,"head":[["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/plugins/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"Plugins"}],["meta",{"property":"og:type","content":"website"}],["meta",{"property":"og:locale","content":"zh-CN"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"WebPage\\",\\"name\\":\\"Plugins\\"}"]]},"headers":[],"git":{},"readingTime":{"minutes":0,"words":1},"filePathRelative":null}');export{m as comp,g as data};

View File

@ -0,0 +1,231 @@
import{_ as n,o as s,c as a,e as t}from"./app-BvUYPzLF.js";const e={},i=t(`<h1 id="liteyuki-bot" tabindex="-1"><a class="header-anchor" href="#liteyuki-bot"><span>liteyuki.bot</span></a></h1><h3 id="class-liteyukibot" tabindex="-1"><a class="header-anchor" href="#class-liteyukibot"><span><em><strong>class</strong></em> <code>LiteyukiBot</code></span></a></h3><h4 id="def-init-self-args-kwargs-none" tabindex="-1"><a class="header-anchor" href="#def-init-self-args-kwargs-none"><span><em><strong>def</strong></em> <code>__init__(self, *args, **kwargs) -&gt; None</code></span></a></h4><p><strong>说明</strong>: 初始化轻雪实例</p><p><strong>参数</strong>:</p><blockquote><ul><li>*args:</li><li>**kwargs: 配置</li></ul></blockquote><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L27" 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> <span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<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:
*args:
**kwargs: 配置
&quot;&quot;&quot;</span>
<span class="token string">&#39;常规操作&#39;</span>
print_logo<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">global</span> _BOT_INSTANCE
_BOT_INSTANCE <span class="token operator">=</span> self
<span class="token string">&#39;配置&#39;</span>
self<span class="token punctuation">.</span>config<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 operator">=</span> kwargs
<span class="token string">&#39;初始化&#39;</span>
self<span class="token punctuation">.</span>init<span class="token punctuation">(</span><span class="token operator">**</span>self<span class="token punctuation">.</span>config<span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">&#39;Liteyuki is initializing...&#39;</span><span class="token punctuation">)</span>
<span class="token string">&#39;生命周期管理&#39;</span>
self<span class="token punctuation">.</span>lifespan <span class="token operator">=</span> Lifespan<span class="token punctuation">(</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>process_manager<span class="token punctuation">:</span> ProcessManager <span class="token operator">=</span> ProcessManager<span class="token punctuation">(</span>lifespan<span class="token operator">=</span>self<span class="token punctuation">.</span>lifespan<span class="token punctuation">)</span>
<span class="token string">&#39;事件循环&#39;</span>
self<span class="token punctuation">.</span>loop <span class="token operator">=</span> asyncio<span class="token punctuation">.</span>new_event_loop<span class="token punctuation">(</span><span class="token punctuation">)</span>
asyncio<span class="token punctuation">.</span>set_event_loop<span class="token punctuation">(</span>self<span class="token punctuation">.</span>loop<span class="token punctuation">)</span>
self<span class="token punctuation">.</span>stop_event <span class="token operator">=</span> threading<span class="token punctuation">.</span>Event<span class="token punctuation">(</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>call_restart_count <span class="token operator">=</span> <span class="token number">0</span>
<span class="token string">&#39;加载插件加载器&#39;</span>
load_plugin<span class="token punctuation">(</span><span class="token string">&#39;liteyuki.plugins.plugin_loader&#39;</span><span class="token punctuation">)</span>
<span class="token string">&#39;信号处理&#39;</span>
signal<span class="token punctuation">.</span>signal<span class="token punctuation">(</span>signal<span class="token punctuation">.</span>SIGINT<span class="token punctuation">,</span> self<span class="token punctuation">.</span>_handle_exit<span class="token punctuation">)</span>
signal<span class="token punctuation">.</span>signal<span class="token punctuation">(</span>signal<span class="token punctuation">.</span>SIGTERM<span class="token punctuation">,</span> self<span class="token punctuation">.</span>_handle_exit<span class="token punctuation">)</span>
atexit<span class="token punctuation">.</span>register<span class="token punctuation">(</span>self<span class="token punctuation">.</span>process_manager<span class="token punctuation">.</span>terminate_all<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 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><h4 id="async-def-run-self" tabindex="-1"><a class="header-anchor" href="#async-def-run-self"><span><em><strong>async def</strong></em> <code>_run(self)</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L65" 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><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
启动逻辑
&quot;&quot;&quot;</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>before_start<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>process_manager<span class="token punctuation">.</span>start_all<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>after_start<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>keep_alive<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></div></details><h4 id="def-run-self" tabindex="-1"><a class="header-anchor" href="#def-run-self"><span><em><strong>def</strong></em> <code>run(self)</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L74" 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">run</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
外部启动接口
&quot;&quot;&quot;</span>
<span class="token keyword">try</span><span class="token punctuation">:</span>
asyncio<span class="token punctuation">.</span>run<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_run<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">except</span> KeyboardInterrupt<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">&#39;Liteyuki is stopping...&#39;</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></div></details><h4 id="async-def-keep-alive-self" tabindex="-1"><a class="header-anchor" href="#async-def-keep-alive-self"><span><em><strong>async def</strong></em> <code>keep_alive(self)</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L83" 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">keep_alive</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
保持轻雪运行
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">try</span><span class="token punctuation">:</span>
<span class="token keyword">while</span> <span class="token keyword">not</span> self<span class="token punctuation">.</span>stop_event<span class="token punctuation">.</span>is_set<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
time<span class="token punctuation">.</span>sleep<span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">)</span>
<span class="token keyword">except</span> KeyboardInterrupt<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">&#39;Liteyuki is stopping...&#39;</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>stop<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-exit-self-signum-frame" tabindex="-1"><a class="header-anchor" href="#def-handle-exit-self-signum-frame"><span><em><strong>def</strong></em> <code>_handle_exit(self, signum, frame)</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>signum:</li><li>frame:</li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L96" 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_exit</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> signum<span class="token punctuation">,</span> frame<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
信号处理
Args:
signum:
frame:
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">&#39;Received signal, stopping all processes.&#39;</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>stop<span class="token punctuation">(</span><span class="token punctuation">)</span>
sys<span class="token punctuation">.</span>exit<span class="token punctuation">(</span><span class="token number">0</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></div></details><h4 id="def-restart-self-delay-int-0" tabindex="-1"><a class="header-anchor" href="#def-restart-self-delay-int-0"><span><em><strong>def</strong></em> <code>restart(self, delay: int = 0)</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L110" 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">restart</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> delay<span class="token punctuation">:</span> <span class="token builtin">int</span><span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
重启轻雪本体
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> self<span class="token punctuation">.</span>call_restart_count <span class="token operator">&lt;</span> <span class="token number">1</span><span class="token punctuation">:</span>
executable <span class="token operator">=</span> sys<span class="token punctuation">.</span>executable
args <span class="token operator">=</span> sys<span class="token punctuation">.</span>argv
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">&#39;Restarting LiteyukiBot...&#39;</span><span class="token punctuation">)</span>
time<span class="token punctuation">.</span>sleep<span class="token punctuation">(</span>delay<span class="token punctuation">)</span>
<span class="token keyword">if</span> platform<span class="token punctuation">.</span>system<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token string">&#39;Windows&#39;</span><span class="token punctuation">:</span>
cmd <span class="token operator">=</span> <span class="token string">&#39;start&#39;</span>
<span class="token keyword">elif</span> platform<span class="token punctuation">.</span>system<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token string">&#39;Linux&#39;</span><span class="token punctuation">:</span>
cmd <span class="token operator">=</span> <span class="token string">&#39;nohup&#39;</span>
<span class="token keyword">elif</span> platform<span class="token punctuation">.</span>system<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token string">&#39;Darwin&#39;</span><span class="token punctuation">:</span>
cmd <span class="token operator">=</span> <span class="token string">&#39;open&#39;</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
cmd <span class="token operator">=</span> <span class="token string">&#39;nohup&#39;</span>
self<span class="token punctuation">.</span>process_manager<span class="token punctuation">.</span>terminate_all<span class="token punctuation">(</span><span class="token punctuation">)</span>
threading<span class="token punctuation">.</span>Thread<span class="token punctuation">(</span>target<span class="token operator">=</span>os<span class="token punctuation">.</span>system<span class="token punctuation">,</span> args<span class="token operator">=</span><span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>cmd<span class="token punctuation">}</span></span><span class="token string"> </span><span class="token interpolation"><span class="token punctuation">{</span>executable<span class="token punctuation">}</span></span><span class="token string"> </span><span class="token interpolation"><span class="token punctuation">{</span><span class="token string">&#39; &#39;</span><span class="token punctuation">.</span>join<span class="token punctuation">(</span>args<span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">&quot;</span></span><span class="token punctuation">,</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span>start<span class="token punctuation">(</span><span class="token punctuation">)</span>
sys<span class="token punctuation">.</span>exit<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>call_restart_count <span class="token operator">+=</span> <span class="token number">1</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 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-restart-process-self-name-optional-str-none" tabindex="-1"><a class="header-anchor" href="#def-restart-process-self-name-optional-str-none"><span><em><strong>def</strong></em> <code>restart_process(self, name: Optional[str] = None)</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>name: , None, </li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L135" 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">restart_process</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">:</span> Optional<span class="token punctuation">[</span><span class="token builtin">str</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>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
停止轻雪
Args:
name: 进程名称, 默认为None, 所有进程
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> name <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
chan_active <span class="token operator">=</span> get_channel<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;</span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string">-active&#39;</span></span><span class="token punctuation">)</span>
chan_active<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
<span class="token keyword">for</span> process_name <span class="token keyword">in</span> self<span class="token punctuation">.</span>process_manager<span class="token punctuation">.</span>processes<span class="token punctuation">:</span>
chan_active <span class="token operator">=</span> get_channel<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;</span><span class="token interpolation"><span class="token punctuation">{</span>process_name<span class="token punctuation">}</span></span><span class="token string">-active&#39;</span></span><span class="token punctuation">)</span>
chan_active<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token number">1</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><h4 id="def-init-self-args-kwargs" tabindex="-1"><a class="header-anchor" href="#def-init-self-args-kwargs"><span><em><strong>def</strong></em> <code>init(self, *args, **kwargs)</code></span></a></h4><p><strong></strong>: , </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L150" 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> <span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
初始化轻雪, 自动调用
Returns:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>init_logger<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></div></details><h4 id="def-init-logger-self" tabindex="-1"><a class="header-anchor" href="#def-init-logger-self"><span><em><strong>def</strong></em> <code>init_logger(self)</code></span></a></h4><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L158" 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_logger</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
init_log<span class="token punctuation">(</span>config<span class="token operator">=</span>self<span class="token punctuation">.</span>config<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></div></details><h4 id="def-stop-self" tabindex="-1"><a class="header-anchor" href="#def-stop-self"><span><em><strong>def</strong></em> <code>stop(self)</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L162" 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">stop</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
停止轻雪
Returns:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>stop_event<span class="token punctuation">.</span><span class="token builtin">set</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>loop<span class="token punctuation">.</span>stop<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></div></details><h4 id="def-on-before-start-self-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-start-self-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_start(self, func: LIFESPAN_FUNC)</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L171" 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">on_before_start</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册启动前的函数
Args:
func:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>on_before_start<span class="token punctuation">(</span>func<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></div></details><h4 id="def-on-after-start-self-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-start-self-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_start(self, func: LIFESPAN_FUNC)</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L182" 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">on_after_start</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册启动后的函数
Args:
func:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>on_after_start<span class="token punctuation">(</span>func<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></div></details><h4 id="def-on-after-shutdown-self-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-shutdown-self-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_shutdown(self, func: LIFESPAN_FUNC)</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L193" 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">on_after_shutdown</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册停止后的函数未实现
Args:
func:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>on_after_shutdown<span class="token punctuation">(</span>func<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></div></details><h4 id="def-on-before-process-shutdown-self-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-process-shutdown-self-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_process_shutdown(self, func: LIFESPAN_FUNC)</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L204" 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">on_before_process_shutdown</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册进程停止前的函数为子进程停止时调用
Args:
func:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>on_before_process_shutdown<span class="token punctuation">(</span>func<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></div></details><h4 id="def-on-before-process-restart-self-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-process-restart-self-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_process_restart(self, func: LIFESPAN_FUNC)</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L215" 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">on_before_process_restart</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册进程重启前的函数为子进程重启时调用
Args:
func:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>on_before_process_restart<span class="token punctuation">(</span>func<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></div></details><h4 id="def-on-after-restart-self-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-restart-self-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_restart(self, func: LIFESPAN_FUNC)</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L227" 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">on_after_restart</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册重启后的函数未实现
Args:
func:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>on_after_restart<span class="token punctuation">(</span>func<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></div></details><h3 id="def-get-bot-liteyukibot" tabindex="-1"><a class="header-anchor" href="#def-get-bot-liteyukibot"><span><em><strong>def</strong></em> <code>get_bot() -&gt; LiteyukiBot</code></span></a></h3><p><strong></strong>: </p><p><strong></strong>: LiteyukiBot: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L242" 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">get_bot</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LiteyukiBot<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取轻雪实例
Returns:
LiteyukiBot: 当前的轻雪实例
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token keyword">if</span> _BOT_INSTANCE <span class="token keyword">is</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
<span class="token keyword">raise</span> RuntimeError<span class="token punctuation">(</span><span class="token string">&#39;Liteyuki instance not initialized.&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> _BOT_INSTANCE
<span class="token keyword">else</span><span class="token punctuation">:</span>
<span class="token keyword">raise</span> RuntimeError<span class="token punctuation">(</span><span class="token string">&quot;Can&#39;t get bot instance in sub process.&quot;</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></div></details><h3 id="def-get-config-key-str-default-any-none-any" tabindex="-1"><a class="header-anchor" href="#def-get-config-key-str-default-any-none-any"><span><em><strong>def</strong></em> <code>get_config(key: str, default: Any = None) -&gt; Any</code></span></a></h3><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>key: </li><li>default: </li></ul></blockquote><p><strong></strong>: Any: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L258" 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">get_config</span><span class="token punctuation">(</span>key<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> default<span class="token punctuation">:</span> Any<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> Any<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取配置
Args:
key: 配置键
default: 默认值
Returns:
Any: 配置值
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>config<span class="token punctuation">.</span>get<span class="token punctuation">(</span>key<span class="token punctuation">,</span> default<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></div></details><h3 id="def-get-config-with-compat-key-str-compat-keys-tuple-str-default-any-none-any" tabindex="-1"><a class="header-anchor" href="#def-get-config-with-compat-key-str-compat-keys-tuple-str-default-any-none-any"><span><em><strong>def</strong></em> <code>get_config_with_compat(key: str, compat_keys: tuple[str], default: Any = None) -&gt; Any</code></span></a></h3><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>key: </li><li>compat_keys: </li><li>default: </li></ul></blockquote><p><strong></strong>: Any: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L271" 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">get_config_with_compat</span><span class="token punctuation">(</span>key<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> compat_keys<span class="token punctuation">:</span> <span class="token builtin">tuple</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">]</span><span class="token punctuation">,</span> default<span class="token punctuation">:</span> Any<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> Any<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取配置兼容旧版本
Args:
key: 配置键
compat_keys: 兼容键
default: 默认值
Returns:
Any: 配置值
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> key <span class="token keyword">in</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>config<span class="token punctuation">:</span>
<span class="token keyword">return</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>config<span class="token punctuation">[</span>key<span class="token punctuation">]</span>
<span class="token keyword">for</span> compat_key <span class="token keyword">in</span> compat_keys<span class="token punctuation">:</span>
<span class="token keyword">if</span> compat_key <span class="token keyword">in</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>config<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Config key &quot;</span><span class="token interpolation"><span class="token punctuation">{</span>compat_key<span class="token punctuation">}</span></span><span class="token string">&quot; will be deprecated, use &quot;</span><span class="token interpolation"><span class="token punctuation">{</span>key<span class="token punctuation">}</span></span><span class="token string">&quot; instead.&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">return</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>config<span class="token punctuation">[</span>compat_key<span class="token punctuation">]</span>
<span class="token keyword">return</span> default
</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></div></details><h3 id="def-print-logo" tabindex="-1"><a class="header-anchor" href="#def-print-logo"><span><em><strong>def</strong></em> <code>print_logo()</code></span></a></h3><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L291" 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">print_logo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">&#39;\\x1b[34m&#39;</span> <span class="token operator">+</span> <span class="token string">&#39;\\n __ ______ ________ ________ __ __ __ __ __ __ ______ \\n / | / |/ |/ |/ \\\\ / |/ | / |/ | / |/ |\\n $$ | $$$$$$/ $$$$$$$$/ $$$$$$$$/ $$ \\\\ /$$/ $$ | $$ |$$ | /$$/ $$$$$$/ \\n $$ | $$ | $$ | $$ |__ $$ \\\\/$$/ $$ | $$ |$$ |/$$/ $$ | \\n $$ | $$ | $$ | $$ | $$ $$/ $$ | $$ |$$ $$&lt; $$ | \\n $$ | $$ | $$ | $$$$$/ $$$$/ $$ | $$ |$$$$$ \\\\ $$ | \\n $$ |_____ _$$ |_ $$ | $$ |_____ $$ | $$ \\\\__$$ |$$ |$$ \\\\ _$$ |_ \\n $$ |/ $$ | $$ | $$ | $$ | $$ $$/ $$ | $$ |/ $$ |\\n $$$$$$$$/ $$$$$$/ $$/ $$$$$$$$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ \\n &#39;</span> <span class="token operator">+</span> <span class="token string">&#39;\\x1b[0m&#39;</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></div></details>`,85),o=[i];function p(l,c){return s(),a("div",null,o)}const r=n(e,[["render",p],["__file","index.html.vue"]]),d=JSON.parse('{"path":"/dev/api/bot/","title":"liteyuki.bot","lang":"zh-CN","frontmatter":{"title":"liteyuki.bot","lastUpdated":false,"description":"liteyuki.bot class LiteyukiBot def __init__(self, *args, **kwargs) -> None : : *args: **kwargs: GitHub async def _run(self) : GitHub de...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/bot/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/bot/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":"liteyuki.bot"}],["meta",{"property":"og:description","content":"liteyuki.bot class LiteyukiBot def __init__(self, *args, **kwargs) -> None : : *args: **kwargs: GitHub async def _run(self) : GitHub de..."}],["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.bot\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class LiteyukiBot","slug":"class-liteyukibot","link":"#class-liteyukibot","children":[]},{"level":3,"title":"def get_bot() -> LiteyukiBot","slug":"def-get-bot-liteyukibot","link":"#def-get-bot-liteyukibot","children":[]},{"level":3,"title":"def get_config(key: str, default: Any = None) -> Any","slug":"def-get-config-key-str-default-any-none-any","link":"#def-get-config-key-str-default-any-none-any","children":[]},{"level":3,"title":"def get_config_with_compat(key: str, compat_keys: tuple[str], default: Any = None) -> Any","slug":"def-get-config-with-compat-key-str-compat-keys-tuple-str-default-any-none-any","link":"#def-get-config-with-compat-key-str-compat-keys-tuple-str-default-any-none-any","children":[]},{"level":3,"title":"def print_logo()","slug":"def-print-logo","link":"#def-print-logo","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":6}]},"readingTime":{"minutes":5.1,"words":1529},"filePathRelative":"dev/api/bot/README.md","localizedDate":"2024819","autoDesc":true}');export{r as comp,d as data};

View File

@ -0,0 +1 @@
import{_ as t,r as o,o as a,c as n,a as r}from"./app-BvUYPzLF.js";const p={};function c(i,l){const e=o("Catalog");return a(),n("div",null,[r(e)])}const s=t(p,[["render",c],["__file","index.html.vue"]]),d=JSON.parse('{"path":"/dev/","title":"开发及贡献","lang":"zh-CN","frontmatter":{"title":"开发及贡献","index":false,"icon":"laptop-code","category":"开发","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"开发及贡献"}],["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:23:13.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:23:13.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"开发及贡献\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:23:13.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1723411596000,"updatedTime":1724912593000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":3}]},"readingTime":{"minutes":0.05,"words":16},"filePathRelative":"dev/README.md","localizedDate":"2024年8月11日"}');export{s as comp,d as data};

View File

@ -0,0 +1 @@
import{_ as i,o,c as a,b as e,d as t}from"./app-BvUYPzLF.js";const s={},n=e("h1",{id:"liteyuki-message",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#liteyuki-message"},[e("span",null,"liteyuki.message")])],-1),l=e("p",null,[e("strong",null,"说明"),t(": Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved")],-1),r=e("p",null,[t("@Time : 2024/8/19 下午10:44 @Author : snowykami @Email : snowykami@outlook.com @File : "),e("strong",null,"init"),t(".py.py @Software: PyCharm")],-1),m=[n,l,r];function p(c,d){return o(),a("div",null,m)}const u=i(s,[["render",p],["__file","index.html.vue"]]),h=JSON.parse('{"path":"/dev/api/message/","title":"liteyuki.message","lang":"zh-CN","frontmatter":{"title":"liteyuki.message","lastUpdated":false,"description":"liteyuki.message 说明: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/19 下午10:44 @Author : snowykami @Email : snowykami@outlook.com @File : init.py.py ...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/message/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/message/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki.message"}],["meta",{"property":"og:description","content":"liteyuki.message 说明: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/19 下午10:44 @Author : snowykami @Email : snowykami@outlook.com @File : init.py.py ..."}],["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\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.1,"words":29},"filePathRelative":"dev/api/message/README.md","localizedDate":"2024年8月21日","autoDesc":true}');export{u as comp,h as data};

View File

@ -0,0 +1,8 @@
import{_ as e,o as t,c as n,e as i}from"./app-BvUYPzLF.js";const a={},s=i(`<h1 id="liteyuki-plugin" tabindex="-1"><a class="header-anchor" href="#liteyuki-plugin"><span>liteyuki.plugin</span></a></h1><h3 id="def-get-loaded-plugins-dict-str-plugin" tabindex="-1"><a class="header-anchor" href="#def-get-loaded-plugins-dict-str-plugin"><span><em><strong>def</strong></em> <code>get_loaded_plugins() -&gt; dict[str, Plugin]</code></span></a></h3><p><strong>说明</strong>: 获取已加载的插件</p><p><strong>返回</strong>: dict[str, Plugin]: 插件字典</p><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/plugin/__init__.py#L13" 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">get_loaded_plugins</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">dict</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">,</span> Plugin<span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取已加载的插件
Returns:
dict[str, Plugin]: 插件字典
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> _plugins
</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></div></details>`,5),l=[s];function o(p,d){return t(),n("div",null,l)}const u=e(a,[["render",o],["__file","index.html.vue"]]),c=JSON.parse('{"path":"/dev/api/plugin/","title":"liteyuki.plugin","lang":"zh-CN","frontmatter":{"title":"liteyuki.plugin","lastUpdated":false,"description":"liteyuki.plugin def get_loaded_plugins() -> dict[str, Plugin] : : dict[str, Plugin]: GitHub","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/plugin/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/plugin/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":"liteyuki.plugin"}],["meta",{"property":"og:description","content":"liteyuki.plugin def get_loaded_plugins() -> dict[str, Plugin] : : dict[str, Plugin]: GitHub"}],["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.plugin\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def get_loaded_plugins() -> dict[str, Plugin]","slug":"def-get-loaded-plugins-dict-str-plugin","link":"#def-get-loaded-plugins-dict-str-plugin","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":4}]},"readingTime":{"minutes":0.25,"words":76},"filePathRelative":"dev/api/plugin/README.md","localizedDate":"2024819","autoDesc":true}');export{u as comp,c as data};

View File

@ -0,0 +1 @@
import{_ as t,r as o,o as a,c as n,a as r}from"./app-BvUYPzLF.js";const p={};function c(i,l){const e=o("Catalog");return a(),n("div",null,[r(e)])}const s=t(p,[["render",c],["__file","index.html.vue"]]),d=JSON.parse('{"path":"/deploy/","title":"项目部署","lang":"zh-CN","frontmatter":{"title":"项目部署","index":false,"icon":"laptop-code","category":"部署","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/deploy/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/deploy/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"项目部署"}],["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-16T18:24:25.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-16T18:24:25.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"项目部署\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-16T18:24:25.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1723832665000,"updatedTime":1723832665000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":1}]},"readingTime":{"minutes":0.05,"words":15},"filePathRelative":"deploy/README.md","localizedDate":"2024年8月16日"}');export{s as comp,d as data};

View File

@ -0,0 +1,9 @@
import{_ as n,o as e,c as t,e as a}from"./app-BvUYPzLF.js";const s={},i=a(`<h1 id="liteyuki-plugins-plugin-loader" tabindex="-1"><a class="header-anchor" href="#liteyuki-plugins-plugin-loader"><span>liteyuki.plugins.plugin_loader</span></a></h1><p><strong>Description</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/8/11 下午10:02 @Author : snowykami @Email : snowykami@outlook.com @File : <strong>init</strong>.py.py @Software: PyCharm</p><h3 id="def-default-plugins-loader" tabindex="-1"><a class="header-anchor" href="#def-default-plugins-loader"><span><em><strong>def</strong></em> <code>default_plugins_loader()</code></span></a></h3><p><strong>Description</strong>: 默认插件加载器,应在初始化时调用</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/plugins/plugin_loader/__init__.py#L21" target="_blank">View on 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">default_plugins_loader</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
默认插件加载器应在初始化时调用
&quot;&quot;&quot;</span>
<span class="token keyword">for</span> plugin <span class="token keyword">in</span> get_config<span class="token punctuation">(</span><span class="token string">&#39;liteyuki.plugins&#39;</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
load_plugin<span class="token punctuation">(</span>plugin<span class="token punctuation">)</span>
<span class="token keyword">for</span> plugin_dir <span class="token keyword">in</span> get_config<span class="token punctuation">(</span><span class="token string">&#39;liteyuki.plugin_dirs&#39;</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">&#39;src/liteyuki_plugins&#39;</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
load_plugins<span class="token punctuation">(</span>plugin_dir<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></div></details>`,6),o=[i];function l(p,u){return e(),t("div",null,o)}const d=n(s,[["render",l],["__file","index.html.vue"]]),c=JSON.parse('{"path":"/en/dev/api/plugins/plugin_loader/","title":"liteyuki.plugins.plugin_loader","lang":"en-US","frontmatter":{"title":"liteyuki.plugins.plugin_loader","lastUpdated":false,"description":"liteyuki.plugins.plugin_loader Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/11 10:02 @Author : snowykami @Email : snowykami@outlook....","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/plugins/plugin_loader/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/plugins/plugin_loader/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.plugins.plugin_loader"}],["meta",{"property":"og:description","content":"liteyuki.plugins.plugin_loader Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/11 10:02 @Author : snowykami @Email : snowykami@outlook...."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.plugins.plugin_loader\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def default_plugins_loader()","slug":"def-default-plugins-loader","link":"#def-default-plugins-loader","children":[]}],"git":{"createdTime":1724912379000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":1}]},"readingTime":{"minutes":0.33,"words":99},"filePathRelative":"en/dev/api/plugins/plugin_loader/README.md","localizedDate":"August 29, 2024","autoDesc":true}');export{d as comp,c as data};

View File

@ -0,0 +1 @@
import{_ as e,o as t,c as o}from"./app-BvUYPzLF.js";const i={};function a(s,l){return t(),o("div")}const c=e(i,[["render",a],["__file","index.html.vue"]]),m=JSON.parse('{"path":"/","title":"首页","lang":"zh-CN","frontmatter":{"home":true,"icon":"home","title":"首页","heroImage":"https://cdn.liteyuki.icu/static/svg/lylogo-full.svg","heroImageDark":"https://cdn.liteyuki.icu/static/svg/lylogo-full-dark.svg","bgImage":null,"bgImageDark":null,"bgImageStyle":{"background-attachment":"fixed"},"heroText":"LiteyukiBot","tagline":"LiteyukiBot 轻雪机器人,综合性的机器人应用及管理框架","actions":[{"text":"快速部署","icon":"rocket","link":"./deploy/install.html","type":"primary"},{"text":"使用手册","icon":"book","link":"./usage/basic_command.html"}],"highlights":[{"header":"简洁至上","image":"/assets/image/layout.svg","bgImage":"https://theme-hope-assets.vuejs.press/bg/2-light.svg","bgImageDark":"https://theme-hope-assets.vuejs.press/bg/2-dark.svg","bgImageStyle":{"background-repeat":"repeat","background-size":"initial"},"features":[{"title":"支持多种框架","icon":"robot","details":"兼容nonebotmelobot等拥有良好的生态支持","link":"https://nonebot.dev/"},{"title":"便捷管理","icon":"plug","details":"使用包管理器,便捷管理插件及资源包"},{"title":"主题支持","icon":"paint-brush","details":"使用资源包对外观进行完全自定义","link":"https://bot.liteyuki.icu/usage/resource_pack.html"},{"title":"国际化","icon":"globe","details":"通过资源包支持多种语言","link":"https://baike.baidu.com/item/i18n/6771940"},{"title":"简易使用","icon":"cog","details":"无需繁琐前期过程,开箱即用","link":"https://bot.liteyuki.icu/deployment/config.html"},{"title":"超高性能","icon":"tachometer-alt","details":"500个插件2s内启动"},{"title":"滚动更新","icon":"cloud-download","details":"让你的机器人保持最新提交"},{"title":"开源项目","icon":"code","details":"项目遵循MIT LICENCE开源欢迎各位的贡献"}]},{"header":"快速部署","image":"/assets/image/box.svg","bgImage":"https://theme-hope-assets.vuejs.press/bg/3-light.svg","bgImageDark":"https://theme-hope-assets.vuejs.press/bg/3-dark.svg","highlights":[{"title":"安装 Git 及 Python3.10+"},{"title":"使用 <code>git clone https://github.com/LiteyukiStudio/LiteyukiBot --depth=1</code> 以克隆项目至本地。","details":"如果无法连接到GitHub可以使用 <code>git clone https://gitee.com/snowykami/LiteyukiBot --depth=1</code>。"},{"title":"使用 <code>cd LiteyukiBot</code> 切换到项目目录。"},{"title":"使用 <code>pip install -r requirements.txt</code> 安装项目依赖。","details":"如果你有多个 Python 环境,请使用 <code>pythonx -m pip install -r requirements.txt</code>。"},{"title":"使用 <code>python main.py</code> 启动项目。"}]}],"copyright":"© 2021-2024 SnowyKami All Rights Reserved","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"首页"}],["meta",{"property":"og:type","content":"website"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:locale:alternate","content":"en-US"}],["meta",{"property":"og:updated_time","content":"2024-08-18T15:43:48.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-18T15:43:48.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"WebPage\\",\\"name\\":\\"首页\\"}"]]},"headers":[],"git":{"createdTime":1711460020000,"updatedTime":1723995828000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":43},{"name":"Nanaloveyuki","email":"miaomiao_159@outlook.com","commits":1},{"name":"Snowykami","email":"79104275+snowykami@users.noreply.github.com","commits":1}]},"readingTime":{"minutes":1.37,"words":411},"filePathRelative":"README.md","localizedDate":"2024年3月26日"}');export{c as comp,m as data};

View File

@ -0,0 +1 @@
import{_ as e,o as t,c as i,e as o}from"./app-BvUYPzLF.js";const a={},n=o('<h1 id="liteyuki" tabindex="-1"><a class="header-anchor" href="#liteyuki"><span>liteyuki</span></a></h1><h3 id="var-version" tabindex="-1"><a class="header-anchor" href="#var-version"><span>var <code>__version__</code></span></a></h3><ul><li><p><strong>Description</strong>: 测试版本号</p></li><li><p><strong>Default</strong>: <code>&#39;6.3.10&#39;</code></p></li></ul>',3),r=[n];function s(l,p){return t(),i("div",null,r)}const d=e(a,[["render",s],["__file","index.html.vue"]]),m=JSON.parse(`{"path":"/en/dev/api/","title":"liteyuki","lang":"en-US","frontmatter":{"title":"liteyuki","lastUpdated":false,"description":"liteyuki var __version__ Description: 测试版本号 Default: '6.3.10'","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki"}],["meta",{"property":"og:description","content":"liteyuki var __version__ Description: 测试版本号 Default: '6.3.10'"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"var __version__","slug":"var-version","link":"#var-version","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.05,"words":15},"filePathRelative":"en/dev/api/README.md","localizedDate":"August 21, 2024","autoDesc":true}`);export{d as comp,m as data};

View File

@ -0,0 +1 @@
import{_ as t,o,c as i,b as e}from"./app-BvUYPzLF.js";const r={},a=e("h1",{id:"liteyuki-core",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#liteyuki-core"},[e("span",null,"liteyuki.core")])],-1),n=[a];function c(p,l){return o(),i("div",null,n)}const d=t(r,[["render",c],["__file","index.html.vue"]]),m=JSON.parse('{"path":"/dev/api/core/","title":"liteyuki.core","lang":"zh-CN","frontmatter":{"title":"liteyuki.core","lastUpdated":false,"description":"liteyuki.core","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/core/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/core/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki.core"}],["meta",{"property":"og:description","content":"liteyuki.core"}],["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.core\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.02,"words":5},"filePathRelative":"dev/api/core/README.md","localizedDate":"2024年8月19日","autoDesc":true}');export{d as comp,m as data};

View File

@ -0,0 +1 @@
import{_ as i,o,c as a,b as e,d as t}from"./app-BvUYPzLF.js";const s={},n=e("h1",{id:"liteyuki-message",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#liteyuki-message"},[e("span",null,"liteyuki.message")])],-1),r=e("p",null,[e("strong",null,"Description"),t(": Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved")],-1),l=e("p",null,[t("@Time : 2024/8/19 下午10:44 @Author : snowykami @Email : snowykami@outlook.com @File : "),e("strong",null,"init"),t(".py.py @Software: PyCharm")],-1),m=[n,r,l];function p(c,d){return o(),a("div",null,m)}const y=i(s,[["render",p],["__file","index.html.vue"]]),h=JSON.parse('{"path":"/en/dev/api/message/","title":"liteyuki.message","lang":"en-US","frontmatter":{"title":"liteyuki.message","lastUpdated":false,"description":"liteyuki.message Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/19 下午10:44 @Author : snowykami @Email : snowykami@outlook.com @File : in...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/message/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/message/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.message"}],["meta",{"property":"og:description","content":"liteyuki.message Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/19 下午10:44 @Author : snowykami @Email : snowykami@outlook.com @File : in..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.09,"words":28},"filePathRelative":"en/dev/api/message/README.md","localizedDate":"August 21, 2024","autoDesc":true}');export{y as comp,h as data};

View File

@ -0,0 +1 @@
import{_ as t,o,c as i,b as e}from"./app-BvUYPzLF.js";const r={},a=e("h1",{id:"liteyuki-core",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#liteyuki-core"},[e("span",null,"liteyuki.core")])],-1),n=[a];function c(p,l){return o(),i("div",null,n)}const d=t(r,[["render",c],["__file","index.html.vue"]]),m=JSON.parse('{"path":"/en/dev/api/core/","title":"liteyuki.core","lang":"en-US","frontmatter":{"title":"liteyuki.core","lastUpdated":false,"description":"liteyuki.core","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/core/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/core/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.core"}],["meta",{"property":"og:description","content":"liteyuki.core"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.core\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.02,"words":5},"filePathRelative":"en/dev/api/core/README.md","localizedDate":"August 21, 2024","autoDesc":true}');export{d as comp,m as data};

View File

@ -0,0 +1 @@
import{_ as t,r as o,o as a,c as n,a as r}from"./app-BvUYPzLF.js";const p={};function c(i,l){const e=o("Catalog");return a(),n("div",null,[r(e)])}const m=t(p,[["render",c],["__file","index.html.vue"]]),d=JSON.parse('{"path":"/usage/","title":"使用手册","lang":"zh-CN","frontmatter":{"title":"使用手册","index":false,"icon":"laptop-code","category":"使用手册","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/usage/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/usage/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"使用手册"}],["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-03-28T04:05:03.000Z"}],["meta",{"property":"article:modified_time","content":"2024-03-28T04:05:03.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"使用手册\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-03-28T04:05:03.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1711589926000,"updatedTime":1711598703000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":4}]},"readingTime":{"minutes":0.06,"words":17},"filePathRelative":"usage/README.md","localizedDate":"2024年3月28日"}');export{m as comp,d as data};

View File

@ -0,0 +1,8 @@
import{_ as e,o as t,c as n,e as i}from"./app-BvUYPzLF.js";const a={},s=i(`<h1 id="liteyuki-plugin" tabindex="-1"><a class="header-anchor" href="#liteyuki-plugin"><span>liteyuki.plugin</span></a></h1><h3 id="def-get-loaded-plugins-dict-str-plugin" tabindex="-1"><a class="header-anchor" href="#def-get-loaded-plugins-dict-str-plugin"><span><em><strong>def</strong></em> <code>get_loaded_plugins() -&gt; dict[str, Plugin]</code></span></a></h3><p><strong>Description</strong>: 获取已加载的插件</p><p><strong>Return</strong>: dict[str, Plugin]: 插件字典</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/plugin/__init__.py#L13" target="_blank">View on 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">get_loaded_plugins</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">dict</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">,</span> Plugin<span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取已加载的插件
Returns:
dict[str, Plugin]: 插件字典
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> _plugins
</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></div></details>`,5),o=[s];function l(p,r){return t(),n("div",null,o)}const u=e(a,[["render",l],["__file","index.html.vue"]]),c=JSON.parse('{"path":"/en/dev/api/plugin/","title":"liteyuki.plugin","lang":"en-US","frontmatter":{"title":"liteyuki.plugin","lastUpdated":false,"description":"liteyuki.plugin def get_loaded_plugins() -> dict[str, Plugin] Description: Return: dict[str, Plugin]: Source code or View on GitHub","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/plugin/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/plugin/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.plugin"}],["meta",{"property":"og:description","content":"liteyuki.plugin def get_loaded_plugins() -> dict[str, Plugin] Description: Return: dict[str, Plugin]: Source code or View on GitHub"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.plugin\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def get_loaded_plugins() -> dict[str, Plugin]","slug":"def-get-loaded-plugins-dict-str-plugin","link":"#def-get-loaded-plugins-dict-str-plugin","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.24,"words":71},"filePathRelative":"en/dev/api/plugin/README.md","localizedDate":"August 21, 2024","autoDesc":true}');export{u as comp,c as data};

View File

@ -0,0 +1 @@
import{_ as t,r as o,o as n,c as r,a}from"./app-BvUYPzLF.js";const s={};function i(c,p){const e=o("Catalog");return n(),r("div",null,[a(e)])}const m=t(s,[["render",i],["__file","index.html.vue"]]),d=JSON.parse('{"path":"/en/store/","title":"Extensions Store","lang":"en-US","frontmatter":{"title":"Extensions Store","index":false,"icon":"store","category":"store","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/store/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/store/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"Extensions Store"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-16T18:24:25.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-16T18:24:25.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"Extensions Store\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-16T18:24:25.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1723829277000,"updatedTime":1723832665000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.04,"words":11},"filePathRelative":"en/store/README.md","localizedDate":"August 16, 2024"}');export{m as comp,d as data};

View File

@ -0,0 +1 @@
import{_ as t,o,c as i,b as e,d as a}from"./app-BvUYPzLF.js";const n={},r=e("h1",{id:"liteyuki-dev",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#liteyuki-dev"},[e("span",null,"liteyuki.dev")])],-1),d=e("p",null,[e("strong",null,"Description"),a(": 该模块用于存放一些开发工具")],-1),p=[r,d];function c(l,s){return o(),i("div",null,p)}const u=t(n,[["render",c],["__file","index.html.vue"]]),h=JSON.parse('{"path":"/en/dev/api/dev/","title":"liteyuki.dev","lang":"en-US","frontmatter":{"title":"liteyuki.dev","lastUpdated":false,"description":"liteyuki.dev Description: 该模块用于存放一些开发工具","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/dev/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/dev/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.dev"}],["meta",{"property":"og:description","content":"liteyuki.dev Description: 该模块用于存放一些开发工具"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.dev\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.06,"words":19},"filePathRelative":"en/dev/api/dev/README.md","localizedDate":"August 21, 2024","autoDesc":true}');export{u as comp,h as data};

View File

@ -0,0 +1 @@
import{_ as t,o,c as i,b as e,d as a}from"./app-BvUYPzLF.js";const n={},r=e("h1",{id:"liteyuki-dev",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#liteyuki-dev"},[e("span",null,"liteyuki.dev")])],-1),d=e("p",null,[e("strong",null,"说明"),a(": 该模块用于存放一些开发工具")],-1),l=[r,d];function p(c,s){return o(),i("div",null,l)}const u=t(n,[["render",p],["__file","index.html.vue"]]),h=JSON.parse('{"path":"/dev/api/dev/","title":"liteyuki.dev","lang":"zh-CN","frontmatter":{"title":"liteyuki.dev","lastUpdated":false,"description":"liteyuki.dev 说明: 该模块用于存放一些开发工具","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/dev/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/dev/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki.dev"}],["meta",{"property":"og:description","content":"liteyuki.dev 说明: 该模块用于存放一些开发工具"}],["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.dev\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.07,"words":20},"filePathRelative":"dev/api/dev/README.md","localizedDate":"2024年8月19日","autoDesc":true}');export{u as comp,h as data};

View File

@ -0,0 +1 @@
import{_ as e,o as t,c as o}from"./app-BvUYPzLF.js";const i={};function a(s,n){return t(),o("div")}const r=e(i,[["render",a],["__file","index.html.vue"]]),c=JSON.parse('{"path":"/en/","title":"Home","lang":"en-US","frontmatter":{"home":true,"icon":"home","title":"Home","heroImage":"https://cdn.liteyuki.icu/static/svg/lylogo-full.svg","heroImageDark":"https://cdn.liteyuki.icu/static/svg/lylogo-full-dark.svg","bgImage":null,"bgImageDark":null,"bgImageStyle":{"background-attachment":"fixed"},"heroText":"LiteyukiBot","tagline":"LiteyukiBot A high-performance, easy-to-use chatbot framework and application","actions":[{"text":"Get Started","icon":"rocket","link":"./deploy/install.html","type":"primary"},{"text":"Usage","icon":"book","link":"./usage/basic_command.html"}],"highlights":[{"header":"Simple and Efficient","image":"/assets/image/layout.svg","bgImage":"https://theme-hope-assets.vuejs.press/bg/2-light.svg","bgImageDark":"https://theme-hope-assets.vuejs.press/bg/2-dark.svg","bgImageStyle":{"background-repeat":"repeat","background-size":"initial"},"features":[{"title":"Multi-Framework Support","icon":"robot","details":"Compatible with nonebot, melobot, etc., with good ecological support","link":"https://nonebot.dev/"},{"title":"Convenient Management","icon":"plug","details":"Use package manager to manage plugins and resource packs"},{"title":"Custom Themes Support","icon":"paint-brush","details":"Fully customize the appearance with resource packs","link":"https://bot.liteyuki.icu/usage/resource_pack.html"},{"title":"i18n","icon":"globe","details":"Support multiple languages through resource packs","link":"https://baike.baidu.com/item/i18n/6771940"},{"title":"Easy to Use","icon":"cog","details":"No need for cumbersome pre-processes, ready to use","link":"https://bot.liteyuki.icu/deployment/config.html"},{"title":"High Performance","icon":"tachometer-alt","details":"500 plugins, start within 2s"},{"title":"Rolling Update","icon":"cloud-download","details":"Keep your bot up to date"},{"title":"OpenSource","icon":"code","details":"MIT LICENCE open source project, welcome your contribution"}]},{"header":"Quick Start","image":"/assets/image/box.svg","bgImage":"https://theme-hope-assets.vuejs.press/bg/3-light.svg","bgImageDark":"https://theme-hope-assets.vuejs.press/bg/3-dark.svg","highlights":[{"title":"Install Git and Python3.10+ environment"},{"title":"Use <code>git clone https://github.com/LiteyukiStudio/LiteyukiBot --depth=1</code> to clone the project locally"},{"title":"Use <code>cd LiteyukiBot</code> to change the directory to the project root"},{"title":"Use <code>pip install -r requirements.txt</code> install the project dependencies","details":"If you have multiple Python environments, please use <code>pythonx -m pip install -r requirements.txt</code>."},{"title":"Start bot with <code>python main.py</code>."}]}],"copyright":"© 2021-2024 SnowyKami All Rights Reserved","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"Home"}],["meta",{"property":"og:type","content":"website"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-16T20:50:27.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-16T20:50:27.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"WebPage\\",\\"name\\":\\"Home\\"}"]]},"headers":[],"git":{"createdTime":1723829277000,"updatedTime":1723841427000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2},{"name":"Snowykami","email":"snowykami@outlook.com","commits":1}]},"readingTime":{"minutes":1,"words":300},"filePathRelative":"en/README.md","localizedDate":"August 16, 2024"}');export{r as comp,c as data};

View File

@ -0,0 +1 @@
import{_ as t,r as o,o as a,c as n,a as p}from"./app-BvUYPzLF.js";const r={};function l(c,i){const e=o("Catalog");return a(),n("div",null,[p(e)])}const s=t(r,[["render",l],["__file","index.html.vue"]]),d=JSON.parse('{"path":"/en/deploy/","title":"Deploy","lang":"en-US","frontmatter":{"title":"Deploy","index":false,"icon":"laptop-code","category":"deploy","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/deploy/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/deploy/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"Deploy"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-16T18:24:25.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-16T18:24:25.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"Deploy\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-16T18:24:25.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1723832665000,"updatedTime":1723832665000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":1}]},"readingTime":{"minutes":0.04,"words":11},"filePathRelative":"en/deploy/README.md","localizedDate":"August 16, 2024"}');export{s as comp,d as data};

View File

@ -0,0 +1 @@
import{_ as e,o as t,c as o,e as i}from"./app-BvUYPzLF.js";const a={},r=i('<h1 id="liteyuki" tabindex="-1"><a class="header-anchor" href="#liteyuki"><span>liteyuki</span></a></h1><h3 id="var-version" tabindex="-1"><a class="header-anchor" href="#var-version"><span>var <code>__version__</code></span></a></h3><ul><li><p><strong>说明</strong>: 测试版本号</p></li><li><p><strong>默认值</strong>: <code>&#39;6.3.10&#39;</code></p></li></ul>',3),n=[r];function s(l,p){return t(),o("div",null,n)}const d=e(a,[["render",s],["__file","index.html.vue"]]),m=JSON.parse(`{"path":"/dev/api/","title":"liteyuki","lang":"zh-CN","frontmatter":{"title":"liteyuki","lastUpdated":false,"description":"liteyuki var __version__ 说明: 测试版本号 默认值: '6.3.10'","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki"}],["meta",{"property":"og:description","content":"liteyuki var __version__ 说明: 测试版本号 默认值: '6.3.10'"}],["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\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"var __version__","slug":"var-version","link":"#var-version","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.06,"words":18},"filePathRelative":"dev/api/README.md","localizedDate":"2024年8月19日","autoDesc":true}`);export{d as comp,m as data};

View File

@ -0,0 +1 @@
import{_ as t,r as o,o as a,c as n,a as r}from"./app-BvUYPzLF.js";const c={};function p(s,i){const e=o("Catalog");return a(),n("div",null,[r(e)])}const m=t(c,[["render",p],["__file","index.html.vue"]]),d=JSON.parse('{"path":"/en/usage/","title":"Usage","lang":"en-US","frontmatter":{"title":"Usage","index":false,"icon":"laptop-code","category":"usage","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/usage/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/usage/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"Usage"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-16T18:24:25.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-16T18:24:25.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"Usage\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-16T18:24:25.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1723829277000,"updatedTime":1723832665000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.04,"words":11},"filePathRelative":"en/usage/README.md","localizedDate":"August 16, 2024"}');export{m as comp,d as data};

View File

@ -0,0 +1 @@
import{_ as t,r as n,o as a,c as o,a as p}from"./app-BvUYPzLF.js";const l={};function s(r,i){const e=n("Catalog");return a(),o("div",null,[p(e)])}const m=t(l,[["render",s],["__file","index.html.vue"]]),g=JSON.parse('{"path":"/dev/api/plugins/","title":"Plugins","lang":"zh-CN","frontmatter":{"title":"Plugins","article":false,"feed":false,"sitemap":false,"head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/plugins/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/plugins/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"Plugins"}],["meta",{"property":"og:type","content":"website"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:locale:alternate","content":"en-US"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"WebPage\\",\\"name\\":\\"Plugins\\"}"]]},"headers":[],"git":{},"readingTime":{"minutes":0,"words":1},"filePathRelative":null}');export{m as comp,g as data};

View File

@ -0,0 +1 @@
import{_ as t,o,c as a,b as e,d as n}from"./app-BvUYPzLF.js";const i={},c=e("h1",{id:"liteyuki-comm",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#liteyuki-comm"},[e("span",null,"liteyuki.comm")])],-1),r=e("p",null,[e("strong",null,"说明"),n(": 该模块用于轻雪主进程和Nonebot子进程之间的通信 依赖关系 event -> _ storage -> channel_ rpc -> channel_, storage")],-1),m=[c,r];function l(p,s){return o(),a("div",null,m)}const h=t(i,[["render",l],["__file","index.html.vue"]]),_=JSON.parse('{"path":"/dev/api/comm/","title":"liteyuki.comm","lang":"zh-CN","frontmatter":{"title":"liteyuki.comm","lastUpdated":false,"description":"liteyuki.comm 说明: 该模块用于轻雪主进程和Nonebot子进程之间的通信 依赖关系 event -> _ storage -> channel_ rpc -> channel_, storage","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/comm/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/comm/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki.comm"}],["meta",{"property":"og:description","content":"liteyuki.comm 说明: 该模块用于轻雪主进程和Nonebot子进程之间的通信 依赖关系 event -> _ storage -> channel_ rpc -> channel_, storage"}],["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.comm\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.13,"words":38},"filePathRelative":"dev/api/comm/README.md","localizedDate":"2024年8月19日","autoDesc":true}');export{h as comp,_ as data};

View File

@ -0,0 +1 @@
import{_ as t,o,c as n,b as e,d as a}from"./app-BvUYPzLF.js";const i={},c=e("h1",{id:"liteyuki-comm",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#liteyuki-comm"},[e("span",null,"liteyuki.comm")])],-1),r=e("p",null,[e("strong",null,"Description"),a(": 该模块用于轻雪主进程和Nonebot子进程之间的通信 依赖关系 event -> _ storage -> channel_ rpc -> channel_, storage")],-1),m=[c,r];function l(p,s){return o(),n("div",null,m)}const h=t(i,[["render",l],["__file","index.html.vue"]]),u=JSON.parse('{"path":"/en/dev/api/comm/","title":"liteyuki.comm","lang":"en-US","frontmatter":{"title":"liteyuki.comm","lastUpdated":false,"description":"liteyuki.comm Description: 该模块用于轻雪主进程和Nonebot子进程之间的通信 依赖关系 event -> _ storage -> channel_ rpc -> channel_, storage","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/comm/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/comm/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.comm"}],["meta",{"property":"og:description","content":"liteyuki.comm Description: 该模块用于轻雪主进程和Nonebot子进程之间的通信 依赖关系 event -> _ storage -> channel_ rpc -> channel_, storage"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.comm\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.12,"words":37},"filePathRelative":"en/dev/api/comm/README.md","localizedDate":"August 21, 2024","autoDesc":true}');export{h as comp,u as data};

View File

@ -0,0 +1,9 @@
import{_ as n,o as e,c as t,e as a}from"./app-BvUYPzLF.js";const s={},i=a(`<h1 id="liteyuki-plugins-plugin-loader" tabindex="-1"><a class="header-anchor" href="#liteyuki-plugins-plugin-loader"><span>liteyuki.plugins.plugin_loader</span></a></h1><p><strong>说明</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/8/11 下午10:02 @Author : snowykami @Email : snowykami@outlook.com @File : <strong>init</strong>.py.py @Software: PyCharm</p><h3 id="def-default-plugins-loader" tabindex="-1"><a class="header-anchor" href="#def-default-plugins-loader"><span><em><strong>def</strong></em> <code>default_plugins_loader()</code></span></a></h3><p><strong>说明</strong>: 默认插件加载器,应在初始化时调用</p><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/plugins/plugin_loader/__init__.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">default_plugins_loader</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
默认插件加载器应在初始化时调用
&quot;&quot;&quot;</span>
<span class="token keyword">for</span> plugin <span class="token keyword">in</span> get_config<span class="token punctuation">(</span><span class="token string">&#39;liteyuki.plugins&#39;</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
load_plugin<span class="token punctuation">(</span>plugin<span class="token punctuation">)</span>
<span class="token keyword">for</span> plugin_dir <span class="token keyword">in</span> get_config<span class="token punctuation">(</span><span class="token string">&#39;liteyuki.plugin_dirs&#39;</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">&#39;src/liteyuki_plugins&#39;</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
load_plugins<span class="token punctuation">(</span>plugin_dir<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></div></details>`,6),o=[i];function l(p,u){return e(),t("div",null,o)}const d=n(s,[["render",l],["__file","index.html.vue"]]),c=JSON.parse('{"path":"/dev/api/plugins/plugin_loader/","title":"liteyuki.plugins.plugin_loader","lang":"zh-CN","frontmatter":{"title":"liteyuki.plugins.plugin_loader","lastUpdated":false,"description":"liteyuki.plugins.plugin_loader : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/11 10:02 @Author : snowykami @Email : snowykami@outlook.com @File...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/plugins/plugin_loader/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/plugins/plugin_loader/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":"liteyuki.plugins.plugin_loader"}],["meta",{"property":"og:description","content":"liteyuki.plugins.plugin_loader : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/11 10:02 @Author : snowykami @Email : snowykami@outlook.com @File..."}],["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.plugins.plugin_loader\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def default_plugins_loader()","slug":"def-default-plugins-loader","link":"#def-default-plugins-loader","children":[]}],"git":{"createdTime":1724912379000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":1}]},"readingTime":{"minutes":0.35,"words":104},"filePathRelative":"dev/api/plugins/plugin_loader/README.md","localizedDate":"2024829","autoDesc":true}');export{d as comp,c as data};

View File

@ -0,0 +1 @@
import{_ as t,r as o,o as a,c as n,a as r}from"./app-BvUYPzLF.js";const c={};function p(i,l){const e=o("Catalog");return a(),n("div",null,[r(e)])}const s=t(c,[["render",p],["__file","index.html.vue"]]),d=JSON.parse('{"path":"/en/dev/","title":"开发及贡献","lang":"en-US","frontmatter":{"title":"开发及贡献","index":false,"icon":"laptop-code","category":"开发","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"开发及贡献"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-29T06:23:13.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:23:13.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"开发及贡献\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:23:13.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1723829277000,"updatedTime":1724912593000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":4}]},"readingTime":{"minutes":0.05,"words":16},"filePathRelative":"en/dev/README.md","localizedDate":"August 16, 2024"}');export{s as comp,d as data};

View File

@ -0,0 +1 @@
import{_ as t,r as o,o as a,c as n,a as r}from"./app-BvUYPzLF.js";const i={};function c(p,s){const e=o("Catalog");return a(),n("div",null,[r(e)])}const m=t(i,[["render",c],["__file","index.html.vue"]]),d=JSON.parse('{"path":"/store/","title":"资源及插件商店","lang":"zh-CN","frontmatter":{"title":"资源及插件商店","index":false,"icon":"store","category":"商店","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/store/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/store/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"资源及插件商店"}],["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-11T21:26:36.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-11T21:26:36.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"资源及插件商店\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-11T21:26:36.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1712364501000,"updatedTime":1723411596000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":5}]},"readingTime":{"minutes":0.06,"words":17},"filePathRelative":"store/README.md","localizedDate":"2024年4月6日"}');export{m as comp,d as data};

View File

@ -0,0 +1,231 @@
import{_ as n,o as s,c as a,e as t}from"./app-BvUYPzLF.js";const e={},i=t(`<h1 id="liteyuki-bot" tabindex="-1"><a class="header-anchor" href="#liteyuki-bot"><span>liteyuki.bot</span></a></h1><h3 id="class-liteyukibot" tabindex="-1"><a class="header-anchor" href="#class-liteyukibot"><span><em><strong>class</strong></em> <code>LiteyukiBot</code></span></a></h3><h4 id="def-init-self-args-kwargs-none" tabindex="-1"><a class="header-anchor" href="#def-init-self-args-kwargs-none"><span><em><strong>def</strong></em> <code>__init__(self, *args, **kwargs) -&gt; None</code></span></a></h4><p><strong>Description</strong>: 初始化轻雪实例</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>*args:</li><li>**kwargs: 配置</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L27" target="_blank">View on 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> <span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<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:
*args:
**kwargs: 配置
&quot;&quot;&quot;</span>
<span class="token string">&#39;常规操作&#39;</span>
print_logo<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">global</span> _BOT_INSTANCE
_BOT_INSTANCE <span class="token operator">=</span> self
<span class="token string">&#39;配置&#39;</span>
self<span class="token punctuation">.</span>config<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 operator">=</span> kwargs
<span class="token string">&#39;初始化&#39;</span>
self<span class="token punctuation">.</span>init<span class="token punctuation">(</span><span class="token operator">**</span>self<span class="token punctuation">.</span>config<span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">&#39;Liteyuki is initializing...&#39;</span><span class="token punctuation">)</span>
<span class="token string">&#39;生命周期管理&#39;</span>
self<span class="token punctuation">.</span>lifespan <span class="token operator">=</span> Lifespan<span class="token punctuation">(</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>process_manager<span class="token punctuation">:</span> ProcessManager <span class="token operator">=</span> ProcessManager<span class="token punctuation">(</span>lifespan<span class="token operator">=</span>self<span class="token punctuation">.</span>lifespan<span class="token punctuation">)</span>
<span class="token string">&#39;事件循环&#39;</span>
self<span class="token punctuation">.</span>loop <span class="token operator">=</span> asyncio<span class="token punctuation">.</span>new_event_loop<span class="token punctuation">(</span><span class="token punctuation">)</span>
asyncio<span class="token punctuation">.</span>set_event_loop<span class="token punctuation">(</span>self<span class="token punctuation">.</span>loop<span class="token punctuation">)</span>
self<span class="token punctuation">.</span>stop_event <span class="token operator">=</span> threading<span class="token punctuation">.</span>Event<span class="token punctuation">(</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>call_restart_count <span class="token operator">=</span> <span class="token number">0</span>
<span class="token string">&#39;加载插件加载器&#39;</span>
load_plugin<span class="token punctuation">(</span><span class="token string">&#39;liteyuki.plugins.plugin_loader&#39;</span><span class="token punctuation">)</span>
<span class="token string">&#39;信号处理&#39;</span>
signal<span class="token punctuation">.</span>signal<span class="token punctuation">(</span>signal<span class="token punctuation">.</span>SIGINT<span class="token punctuation">,</span> self<span class="token punctuation">.</span>_handle_exit<span class="token punctuation">)</span>
signal<span class="token punctuation">.</span>signal<span class="token punctuation">(</span>signal<span class="token punctuation">.</span>SIGTERM<span class="token punctuation">,</span> self<span class="token punctuation">.</span>_handle_exit<span class="token punctuation">)</span>
atexit<span class="token punctuation">.</span>register<span class="token punctuation">(</span>self<span class="token punctuation">.</span>process_manager<span class="token punctuation">.</span>terminate_all<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 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><h4 id="async-def-run-self" tabindex="-1"><a class="header-anchor" href="#async-def-run-self"><span><em><strong>async def</strong></em> <code>_run(self)</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L65" target="_blank">View on 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><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
启动逻辑
&quot;&quot;&quot;</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>before_start<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>process_manager<span class="token punctuation">.</span>start_all<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>after_start<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>keep_alive<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></div></details><h4 id="def-run-self" tabindex="-1"><a class="header-anchor" href="#def-run-self"><span><em><strong>def</strong></em> <code>run(self)</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L74" target="_blank">View on 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">run</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
外部启动接口
&quot;&quot;&quot;</span>
<span class="token keyword">try</span><span class="token punctuation">:</span>
asyncio<span class="token punctuation">.</span>run<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_run<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">except</span> KeyboardInterrupt<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">&#39;Liteyuki is stopping...&#39;</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></div></details><h4 id="async-def-keep-alive-self" tabindex="-1"><a class="header-anchor" href="#async-def-keep-alive-self"><span><em><strong>async def</strong></em> <code>keep_alive(self)</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L83" target="_blank">View on 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">keep_alive</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
保持轻雪运行
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">try</span><span class="token punctuation">:</span>
<span class="token keyword">while</span> <span class="token keyword">not</span> self<span class="token punctuation">.</span>stop_event<span class="token punctuation">.</span>is_set<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
time<span class="token punctuation">.</span>sleep<span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">)</span>
<span class="token keyword">except</span> KeyboardInterrupt<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">&#39;Liteyuki is stopping...&#39;</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>stop<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-exit-self-signum-frame" tabindex="-1"><a class="header-anchor" href="#def-handle-exit-self-signum-frame"><span><em><strong>def</strong></em> <code>_handle_exit(self, signum, frame)</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>signum:</li><li>frame:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L96" target="_blank">View on 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_exit</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> signum<span class="token punctuation">,</span> frame<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
信号处理
Args:
signum:
frame:
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">&#39;Received signal, stopping all processes.&#39;</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>stop<span class="token punctuation">(</span><span class="token punctuation">)</span>
sys<span class="token punctuation">.</span>exit<span class="token punctuation">(</span><span class="token number">0</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></div></details><h4 id="def-restart-self-delay-int-0" tabindex="-1"><a class="header-anchor" href="#def-restart-self-delay-int-0"><span><em><strong>def</strong></em> <code>restart(self, delay: int = 0)</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L110" target="_blank">View on 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">restart</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> delay<span class="token punctuation">:</span> <span class="token builtin">int</span><span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
重启轻雪本体
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> self<span class="token punctuation">.</span>call_restart_count <span class="token operator">&lt;</span> <span class="token number">1</span><span class="token punctuation">:</span>
executable <span class="token operator">=</span> sys<span class="token punctuation">.</span>executable
args <span class="token operator">=</span> sys<span class="token punctuation">.</span>argv
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string">&#39;Restarting LiteyukiBot...&#39;</span><span class="token punctuation">)</span>
time<span class="token punctuation">.</span>sleep<span class="token punctuation">(</span>delay<span class="token punctuation">)</span>
<span class="token keyword">if</span> platform<span class="token punctuation">.</span>system<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token string">&#39;Windows&#39;</span><span class="token punctuation">:</span>
cmd <span class="token operator">=</span> <span class="token string">&#39;start&#39;</span>
<span class="token keyword">elif</span> platform<span class="token punctuation">.</span>system<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token string">&#39;Linux&#39;</span><span class="token punctuation">:</span>
cmd <span class="token operator">=</span> <span class="token string">&#39;nohup&#39;</span>
<span class="token keyword">elif</span> platform<span class="token punctuation">.</span>system<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token string">&#39;Darwin&#39;</span><span class="token punctuation">:</span>
cmd <span class="token operator">=</span> <span class="token string">&#39;open&#39;</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
cmd <span class="token operator">=</span> <span class="token string">&#39;nohup&#39;</span>
self<span class="token punctuation">.</span>process_manager<span class="token punctuation">.</span>terminate_all<span class="token punctuation">(</span><span class="token punctuation">)</span>
threading<span class="token punctuation">.</span>Thread<span class="token punctuation">(</span>target<span class="token operator">=</span>os<span class="token punctuation">.</span>system<span class="token punctuation">,</span> args<span class="token operator">=</span><span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>cmd<span class="token punctuation">}</span></span><span class="token string"> </span><span class="token interpolation"><span class="token punctuation">{</span>executable<span class="token punctuation">}</span></span><span class="token string"> </span><span class="token interpolation"><span class="token punctuation">{</span><span class="token string">&#39; &#39;</span><span class="token punctuation">.</span>join<span class="token punctuation">(</span>args<span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">&quot;</span></span><span class="token punctuation">,</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span>start<span class="token punctuation">(</span><span class="token punctuation">)</span>
sys<span class="token punctuation">.</span>exit<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>call_restart_count <span class="token operator">+=</span> <span class="token number">1</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 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-restart-process-self-name-optional-str-none" tabindex="-1"><a class="header-anchor" href="#def-restart-process-self-name-optional-str-none"><span><em><strong>def</strong></em> <code>restart_process(self, name: Optional[str] = None)</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>name: , None, </li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L135" target="_blank">View on 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">restart_process</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">:</span> Optional<span class="token punctuation">[</span><span class="token builtin">str</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>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
停止轻雪
Args:
name: 进程名称, 默认为None, 所有进程
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> name <span class="token keyword">is</span> <span class="token keyword">not</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
chan_active <span class="token operator">=</span> get_channel<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;</span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string">-active&#39;</span></span><span class="token punctuation">)</span>
chan_active<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
<span class="token keyword">for</span> process_name <span class="token keyword">in</span> self<span class="token punctuation">.</span>process_manager<span class="token punctuation">.</span>processes<span class="token punctuation">:</span>
chan_active <span class="token operator">=</span> get_channel<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;</span><span class="token interpolation"><span class="token punctuation">{</span>process_name<span class="token punctuation">}</span></span><span class="token string">-active&#39;</span></span><span class="token punctuation">)</span>
chan_active<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token number">1</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><h4 id="def-init-self-args-kwargs" tabindex="-1"><a class="header-anchor" href="#def-init-self-args-kwargs"><span><em><strong>def</strong></em> <code>init(self, *args, **kwargs)</code></span></a></h4><p><strong>Description</strong>: , </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L150" target="_blank">View on 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> <span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
初始化轻雪, 自动调用
Returns:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>init_logger<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></div></details><h4 id="def-init-logger-self" tabindex="-1"><a class="header-anchor" href="#def-init-logger-self"><span><em><strong>def</strong></em> <code>init_logger(self)</code></span></a></h4><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L158" target="_blank">View on 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_logger</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
init_log<span class="token punctuation">(</span>config<span class="token operator">=</span>self<span class="token punctuation">.</span>config<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></div></details><h4 id="def-stop-self" tabindex="-1"><a class="header-anchor" href="#def-stop-self"><span><em><strong>def</strong></em> <code>stop(self)</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L162" target="_blank">View on 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">stop</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
停止轻雪
Returns:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>stop_event<span class="token punctuation">.</span><span class="token builtin">set</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>loop<span class="token punctuation">.</span>stop<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></div></details><h4 id="def-on-before-start-self-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-start-self-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_start(self, func: LIFESPAN_FUNC)</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L171" target="_blank">View on 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">on_before_start</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册启动前的函数
Args:
func:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>on_before_start<span class="token punctuation">(</span>func<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></div></details><h4 id="def-on-after-start-self-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-start-self-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_start(self, func: LIFESPAN_FUNC)</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L182" target="_blank">View on 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">on_after_start</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册启动后的函数
Args:
func:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>on_after_start<span class="token punctuation">(</span>func<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></div></details><h4 id="def-on-after-shutdown-self-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-shutdown-self-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_shutdown(self, func: LIFESPAN_FUNC)</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L193" target="_blank">View on 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">on_after_shutdown</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册停止后的函数未实现
Args:
func:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>on_after_shutdown<span class="token punctuation">(</span>func<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></div></details><h4 id="def-on-before-process-shutdown-self-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-process-shutdown-self-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_process_shutdown(self, func: LIFESPAN_FUNC)</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L204" target="_blank">View on 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">on_before_process_shutdown</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册进程停止前的函数为子进程停止时调用
Args:
func:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>on_before_process_shutdown<span class="token punctuation">(</span>func<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></div></details><h4 id="def-on-before-process-restart-self-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-process-restart-self-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_process_restart(self, func: LIFESPAN_FUNC)</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L215" target="_blank">View on 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">on_before_process_restart</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册进程重启前的函数为子进程重启时调用
Args:
func:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>on_before_process_restart<span class="token punctuation">(</span>func<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></div></details><h4 id="def-on-after-restart-self-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-restart-self-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_restart(self, func: LIFESPAN_FUNC)</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L227" target="_blank">View on 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">on_after_restart</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册重启后的函数未实现
Args:
func:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>on_after_restart<span class="token punctuation">(</span>func<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></div></details><h3 id="def-get-bot-liteyukibot" tabindex="-1"><a class="header-anchor" href="#def-get-bot-liteyukibot"><span><em><strong>def</strong></em> <code>get_bot() -&gt; LiteyukiBot</code></span></a></h3><p><strong>Description</strong>: </p><p><strong>Return</strong>: LiteyukiBot: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L242" target="_blank">View on 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">get_bot</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LiteyukiBot<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取轻雪实例
Returns:
LiteyukiBot: 当前的轻雪实例
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> IS_MAIN_PROCESS<span class="token punctuation">:</span>
<span class="token keyword">if</span> _BOT_INSTANCE <span class="token keyword">is</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
<span class="token keyword">raise</span> RuntimeError<span class="token punctuation">(</span><span class="token string">&#39;Liteyuki instance not initialized.&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> _BOT_INSTANCE
<span class="token keyword">else</span><span class="token punctuation">:</span>
<span class="token keyword">raise</span> RuntimeError<span class="token punctuation">(</span><span class="token string">&quot;Can&#39;t get bot instance in sub process.&quot;</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></div></details><h3 id="def-get-config-key-str-default-any-none-any" tabindex="-1"><a class="header-anchor" href="#def-get-config-key-str-default-any-none-any"><span><em><strong>def</strong></em> <code>get_config(key: str, default: Any = None) -&gt; Any</code></span></a></h3><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>key: </li><li>default: </li></ul></blockquote><p><strong>Return</strong>: Any: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L258" target="_blank">View on 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">get_config</span><span class="token punctuation">(</span>key<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> default<span class="token punctuation">:</span> Any<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> Any<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取配置
Args:
key: 配置键
default: 默认值
Returns:
Any: 配置值
&quot;&quot;&quot;</span>
<span class="token keyword">return</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>config<span class="token punctuation">.</span>get<span class="token punctuation">(</span>key<span class="token punctuation">,</span> default<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></div></details><h3 id="def-get-config-with-compat-key-str-compat-keys-tuple-str-default-any-none-any" tabindex="-1"><a class="header-anchor" href="#def-get-config-with-compat-key-str-compat-keys-tuple-str-default-any-none-any"><span><em><strong>def</strong></em> <code>get_config_with_compat(key: str, compat_keys: tuple[str], default: Any = None) -&gt; Any</code></span></a></h3><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>key: </li><li>compat_keys: </li><li>default: </li></ul></blockquote><p><strong>Return</strong>: Any: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L271" target="_blank">View on 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">get_config_with_compat</span><span class="token punctuation">(</span>key<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> compat_keys<span class="token punctuation">:</span> <span class="token builtin">tuple</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">]</span><span class="token punctuation">,</span> default<span class="token punctuation">:</span> Any<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> Any<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
获取配置兼容旧版本
Args:
key: 配置键
compat_keys: 兼容键
default: 默认值
Returns:
Any: 配置值
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> key <span class="token keyword">in</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>config<span class="token punctuation">:</span>
<span class="token keyword">return</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>config<span class="token punctuation">[</span>key<span class="token punctuation">]</span>
<span class="token keyword">for</span> compat_key <span class="token keyword">in</span> compat_keys<span class="token punctuation">:</span>
<span class="token keyword">if</span> compat_key <span class="token keyword">in</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>config<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Config key &quot;</span><span class="token interpolation"><span class="token punctuation">{</span>compat_key<span class="token punctuation">}</span></span><span class="token string">&quot; will be deprecated, use &quot;</span><span class="token interpolation"><span class="token punctuation">{</span>key<span class="token punctuation">}</span></span><span class="token string">&quot; instead.&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">return</span> get_bot<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>config<span class="token punctuation">[</span>compat_key<span class="token punctuation">]</span>
<span class="token keyword">return</span> default
</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></div></details><h3 id="def-print-logo" tabindex="-1"><a class="header-anchor" href="#def-print-logo"><span><em><strong>def</strong></em> <code>print_logo()</code></span></a></h3><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/__init__.py#L291" target="_blank">View on 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">print_logo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">&#39;\\x1b[34m&#39;</span> <span class="token operator">+</span> <span class="token string">&#39;\\n __ ______ ________ ________ __ __ __ __ __ __ ______ \\n / | / |/ |/ |/ \\\\ / |/ | / |/ | / |/ |\\n $$ | $$$$$$/ $$$$$$$$/ $$$$$$$$/ $$ \\\\ /$$/ $$ | $$ |$$ | /$$/ $$$$$$/ \\n $$ | $$ | $$ | $$ |__ $$ \\\\/$$/ $$ | $$ |$$ |/$$/ $$ | \\n $$ | $$ | $$ | $$ | $$ $$/ $$ | $$ |$$ $$&lt; $$ | \\n $$ | $$ | $$ | $$$$$/ $$$$/ $$ | $$ |$$$$$ \\\\ $$ | \\n $$ |_____ _$$ |_ $$ | $$ |_____ $$ | $$ \\\\__$$ |$$ |$$ \\\\ _$$ |_ \\n $$ |/ $$ | $$ | $$ | $$ | $$ $$/ $$ | $$ |/ $$ |\\n $$$$$$$$/ $$$$$$/ $$/ $$$$$$$$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ \\n &#39;</span> <span class="token operator">+</span> <span class="token string">&#39;\\x1b[0m&#39;</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></div></details>`,85),o=[i];function p(l,c){return s(),a("div",null,o)}const r=n(e,[["render",p],["__file","index.html.vue"]]),d=JSON.parse('{"path":"/en/dev/api/bot/","title":"liteyuki.bot","lang":"en-US","frontmatter":{"title":"liteyuki.bot","lastUpdated":false,"description":"liteyuki.bot class LiteyukiBot def __init__(self, *args, **kwargs) -> None Description: Arguments: *args: **kwargs: Source code or View on GitHub async def _run(self)...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/bot/"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/bot/"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.bot"}],["meta",{"property":"og:description","content":"liteyuki.bot class LiteyukiBot def __init__(self, *args, **kwargs) -> None Description: Arguments: *args: **kwargs: Source code or View on GitHub async def _run(self)..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.bot\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class LiteyukiBot","slug":"class-liteyukibot","link":"#class-liteyukibot","children":[]},{"level":3,"title":"def get_bot() -> LiteyukiBot","slug":"def-get-bot-liteyukibot","link":"#def-get-bot-liteyukibot","children":[]},{"level":3,"title":"def get_config(key: str, default: Any = None) -> Any","slug":"def-get-config-key-str-default-any-none-any","link":"#def-get-config-key-str-default-any-none-any","children":[]},{"level":3,"title":"def get_config_with_compat(key: str, compat_keys: tuple[str], default: Any = None) -> Any","slug":"def-get-config-with-compat-key-str-compat-keys-tuple-str-default-any-none-any","link":"#def-get-config-with-compat-key-str-compat-keys-tuple-str-default-any-none-any","children":[]},{"level":3,"title":"def print_logo()","slug":"def-print-logo","link":"#def-print-logo","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":4.79,"words":1437},"filePathRelative":"en/dev/api/bot/README.md","localizedDate":"August 21, 2024","autoDesc":true}');export{r as comp,d as data};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,128 @@
import{_ as e,r as t,o,c as p,b as n,a as i,e as s}from"./app-BvUYPzLF.js";const l={},u=s(`<h1 id="liteyuki-bot-lifespan" tabindex="-1"><a class="header-anchor" href="#liteyuki-bot-lifespan"><span>liteyuki.bot.lifespan</span></a></h1><p><strong>说明</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/7/23 下午8:24 @Author : snowykami @Email : snowykami@outlook.com @File : lifespan.py @Software: PyCharm</p><h3 id="class-lifespan" tabindex="-1"><a class="header-anchor" href="#class-lifespan"><span><em><strong>class</strong></em> <code>Lifespan</code></span></a></h3><h4 id="def-init-self-none" tabindex="-1"><a class="header-anchor" href="#def-init-self-none"><span><em><strong>def</strong></em> <code>__init__(self) -&gt; None</code></span></a></h4><p><strong>说明</strong>: 轻雪生命周期管理,启动、停止、重启</p><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L27" 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> <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;
轻雪生命周期管理启动停止重启
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>life_flag<span class="token punctuation">:</span> <span class="token builtin">int</span> <span class="token operator">=</span> <span class="token number">0</span>
self<span class="token punctuation">.</span>_before_start_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>_after_start_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>_before_process_shutdown_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>_after_shutdown_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>_before_process_restart_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>_after_restart_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<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></div></details>`,7),c={href:"https://docs.python.org/3/library/functions.html#staticmethod",target:"_blank",rel:"noopener noreferrer"},r=n("code",null,"@staticmethod",-1),d=s(`<h4 id="async-def-run-funcs-funcs-list-async-lifespan-func-process-lifespan-func-args-kwargs-none" tabindex="-1"><a class="header-anchor" href="#async-def-run-funcs-funcs-list-async-lifespan-func-process-lifespan-func-args-kwargs-none"><span><em><strong>async def</strong></em> <code>run_funcs(funcs: list[ASYNC_LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC], *args, **kwargs) -&gt; None</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>funcs:</li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L43" 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 decorator annotation punctuation">@staticmethod</span>
<span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">run_funcs</span><span class="token punctuation">(</span>funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>ASYNC_LIFESPAN_FUNC <span class="token operator">|</span> PROCESS_LIFESPAN_FUNC<span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<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:
funcs:
Returns:
&quot;&quot;&quot;</span>
loop <span class="token operator">=</span> asyncio<span class="token punctuation">.</span>get_running_loop<span class="token punctuation">(</span><span class="token punctuation">)</span>
tasks <span class="token operator">=</span> <span class="token punctuation">[</span>func<span class="token punctuation">(</span><span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<span class="token punctuation">)</span> <span class="token keyword">if</span> is_coroutine_callable<span class="token punctuation">(</span>func<span class="token punctuation">)</span> <span class="token keyword">else</span> async_wrapper<span class="token punctuation">(</span>func<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<span class="token punctuation">)</span> <span class="token keyword">for</span> func <span class="token keyword">in</span> funcs<span class="token punctuation">]</span>
<span class="token keyword">await</span> asyncio<span class="token punctuation">.</span>gather<span class="token punctuation">(</span><span class="token operator">*</span>tasks<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></div></details><h4 id="def-on-before-start-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-start-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_start(self, func: LIFESPAN_FUNC) -&gt; LIFESPAN_FUNC</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong></strong>: LIFESPAN_FUNC:</p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L54" 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">on_before_start</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LIFESPAN_FUNC<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册启动时的函数
Args:
func:
Returns:
LIFESPAN_FUNC:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>_before_start_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
<span class="token keyword">return</span> func
</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></div></details><h4 id="def-on-after-start-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-start-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_start(self, func: LIFESPAN_FUNC) -&gt; LIFESPAN_FUNC</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong></strong>: LIFESPAN_FUNC:</p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L65" 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">on_after_start</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LIFESPAN_FUNC<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册启动时的函数
Args:
func:
Returns:
LIFESPAN_FUNC:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>_after_start_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
<span class="token keyword">return</span> func
</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></div></details><h4 id="def-on-before-process-shutdown-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-process-shutdown-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_process_shutdown(self, func: LIFESPAN_FUNC) -&gt; LIFESPAN_FUNC</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong></strong>: LIFESPAN_FUNC:</p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L76" 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">on_before_process_shutdown</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LIFESPAN_FUNC<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册停止前的函数
Args:
func:
Returns:
LIFESPAN_FUNC:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>_before_process_shutdown_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
<span class="token keyword">return</span> func
</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></div></details><h4 id="def-on-after-shutdown-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-shutdown-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_shutdown(self, func: LIFESPAN_FUNC) -&gt; LIFESPAN_FUNC</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong></strong>: LIFESPAN_FUNC:</p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L87" 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">on_after_shutdown</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LIFESPAN_FUNC<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册停止后的函数
Args:
func:
Returns:
LIFESPAN_FUNC:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>_after_shutdown_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
<span class="token keyword">return</span> func
</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-on-before-process-restart-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-process-restart-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_process_restart(self, func: LIFESPAN_FUNC) -&gt; LIFESPAN_FUNC</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong></strong>: LIFESPAN_FUNC:</p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L100" 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">on_before_process_restart</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LIFESPAN_FUNC<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册重启时的函数
Args:
func:
Returns:
LIFESPAN_FUNC:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>_before_process_restart_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
<span class="token keyword">return</span> func
</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></div></details><h4 id="def-on-after-restart-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-restart-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_restart(self, func: LIFESPAN_FUNC) -&gt; LIFESPAN_FUNC</code></span></a></h4><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong></strong>: LIFESPAN_FUNC:</p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L111" 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">on_after_restart</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LIFESPAN_FUNC<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册重启后的函数
Args:
func:
Returns:
LIFESPAN_FUNC:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>_after_restart_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
<span class="token keyword">return</span> func
</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></div></details><h4 id="async-def-before-start-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-before-start-self-none"><span><em><strong>async def</strong></em> <code>before_start(self) -&gt; None</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L122" 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">before_start</span><span class="token punctuation">(</span>self<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;
启动前
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">&#39;Running before_start functions&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_before_start_funcs<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></div></details><h4 id="async-def-after-start-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-after-start-self-none"><span><em><strong>async def</strong></em> <code>after_start(self) -&gt; None</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L130" 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">after_start</span><span class="token punctuation">(</span>self<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;
启动后
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">&#39;Running after_start functions&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_after_start_funcs<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></div></details><h4 id="async-def-before-process-shutdown-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-before-process-shutdown-self-none"><span><em><strong>async def</strong></em> <code>before_process_shutdown(self) -&gt; None</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L138" 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">before_process_shutdown</span><span class="token punctuation">(</span>self<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;
停止前
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">&#39;Running before_shutdown functions&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_before_process_shutdown_funcs<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></div></details><h4 id="async-def-after-shutdown-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-after-shutdown-self-none"><span><em><strong>async def</strong></em> <code>after_shutdown(self) -&gt; None</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L146" 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">after_shutdown</span><span class="token punctuation">(</span>self<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;
停止后
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">&#39;Running after_shutdown functions&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_after_shutdown_funcs<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></div></details><h4 id="async-def-before-process-restart-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-before-process-restart-self-none"><span><em><strong>async def</strong></em> <code>before_process_restart(self) -&gt; None</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L154" 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">before_process_restart</span><span class="token punctuation">(</span>self<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;
重启前
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">&#39;Running before_restart functions&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_before_process_restart_funcs<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></div></details><h4 id="async-def-after-restart-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-after-restart-self-none"><span><em><strong>async def</strong></em> <code>after_restart(self) -&gt; None</code></span></a></h4><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L162" 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">after_restart</span><span class="token punctuation">(</span>self<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;
重启后
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">&#39;Running after_restart functions&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_after_restart_funcs<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></div></details>`,59);function k(f,m){const a=t("ExternalLinkIcon");return o(),p("div",null,[u,n("p",null,[n("a",c,[r,i(a)])]),d])}const v=e(l,[["render",k],["__file","lifespan.html.vue"]]),g=JSON.parse('{"path":"/dev/api/bot/lifespan.html","title":"liteyuki.bot.lifespan","lang":"zh-CN","frontmatter":{"title":"liteyuki.bot.lifespan","lastUpdated":false,"description":"liteyuki.bot.lifespan : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 8:24 @Author : snowykami @Email : snowykami@outlook.com @File : lifespa...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/bot/lifespan.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/bot/lifespan.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":"liteyuki.bot.lifespan"}],["meta",{"property":"og:description","content":"liteyuki.bot.lifespan : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 8:24 @Author : snowykami @Email : snowykami@outlook.com @File : lifespa..."}],["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.bot.lifespan\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class Lifespan","slug":"class-lifespan","link":"#class-lifespan","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":6}]},"readingTime":{"minutes":3.05,"words":916},"filePathRelative":"dev/api/bot/lifespan.md","localizedDate":"2024819","autoDesc":true}');export{v as comp,g as data};

View File

@ -0,0 +1,128 @@
import{_ as e,r as t,o,c as p,b as n,a as i,e as s}from"./app-BvUYPzLF.js";const c={},u=s(`<h1 id="liteyuki-bot-lifespan" tabindex="-1"><a class="header-anchor" href="#liteyuki-bot-lifespan"><span>liteyuki.bot.lifespan</span></a></h1><p><strong>Description</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/7/23 下午8:24 @Author : snowykami @Email : snowykami@outlook.com @File : lifespan.py @Software: PyCharm</p><h3 id="class-lifespan" tabindex="-1"><a class="header-anchor" href="#class-lifespan"><span><em><strong>class</strong></em> <code>Lifespan</code></span></a></h3><h4 id="def-init-self-none" tabindex="-1"><a class="header-anchor" href="#def-init-self-none"><span><em><strong>def</strong></em> <code>__init__(self) -&gt; None</code></span></a></h4><p><strong>Description</strong>: 轻雪生命周期管理,启动、停止、重启</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L27" target="_blank">View on 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> <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;
轻雪生命周期管理启动停止重启
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>life_flag<span class="token punctuation">:</span> <span class="token builtin">int</span> <span class="token operator">=</span> <span class="token number">0</span>
self<span class="token punctuation">.</span>_before_start_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>_after_start_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>_before_process_shutdown_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>_after_shutdown_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>_before_process_restart_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
self<span class="token punctuation">.</span>_after_restart_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<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></div></details>`,7),l={href:"https://docs.python.org/3/library/functions.html#staticmethod",target:"_blank",rel:"noopener noreferrer"},r=n("code",null,"@staticmethod",-1),d=s(`<h4 id="async-def-run-funcs-funcs-list-async-lifespan-func-process-lifespan-func-args-kwargs-none" tabindex="-1"><a class="header-anchor" href="#async-def-run-funcs-funcs-list-async-lifespan-func-process-lifespan-func-args-kwargs-none"><span><em><strong>async def</strong></em> <code>run_funcs(funcs: list[ASYNC_LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC], *args, **kwargs) -&gt; None</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>funcs:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L43" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token decorator annotation punctuation">@staticmethod</span>
<span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">run_funcs</span><span class="token punctuation">(</span>funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>ASYNC_LIFESPAN_FUNC <span class="token operator">|</span> PROCESS_LIFESPAN_FUNC<span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<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:
funcs:
Returns:
&quot;&quot;&quot;</span>
loop <span class="token operator">=</span> asyncio<span class="token punctuation">.</span>get_running_loop<span class="token punctuation">(</span><span class="token punctuation">)</span>
tasks <span class="token operator">=</span> <span class="token punctuation">[</span>func<span class="token punctuation">(</span><span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<span class="token punctuation">)</span> <span class="token keyword">if</span> is_coroutine_callable<span class="token punctuation">(</span>func<span class="token punctuation">)</span> <span class="token keyword">else</span> async_wrapper<span class="token punctuation">(</span>func<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<span class="token punctuation">)</span> <span class="token keyword">for</span> func <span class="token keyword">in</span> funcs<span class="token punctuation">]</span>
<span class="token keyword">await</span> asyncio<span class="token punctuation">.</span>gather<span class="token punctuation">(</span><span class="token operator">*</span>tasks<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></div></details><h4 id="def-on-before-start-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-start-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_start(self, func: LIFESPAN_FUNC) -&gt; LIFESPAN_FUNC</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong>Return</strong>: LIFESPAN_FUNC:</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L54" target="_blank">View on 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">on_before_start</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LIFESPAN_FUNC<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册启动时的函数
Args:
func:
Returns:
LIFESPAN_FUNC:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>_before_start_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
<span class="token keyword">return</span> func
</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></div></details><h4 id="def-on-after-start-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-start-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_start(self, func: LIFESPAN_FUNC) -&gt; LIFESPAN_FUNC</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong>Return</strong>: LIFESPAN_FUNC:</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L65" target="_blank">View on 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">on_after_start</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LIFESPAN_FUNC<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册启动时的函数
Args:
func:
Returns:
LIFESPAN_FUNC:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>_after_start_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
<span class="token keyword">return</span> func
</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></div></details><h4 id="def-on-before-process-shutdown-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-process-shutdown-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_process_shutdown(self, func: LIFESPAN_FUNC) -&gt; LIFESPAN_FUNC</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong>Return</strong>: LIFESPAN_FUNC:</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L76" target="_blank">View on 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">on_before_process_shutdown</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LIFESPAN_FUNC<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册停止前的函数
Args:
func:
Returns:
LIFESPAN_FUNC:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>_before_process_shutdown_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
<span class="token keyword">return</span> func
</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></div></details><h4 id="def-on-after-shutdown-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-shutdown-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_shutdown(self, func: LIFESPAN_FUNC) -&gt; LIFESPAN_FUNC</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong>Return</strong>: LIFESPAN_FUNC:</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L87" target="_blank">View on 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">on_after_shutdown</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LIFESPAN_FUNC<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册停止后的函数
Args:
func:
Returns:
LIFESPAN_FUNC:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>_after_shutdown_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
<span class="token keyword">return</span> func
</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-on-before-process-restart-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-process-restart-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_process_restart(self, func: LIFESPAN_FUNC) -&gt; LIFESPAN_FUNC</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong>Return</strong>: LIFESPAN_FUNC:</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L100" target="_blank">View on 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">on_before_process_restart</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LIFESPAN_FUNC<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册重启时的函数
Args:
func:
Returns:
LIFESPAN_FUNC:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>_before_process_restart_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
<span class="token keyword">return</span> func
</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></div></details><h4 id="def-on-after-restart-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-restart-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_restart(self, func: LIFESPAN_FUNC) -&gt; LIFESPAN_FUNC</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong>Return</strong>: LIFESPAN_FUNC:</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L111" target="_blank">View on 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">on_after_restart</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> LIFESPAN_FUNC<span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
注册重启后的函数
Args:
func:
Returns:
LIFESPAN_FUNC:
&quot;&quot;&quot;</span>
self<span class="token punctuation">.</span>_after_restart_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
<span class="token keyword">return</span> func
</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></div></details><h4 id="async-def-before-start-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-before-start-self-none"><span><em><strong>async def</strong></em> <code>before_start(self) -&gt; None</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L122" target="_blank">View on 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">before_start</span><span class="token punctuation">(</span>self<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;
启动前
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">&#39;Running before_start functions&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_before_start_funcs<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></div></details><h4 id="async-def-after-start-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-after-start-self-none"><span><em><strong>async def</strong></em> <code>after_start(self) -&gt; None</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L130" target="_blank">View on 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">after_start</span><span class="token punctuation">(</span>self<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;
启动后
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">&#39;Running after_start functions&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_after_start_funcs<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></div></details><h4 id="async-def-before-process-shutdown-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-before-process-shutdown-self-none"><span><em><strong>async def</strong></em> <code>before_process_shutdown(self) -&gt; None</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L138" target="_blank">View on 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">before_process_shutdown</span><span class="token punctuation">(</span>self<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;
停止前
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">&#39;Running before_shutdown functions&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_before_process_shutdown_funcs<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></div></details><h4 id="async-def-after-shutdown-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-after-shutdown-self-none"><span><em><strong>async def</strong></em> <code>after_shutdown(self) -&gt; None</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L146" target="_blank">View on 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">after_shutdown</span><span class="token punctuation">(</span>self<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;
停止后
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">&#39;Running after_shutdown functions&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_after_shutdown_funcs<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></div></details><h4 id="async-def-before-process-restart-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-before-process-restart-self-none"><span><em><strong>async def</strong></em> <code>before_process_restart(self) -&gt; None</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L154" target="_blank">View on 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">before_process_restart</span><span class="token punctuation">(</span>self<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;
重启前
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">&#39;Running before_restart functions&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_before_process_restart_funcs<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></div></details><h4 id="async-def-after-restart-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-after-restart-self-none"><span><em><strong>async def</strong></em> <code>after_restart(self) -&gt; None</code></span></a></h4><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L162" target="_blank">View on 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">after_restart</span><span class="token punctuation">(</span>self<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;
重启后
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">&#39;Running after_restart functions&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_after_restart_funcs<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></div></details>`,59);function k(f,m){const a=t("ExternalLinkIcon");return o(),p("div",null,[u,n("p",null,[n("a",l,[r,i(a)])]),d])}const v=e(c,[["render",k],["__file","lifespan.html.vue"]]),g=JSON.parse('{"path":"/en/dev/api/bot/lifespan.html","title":"liteyuki.bot.lifespan","lang":"en-US","frontmatter":{"title":"liteyuki.bot.lifespan","lastUpdated":false,"description":"liteyuki.bot.lifespan Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 8:24 @Author : snowykami @Email : snowykami@outlook.com @File ...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/bot/lifespan.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/bot/lifespan.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.bot.lifespan"}],["meta",{"property":"og:description","content":"liteyuki.bot.lifespan Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 8:24 @Author : snowykami @Email : snowykami@outlook.com @File ..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.bot.lifespan\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class Lifespan","slug":"class-lifespan","link":"#class-lifespan","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":2.82,"words":846},"filePathRelative":"en/dev/api/bot/lifespan.md","localizedDate":"August 21, 2024","autoDesc":true}');export{v as comp,g as data};

View File

@ -0,0 +1,4 @@
import{_ as e,o as t,c as n,e as a}from"./app-BvUYPzLF.js";const s={},o=a(`<h1 id="liteyuki-plugins-liteecho" tabindex="-1"><a class="header-anchor" href="#liteyuki-plugins-liteecho"><span>liteyuki.plugins.liteecho</span></a></h1><p><strong>说明</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/8/22 下午12:31 @Author : snowykami @Email : snowykami@outlook.com @File : liteecho.py @Software: PyCharm</p><p><code>@on_startswith([&#39;liteecho&#39;], rule=is_su_rule).handle()</code></p><h3 id="async-def-liteecho-event-messageevent" tabindex="-1"><a class="header-anchor" href="#async-def-liteecho-event-messageevent"><span><em><strong>async def</strong></em> <code>liteecho(event: MessageEvent)</code></span></a></h3><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/plugins/liteecho.py#L18" 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 decorator annotation punctuation">@on_startswith</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">&#39;liteecho&#39;</span><span class="token punctuation">]</span><span class="token punctuation">,</span> rule<span class="token operator">=</span>is_su_rule<span class="token punctuation">)</span><span class="token punctuation">.</span>handle<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">liteecho</span><span class="token punctuation">(</span>event<span class="token punctuation">:</span> MessageEvent<span class="token punctuation">)</span><span class="token punctuation">:</span>
event<span class="token punctuation">.</span>reply<span class="token punctuation">(</span>event<span class="token punctuation">.</span>raw_message<span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">8</span><span class="token punctuation">:</span><span class="token punctuation">]</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</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></div></details>`,6),i=[o];function p(l,c){return t(),n("div",null,i)}const r=e(s,[["render",p],["__file","liteecho.html.vue"]]),d=JSON.parse('{"path":"/dev/api/plugins/liteecho.html","title":"liteyuki.plugins.liteecho","lang":"zh-CN","frontmatter":{"title":"liteyuki.plugins.liteecho","lastUpdated":false,"description":"liteyuki.plugins.liteecho : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/22 12:31 @Author : snowykami @Email : snowykami@outlook.com @File : li...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/plugins/liteecho.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/plugins/liteecho.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":"liteyuki.plugins.liteecho"}],["meta",{"property":"og:description","content":"liteyuki.plugins.liteecho : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/22 12:31 @Author : snowykami @Email : snowykami@outlook.com @File : li..."}],["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.plugins.liteecho\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"async def liteecho(event: MessageEvent)","slug":"async-def-liteecho-event-messageevent","link":"#async-def-liteecho-event-messageevent","children":[]}],"git":{"createdTime":1724912379000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":1}]},"readingTime":{"minutes":0.26,"words":77},"filePathRelative":"dev/api/plugins/liteecho.md","localizedDate":"2024829","autoDesc":true}');export{r as comp,d as data};

View File

@ -0,0 +1,4 @@
import{_ as e,o as t,c as n,e as s}from"./app-BvUYPzLF.js";const a={},o=s(`<h1 id="liteyuki-plugins-liteecho" tabindex="-1"><a class="header-anchor" href="#liteyuki-plugins-liteecho"><span>liteyuki.plugins.liteecho</span></a></h1><p><strong>Description</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/8/22 下午12:31 @Author : snowykami @Email : snowykami@outlook.com @File : liteecho.py @Software: PyCharm</p><p><code>@on_startswith([&#39;liteecho&#39;], rule=is_su_rule).handle()</code></p><h3 id="async-def-liteecho-event-messageevent" tabindex="-1"><a class="header-anchor" href="#async-def-liteecho-event-messageevent"><span><em><strong>async def</strong></em> <code>liteecho(event: MessageEvent)</code></span></a></h3><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/plugins/liteecho.py#L18" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token decorator annotation punctuation">@on_startswith</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">&#39;liteecho&#39;</span><span class="token punctuation">]</span><span class="token punctuation">,</span> rule<span class="token operator">=</span>is_su_rule<span class="token punctuation">)</span><span class="token punctuation">.</span>handle<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">liteecho</span><span class="token punctuation">(</span>event<span class="token punctuation">:</span> MessageEvent<span class="token punctuation">)</span><span class="token punctuation">:</span>
event<span class="token punctuation">.</span>reply<span class="token punctuation">(</span>event<span class="token punctuation">.</span>raw_message<span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">8</span><span class="token punctuation">:</span><span class="token punctuation">]</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</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></div></details>`,6),i=[o];function p(l,c){return t(),n("div",null,i)}const r=e(a,[["render",p],["__file","liteecho.html.vue"]]),d=JSON.parse('{"path":"/en/dev/api/plugins/liteecho.html","title":"liteyuki.plugins.liteecho","lang":"en-US","frontmatter":{"title":"liteyuki.plugins.liteecho","lastUpdated":false,"description":"liteyuki.plugins.liteecho Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/22 12:31 @Author : snowykami @Email : snowykami@outlook.com @...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/plugins/liteecho.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/plugins/liteecho.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.plugins.liteecho"}],["meta",{"property":"og:description","content":"liteyuki.plugins.liteecho Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/8/22 12:31 @Author : snowykami @Email : snowykami@outlook.com @..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.plugins.liteecho\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"async def liteecho(event: MessageEvent)","slug":"async-def-liteecho-event-messageevent","link":"#async-def-liteecho-event-messageevent","children":[]}],"git":{"createdTime":1724912379000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":1}]},"readingTime":{"minutes":0.24,"words":73},"filePathRelative":"en/dev/api/plugins/liteecho.md","localizedDate":"August 29, 2024","autoDesc":true}');export{r as comp,d as data};

View File

@ -0,0 +1,86 @@
import{_ as p,r as o,o as e,c as i,b as s,d as n,a as l,w as c,e as a}from"./app-BvUYPzLF.js";const u={},r=a(`<h1 id="liteyuki-plugin-load" tabindex="-1"><a class="header-anchor" href="#liteyuki-plugin-load"><span>liteyuki.plugin.load</span></a></h1><p><strong>说明</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/7/23 下午11:59 @Author : snowykami @Email : snowykami@outlook.com @File : load.py @Software: PyCharm</p><h3 id="def-load-plugin-module-path-str-path-optional-plugin" tabindex="-1"><a class="header-anchor" href="#def-load-plugin-module-path-str-path-optional-plugin"><span><em><strong>def</strong></em> <code>load_plugin(module_path: str | Path) -&gt; Optional[Plugin]</code></span></a></h3><p><strong>说明</strong>: 加载单个插件,可以是本地插件或是通过 <code>pip</code> 安装的插件。</p><p><strong>参数</strong>:</p><blockquote><ul><li>module_path: 插件名称 <code>path.to.your.plugin</code></li><li>或插件路径 <code>pathlib.Path(path/to/your/plugin)</code>:</li></ul></blockquote><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/plugin/load.py#L30" 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">load_plugin</span><span class="token punctuation">(</span>module_path<span class="token punctuation">:</span> <span class="token builtin">str</span> <span class="token operator">|</span> Path<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> Optional<span class="token punctuation">[</span>Plugin<span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;加载单个插件可以是本地插件或是通过 \`pip\` 安装的插件。
参数:
module_path: 插件名称 \`path.to.your.plugin\`
或插件路径 \`pathlib.Path(path/to/your/plugin)\`
&quot;&quot;&quot;</span>
module_path <span class="token operator">=</span> path_to_module_name<span class="token punctuation">(</span>Path<span class="token punctuation">(</span>module_path<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">if</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>module_path<span class="token punctuation">,</span> Path<span class="token punctuation">)</span> <span class="token keyword">else</span> module_path
<span class="token keyword">try</span><span class="token punctuation">:</span>
module <span class="token operator">=</span> import_module<span class="token punctuation">(</span>module_path<span class="token punctuation">)</span>
_plugins<span class="token punctuation">[</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">]</span> <span class="token operator">=</span> Plugin<span class="token punctuation">(</span>name<span class="token operator">=</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">,</span> module<span class="token operator">=</span>module<span class="token punctuation">,</span> module_name<span class="token operator">=</span>module_path<span class="token punctuation">)</span>
<span class="token keyword">if</span> module<span class="token punctuation">.</span>__dict__<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">&#39;__plugin_metadata__&#39;</span><span class="token punctuation">,</span> <span class="token boolean">None</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
metadata<span class="token punctuation">:</span> <span class="token string">&#39;PluginMetadata&#39;</span> <span class="token operator">=</span> module<span class="token punctuation">.</span>__dict__<span class="token punctuation">[</span><span class="token string">&#39;__plugin_metadata__&#39;</span><span class="token punctuation">]</span>
display_name <span class="token operator">=</span> module<span class="token punctuation">.</span>__name__<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">&#39;.&#39;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span>
<span class="token keyword">elif</span> module<span class="token punctuation">.</span>__dict__<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">&#39;__liteyuki_plugin_meta__&#39;</span><span class="token punctuation">,</span> <span class="token boolean">None</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
metadata<span class="token punctuation">:</span> <span class="token string">&#39;PluginMetadata&#39;</span> <span class="token operator">=</span> module<span class="token punctuation">.</span>__dict__<span class="token punctuation">[</span><span class="token string">&#39;__liteyuki_plugin_meta__&#39;</span><span class="token punctuation">]</span>
display_name <span class="token operator">=</span> format_display_name<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>metadata<span class="token punctuation">.</span>name<span class="token punctuation">}</span></span><span class="token string">(</span><span class="token interpolation"><span class="token punctuation">{</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">&#39;.&#39;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">)&quot;</span></span><span class="token punctuation">,</span> metadata<span class="token punctuation">.</span><span class="token builtin">type</span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> module<span class="token punctuation">.</span>__dict__<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">&#39;__plugin_meta__&#39;</span><span class="token punctuation">,</span> <span class="token boolean">None</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
metadata<span class="token punctuation">:</span> <span class="token string">&#39;PluginMetadata&#39;</span> <span class="token operator">=</span> module<span class="token punctuation">.</span>__dict__<span class="token punctuation">[</span><span class="token string">&#39;__plugin_meta__&#39;</span><span class="token punctuation">]</span>
display_name <span class="token operator">=</span> format_display_name<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>metadata<span class="token punctuation">.</span>name<span class="token punctuation">}</span></span><span class="token string">(</span><span class="token interpolation"><span class="token punctuation">{</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">&#39;.&#39;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">)&quot;</span></span><span class="token punctuation">,</span> metadata<span class="token punctuation">.</span><span class="token builtin">type</span><span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>opt<span class="token punctuation">(</span>colors<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span><span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;The metadata of Liteyuki plugin &quot;</span><span class="token interpolation"><span class="token punctuation">{</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">}</span></span><span class="token string">&quot; is not specified, use empty.&#39;</span></span><span class="token punctuation">)</span>
metadata <span class="token operator">=</span> PluginMetadata<span class="token punctuation">(</span>name<span class="token operator">=</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">)</span>
display_name <span class="token operator">=</span> module<span class="token punctuation">.</span>__name__<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">&#39;.&#39;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span>
_plugins<span class="token punctuation">[</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">]</span><span class="token punctuation">.</span>metadata <span class="token operator">=</span> metadata
logger<span class="token punctuation">.</span>opt<span class="token punctuation">(</span>colors<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span><span class="token punctuation">.</span>success<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Succeeded to load liteyuki plugin &quot;</span><span class="token interpolation"><span class="token punctuation">{</span>display_name<span class="token punctuation">}</span></span><span class="token string">&quot;&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">return</span> _plugins<span class="token punctuation">[</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">]</span>
<span class="token keyword">except</span> Exception <span class="token keyword">as</span> e<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>opt<span class="token punctuation">(</span>colors<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span><span class="token punctuation">.</span>success<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Failed to load liteyuki plugin &quot;&lt;r&gt;</span><span class="token interpolation"><span class="token punctuation">{</span>module_path<span class="token punctuation">}</span></span><span class="token string">&lt;/r&gt;&quot;&#39;</span></span><span class="token punctuation">)</span>
traceback<span class="token punctuation">.</span>print_exc<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token boolean">None</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 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-load-plugins-plugin-dir-str-ignore-warning-bool-true-set-plugin" tabindex="-1"><a class="header-anchor" href="#def-load-plugins-plugin-dir-str-ignore-warning-bool-true-set-plugin"><span><em><strong>def</strong></em> <code>load_plugins(*plugin_dir: str, *, ignore_warning: bool = True) -&gt; set[Plugin]</code></span></a></h3><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>plugin_dir: </li><li>ignore_warning: </li></ul></blockquote><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/plugin/load.py#L88" 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">load_plugins</span><span class="token punctuation">(</span><span class="token operator">*</span>plugin_dir<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> ignore_warning<span class="token punctuation">:</span> <span class="token builtin">bool</span><span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">set</span><span class="token punctuation">[</span>Plugin<span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;导入文件夹下多个插件
参数:
plugin_dir: 文件夹路径
ignore_warning: 是否忽略警告通常是目录不存在或目录为空
&quot;&quot;&quot;</span>
plugins <span class="token operator">=</span> <span class="token builtin">set</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">for</span> dir_path <span class="token keyword">in</span> plugin_dir<span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists<span class="token punctuation">(</span>dir_path<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> ignore_warning<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;Plugins dir &#39;</span><span class="token interpolation"><span class="token punctuation">{</span>dir_path<span class="token punctuation">}</span></span><span class="token string">&#39; does not exist.&quot;</span></span><span class="token punctuation">)</span>
<span class="token keyword">continue</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> os<span class="token punctuation">.</span>listdir<span class="token punctuation">(</span>dir_path<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> ignore_warning<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;Plugins dir &#39;</span><span class="token interpolation"><span class="token punctuation">{</span>dir_path<span class="token punctuation">}</span></span><span class="token string">&#39; is empty.&quot;</span></span><span class="token punctuation">)</span>
<span class="token keyword">continue</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>isdir<span class="token punctuation">(</span>dir_path<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> ignore_warning<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;Plugins dir &#39;</span><span class="token interpolation"><span class="token punctuation">{</span>dir_path<span class="token punctuation">}</span></span><span class="token string">&#39; is not a directory.&quot;</span></span><span class="token punctuation">)</span>
<span class="token keyword">continue</span>
<span class="token keyword">for</span> f <span class="token keyword">in</span> os<span class="token punctuation">.</span>listdir<span class="token punctuation">(</span>dir_path<span class="token punctuation">)</span><span class="token punctuation">:</span>
path <span class="token operator">=</span> Path<span class="token punctuation">(</span>os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>dir_path<span class="token punctuation">,</span> f<span class="token punctuation">)</span><span class="token punctuation">)</span>
module_name <span class="token operator">=</span> <span class="token boolean">None</span>
<span class="token keyword">if</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>isfile<span class="token punctuation">(</span>path<span class="token punctuation">)</span> <span class="token keyword">and</span> f<span class="token punctuation">.</span>endswith<span class="token punctuation">(</span><span class="token string">&#39;.py&#39;</span><span class="token punctuation">)</span> <span class="token keyword">and</span> <span class="token punctuation">(</span>f <span class="token operator">!=</span> <span class="token string">&#39;__init__.py&#39;</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
module_name <span class="token operator">=</span> <span class="token string-interpolation"><span class="token string">f&#39;</span><span class="token interpolation"><span class="token punctuation">{</span>path_to_module_name<span class="token punctuation">(</span>Path<span class="token punctuation">(</span>dir_path<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">.</span><span class="token interpolation"><span class="token punctuation">{</span>f<span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token format-spec">-3]</span><span class="token punctuation">}</span></span><span class="token string">&#39;</span></span>
<span class="token keyword">elif</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>isdir<span class="token punctuation">(</span>path<span class="token punctuation">)</span> <span class="token keyword">and</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists<span class="token punctuation">(</span>os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>path<span class="token punctuation">,</span> <span class="token string">&#39;__init__.py&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
module_name <span class="token operator">=</span> path_to_module_name<span class="token punctuation">(</span>path<span class="token punctuation">)</span>
<span class="token keyword">if</span> module_name<span class="token punctuation">:</span>
load_plugin<span class="token punctuation">(</span>module_name<span class="token punctuation">)</span>
<span class="token keyword">if</span> _plugins<span class="token punctuation">.</span>get<span class="token punctuation">(</span>module_name<span class="token punctuation">)</span><span class="token punctuation">:</span>
plugins<span class="token punctuation">.</span>add<span class="token punctuation">(</span>_plugins<span class="token punctuation">[</span>module_name<span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> plugins
</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 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-format-display-name-display-name-str-plugin-type-plugintype-str" tabindex="-1"><a class="header-anchor" href="#def-format-display-name-display-name-str-plugin-type-plugintype-str"><span><em><strong>def</strong></em> <code>format_display_name(display_name: str, plugin_type: PluginType) -&gt; str</code></span></a></h3><p><strong></strong>: </p><p><strong></strong>:</p><blockquote><ul><li>display_name: </li><li>plugin_type: </li></ul></blockquote>`,17),k=s("strong",null,"",-1),d=a(`<details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/plugin/load.py#L132" 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">format_display_name</span><span class="token punctuation">(</span>display_name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> plugin_type<span class="token punctuation">:</span> PluginType<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">str</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
设置插件名称颜色根据不同类型插件设置颜色
Args:
display_name: 插件名称
plugin_type: 插件类型
Returns:
str: 设置后的插件名称 &lt;y&gt;name&lt;/y&gt;
&quot;&quot;&quot;</span>
color <span class="token operator">=</span> <span class="token string">&#39;y&#39;</span>
<span class="token keyword">match</span> plugin_type<span class="token punctuation">:</span>
<span class="token keyword">case</span> PluginType<span class="token punctuation">.</span>APPLICATION<span class="token punctuation">:</span>
color <span class="token operator">=</span> <span class="token string">&#39;m&#39;</span>
<span class="token keyword">case</span> PluginType<span class="token punctuation">.</span>TEST<span class="token punctuation">:</span>
color <span class="token operator">=</span> <span class="token string">&#39;g&#39;</span>
<span class="token keyword">case</span> PluginType<span class="token punctuation">.</span>MODULE<span class="token punctuation">:</span>
color <span class="token operator">=</span> <span class="token string">&#39;e&#39;</span>
<span class="token keyword">case</span> PluginType<span class="token punctuation">.</span>SERVICE<span class="token punctuation">:</span>
color <span class="token operator">=</span> <span class="token string">&#39;c&#39;</span>
<span class="token keyword">return</span> <span class="token string-interpolation"><span class="token string">f&#39;&lt;</span><span class="token interpolation"><span class="token punctuation">{</span>color<span class="token punctuation">}</span></span><span class="token string">&gt;</span><span class="token interpolation"><span class="token punctuation">{</span>display_name<span class="token punctuation">}</span></span><span class="token string"> [</span><span class="token interpolation"><span class="token punctuation">{</span>plugin_type<span class="token punctuation">.</span>name<span class="token punctuation">}</span></span><span class="token string">]&lt;/</span><span class="token interpolation"><span class="token punctuation">{</span>color<span class="token punctuation">}</span></span><span class="token string">&gt;&#39;</span></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 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>`,1);function m(g,_){const t=o("y");return e(),i("div",null,[r,s("p",null,[k,n(": str: "),l(t,null,{default:c(()=>[n("name")]),_:1})]),d])}const y=p(u,[["render",m],["__file","load.html.vue"]]),b=JSON.parse('{"path":"/dev/api/plugin/load.html","title":"liteyuki.plugin.load","lang":"zh-CN","frontmatter":{"title":"liteyuki.plugin.load","lastUpdated":false,"description":"liteyuki.plugin.load : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 11:59 @Author : snowykami @Email : snowykami@outlook.com @File : load.py...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/plugin/load.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/plugin/load.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":"liteyuki.plugin.load"}],["meta",{"property":"og:description","content":"liteyuki.plugin.load : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 11:59 @Author : snowykami @Email : snowykami@outlook.com @File : load.py..."}],["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.plugin.load\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def load_plugin(module_path: str | Path) -> Optional[Plugin]","slug":"def-load-plugin-module-path-str-path-optional-plugin","link":"#def-load-plugin-module-path-str-path-optional-plugin","children":[]},{"level":3,"title":"def load_plugins(*plugin_dir: str, *, ignore_warning: bool = True) -> set[Plugin]","slug":"def-load-plugins-plugin-dir-str-ignore-warning-bool-true-set-plugin","link":"#def-load-plugins-plugin-dir-str-ignore-warning-bool-true-set-plugin","children":[]},{"level":3,"title":"def format_display_name(display_name: str, plugin_type: PluginType) -> str","slug":"def-format-display-name-display-name-str-plugin-type-plugintype-str","link":"#def-format-display-name-display-name-str-plugin-type-plugintype-str","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":5}]},"readingTime":{"minutes":2.19,"words":658},"filePathRelative":"dev/api/plugin/load.md","localizedDate":"2024819","autoDesc":true}');export{y as comp,b as data};

View File

@ -0,0 +1,86 @@
import{_ as p,r as o,o as e,c as i,b as s,d as n,a as l,w as c,e as a}from"./app-BvUYPzLF.js";const u={},r=a(`<h1 id="liteyuki-plugin-load" tabindex="-1"><a class="header-anchor" href="#liteyuki-plugin-load"><span>liteyuki.plugin.load</span></a></h1><p><strong>Description</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/7/23 下午11:59 @Author : snowykami @Email : snowykami@outlook.com @File : load.py @Software: PyCharm</p><h3 id="def-load-plugin-module-path-str-path-optional-plugin" tabindex="-1"><a class="header-anchor" href="#def-load-plugin-module-path-str-path-optional-plugin"><span><em><strong>def</strong></em> <code>load_plugin(module_path: str | Path) -&gt; Optional[Plugin]</code></span></a></h3><p><strong>Description</strong>: 加载单个插件,可以是本地插件或是通过 <code>pip</code> 安装的插件。</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>module_path: 插件名称 <code>path.to.your.plugin</code></li><li>或插件路径 <code>pathlib.Path(path/to/your/plugin)</code>:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/plugin/load.py#L30" target="_blank">View on 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">load_plugin</span><span class="token punctuation">(</span>module_path<span class="token punctuation">:</span> <span class="token builtin">str</span> <span class="token operator">|</span> Path<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> Optional<span class="token punctuation">[</span>Plugin<span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;加载单个插件可以是本地插件或是通过 \`pip\` 安装的插件。
参数:
module_path: 插件名称 \`path.to.your.plugin\`
或插件路径 \`pathlib.Path(path/to/your/plugin)\`
&quot;&quot;&quot;</span>
module_path <span class="token operator">=</span> path_to_module_name<span class="token punctuation">(</span>Path<span class="token punctuation">(</span>module_path<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">if</span> <span class="token builtin">isinstance</span><span class="token punctuation">(</span>module_path<span class="token punctuation">,</span> Path<span class="token punctuation">)</span> <span class="token keyword">else</span> module_path
<span class="token keyword">try</span><span class="token punctuation">:</span>
module <span class="token operator">=</span> import_module<span class="token punctuation">(</span>module_path<span class="token punctuation">)</span>
_plugins<span class="token punctuation">[</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">]</span> <span class="token operator">=</span> Plugin<span class="token punctuation">(</span>name<span class="token operator">=</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">,</span> module<span class="token operator">=</span>module<span class="token punctuation">,</span> module_name<span class="token operator">=</span>module_path<span class="token punctuation">)</span>
<span class="token keyword">if</span> module<span class="token punctuation">.</span>__dict__<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">&#39;__plugin_metadata__&#39;</span><span class="token punctuation">,</span> <span class="token boolean">None</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
metadata<span class="token punctuation">:</span> <span class="token string">&#39;PluginMetadata&#39;</span> <span class="token operator">=</span> module<span class="token punctuation">.</span>__dict__<span class="token punctuation">[</span><span class="token string">&#39;__plugin_metadata__&#39;</span><span class="token punctuation">]</span>
display_name <span class="token operator">=</span> module<span class="token punctuation">.</span>__name__<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">&#39;.&#39;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span>
<span class="token keyword">elif</span> module<span class="token punctuation">.</span>__dict__<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">&#39;__liteyuki_plugin_meta__&#39;</span><span class="token punctuation">,</span> <span class="token boolean">None</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
metadata<span class="token punctuation">:</span> <span class="token string">&#39;PluginMetadata&#39;</span> <span class="token operator">=</span> module<span class="token punctuation">.</span>__dict__<span class="token punctuation">[</span><span class="token string">&#39;__liteyuki_plugin_meta__&#39;</span><span class="token punctuation">]</span>
display_name <span class="token operator">=</span> format_display_name<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>metadata<span class="token punctuation">.</span>name<span class="token punctuation">}</span></span><span class="token string">(</span><span class="token interpolation"><span class="token punctuation">{</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">&#39;.&#39;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">)&quot;</span></span><span class="token punctuation">,</span> metadata<span class="token punctuation">.</span><span class="token builtin">type</span><span class="token punctuation">)</span>
<span class="token keyword">elif</span> module<span class="token punctuation">.</span>__dict__<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">&#39;__plugin_meta__&#39;</span><span class="token punctuation">,</span> <span class="token boolean">None</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
metadata<span class="token punctuation">:</span> <span class="token string">&#39;PluginMetadata&#39;</span> <span class="token operator">=</span> module<span class="token punctuation">.</span>__dict__<span class="token punctuation">[</span><span class="token string">&#39;__plugin_meta__&#39;</span><span class="token punctuation">]</span>
display_name <span class="token operator">=</span> format_display_name<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>metadata<span class="token punctuation">.</span>name<span class="token punctuation">}</span></span><span class="token string">(</span><span class="token interpolation"><span class="token punctuation">{</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">&#39;.&#39;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">)&quot;</span></span><span class="token punctuation">,</span> metadata<span class="token punctuation">.</span><span class="token builtin">type</span><span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>opt<span class="token punctuation">(</span>colors<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span><span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;The metadata of Liteyuki plugin &quot;</span><span class="token interpolation"><span class="token punctuation">{</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">}</span></span><span class="token string">&quot; is not specified, use empty.&#39;</span></span><span class="token punctuation">)</span>
metadata <span class="token operator">=</span> PluginMetadata<span class="token punctuation">(</span>name<span class="token operator">=</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">)</span>
display_name <span class="token operator">=</span> module<span class="token punctuation">.</span>__name__<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">&#39;.&#39;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span>
_plugins<span class="token punctuation">[</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">]</span><span class="token punctuation">.</span>metadata <span class="token operator">=</span> metadata
logger<span class="token punctuation">.</span>opt<span class="token punctuation">(</span>colors<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span><span class="token punctuation">.</span>success<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Succeeded to load liteyuki plugin &quot;</span><span class="token interpolation"><span class="token punctuation">{</span>display_name<span class="token punctuation">}</span></span><span class="token string">&quot;&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">return</span> _plugins<span class="token punctuation">[</span>module<span class="token punctuation">.</span>__name__<span class="token punctuation">]</span>
<span class="token keyword">except</span> Exception <span class="token keyword">as</span> e<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>opt<span class="token punctuation">(</span>colors<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span><span class="token punctuation">.</span>success<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Failed to load liteyuki plugin &quot;&lt;r&gt;</span><span class="token interpolation"><span class="token punctuation">{</span>module_path<span class="token punctuation">}</span></span><span class="token string">&lt;/r&gt;&quot;&#39;</span></span><span class="token punctuation">)</span>
traceback<span class="token punctuation">.</span>print_exc<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token boolean">None</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 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-load-plugins-plugin-dir-str-ignore-warning-bool-true-set-plugin" tabindex="-1"><a class="header-anchor" href="#def-load-plugins-plugin-dir-str-ignore-warning-bool-true-set-plugin"><span><em><strong>def</strong></em> <code>load_plugins(*plugin_dir: str, *, ignore_warning: bool = True) -&gt; set[Plugin]</code></span></a></h3><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>plugin_dir: </li><li>ignore_warning: </li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/plugin/load.py#L88" target="_blank">View on 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">load_plugins</span><span class="token punctuation">(</span><span class="token operator">*</span>plugin_dir<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> ignore_warning<span class="token punctuation">:</span> <span class="token builtin">bool</span><span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">set</span><span class="token punctuation">[</span>Plugin<span class="token punctuation">]</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;导入文件夹下多个插件
参数:
plugin_dir: 文件夹路径
ignore_warning: 是否忽略警告通常是目录不存在或目录为空
&quot;&quot;&quot;</span>
plugins <span class="token operator">=</span> <span class="token builtin">set</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">for</span> dir_path <span class="token keyword">in</span> plugin_dir<span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists<span class="token punctuation">(</span>dir_path<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> ignore_warning<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;Plugins dir &#39;</span><span class="token interpolation"><span class="token punctuation">{</span>dir_path<span class="token punctuation">}</span></span><span class="token string">&#39; does not exist.&quot;</span></span><span class="token punctuation">)</span>
<span class="token keyword">continue</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> os<span class="token punctuation">.</span>listdir<span class="token punctuation">(</span>dir_path<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> ignore_warning<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;Plugins dir &#39;</span><span class="token interpolation"><span class="token punctuation">{</span>dir_path<span class="token punctuation">}</span></span><span class="token string">&#39; is empty.&quot;</span></span><span class="token punctuation">)</span>
<span class="token keyword">continue</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>isdir<span class="token punctuation">(</span>dir_path<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> <span class="token keyword">not</span> ignore_warning<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;Plugins dir &#39;</span><span class="token interpolation"><span class="token punctuation">{</span>dir_path<span class="token punctuation">}</span></span><span class="token string">&#39; is not a directory.&quot;</span></span><span class="token punctuation">)</span>
<span class="token keyword">continue</span>
<span class="token keyword">for</span> f <span class="token keyword">in</span> os<span class="token punctuation">.</span>listdir<span class="token punctuation">(</span>dir_path<span class="token punctuation">)</span><span class="token punctuation">:</span>
path <span class="token operator">=</span> Path<span class="token punctuation">(</span>os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>dir_path<span class="token punctuation">,</span> f<span class="token punctuation">)</span><span class="token punctuation">)</span>
module_name <span class="token operator">=</span> <span class="token boolean">None</span>
<span class="token keyword">if</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>isfile<span class="token punctuation">(</span>path<span class="token punctuation">)</span> <span class="token keyword">and</span> f<span class="token punctuation">.</span>endswith<span class="token punctuation">(</span><span class="token string">&#39;.py&#39;</span><span class="token punctuation">)</span> <span class="token keyword">and</span> <span class="token punctuation">(</span>f <span class="token operator">!=</span> <span class="token string">&#39;__init__.py&#39;</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
module_name <span class="token operator">=</span> <span class="token string-interpolation"><span class="token string">f&#39;</span><span class="token interpolation"><span class="token punctuation">{</span>path_to_module_name<span class="token punctuation">(</span>Path<span class="token punctuation">(</span>dir_path<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">.</span><span class="token interpolation"><span class="token punctuation">{</span>f<span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token format-spec">-3]</span><span class="token punctuation">}</span></span><span class="token string">&#39;</span></span>
<span class="token keyword">elif</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>isdir<span class="token punctuation">(</span>path<span class="token punctuation">)</span> <span class="token keyword">and</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists<span class="token punctuation">(</span>os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>path<span class="token punctuation">,</span> <span class="token string">&#39;__init__.py&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
module_name <span class="token operator">=</span> path_to_module_name<span class="token punctuation">(</span>path<span class="token punctuation">)</span>
<span class="token keyword">if</span> module_name<span class="token punctuation">:</span>
load_plugin<span class="token punctuation">(</span>module_name<span class="token punctuation">)</span>
<span class="token keyword">if</span> _plugins<span class="token punctuation">.</span>get<span class="token punctuation">(</span>module_name<span class="token punctuation">)</span><span class="token punctuation">:</span>
plugins<span class="token punctuation">.</span>add<span class="token punctuation">(</span>_plugins<span class="token punctuation">[</span>module_name<span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> plugins
</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 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-format-display-name-display-name-str-plugin-type-plugintype-str" tabindex="-1"><a class="header-anchor" href="#def-format-display-name-display-name-str-plugin-type-plugintype-str"><span><em><strong>def</strong></em> <code>format_display_name(display_name: str, plugin_type: PluginType) -&gt; str</code></span></a></h3><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>display_name: </li><li>plugin_type: </li></ul></blockquote>`,17),k=s("strong",null,"Return",-1),d=a(`<details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/plugin/load.py#L132" target="_blank">View on 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">format_display_name</span><span class="token punctuation">(</span>display_name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> plugin_type<span class="token punctuation">:</span> PluginType<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">str</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
设置插件名称颜色根据不同类型插件设置颜色
Args:
display_name: 插件名称
plugin_type: 插件类型
Returns:
str: 设置后的插件名称 &lt;y&gt;name&lt;/y&gt;
&quot;&quot;&quot;</span>
color <span class="token operator">=</span> <span class="token string">&#39;y&#39;</span>
<span class="token keyword">match</span> plugin_type<span class="token punctuation">:</span>
<span class="token keyword">case</span> PluginType<span class="token punctuation">.</span>APPLICATION<span class="token punctuation">:</span>
color <span class="token operator">=</span> <span class="token string">&#39;m&#39;</span>
<span class="token keyword">case</span> PluginType<span class="token punctuation">.</span>TEST<span class="token punctuation">:</span>
color <span class="token operator">=</span> <span class="token string">&#39;g&#39;</span>
<span class="token keyword">case</span> PluginType<span class="token punctuation">.</span>MODULE<span class="token punctuation">:</span>
color <span class="token operator">=</span> <span class="token string">&#39;e&#39;</span>
<span class="token keyword">case</span> PluginType<span class="token punctuation">.</span>SERVICE<span class="token punctuation">:</span>
color <span class="token operator">=</span> <span class="token string">&#39;c&#39;</span>
<span class="token keyword">return</span> <span class="token string-interpolation"><span class="token string">f&#39;&lt;</span><span class="token interpolation"><span class="token punctuation">{</span>color<span class="token punctuation">}</span></span><span class="token string">&gt;</span><span class="token interpolation"><span class="token punctuation">{</span>display_name<span class="token punctuation">}</span></span><span class="token string"> [</span><span class="token interpolation"><span class="token punctuation">{</span>plugin_type<span class="token punctuation">.</span>name<span class="token punctuation">}</span></span><span class="token string">]&lt;/</span><span class="token interpolation"><span class="token punctuation">{</span>color<span class="token punctuation">}</span></span><span class="token string">&gt;&#39;</span></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 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>`,1);function m(g,_){const t=o("y");return e(),i("div",null,[r,s("p",null,[k,n(": str: "),l(t,null,{default:c(()=>[n("name")]),_:1})]),d])}const y=p(u,[["render",m],["__file","load.html.vue"]]),b=JSON.parse('{"path":"/en/dev/api/plugin/load.html","title":"liteyuki.plugin.load","lang":"en-US","frontmatter":{"title":"liteyuki.plugin.load","lastUpdated":false,"description":"liteyuki.plugin.load Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 11:59 @Author : snowykami @Email : snowykami@outlook.com @File ...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/plugin/load.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/plugin/load.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.plugin.load"}],["meta",{"property":"og:description","content":"liteyuki.plugin.load Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 11:59 @Author : snowykami @Email : snowykami@outlook.com @File ..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.plugin.load\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def load_plugin(module_path: str | Path) -> Optional[Plugin]","slug":"def-load-plugin-module-path-str-path-optional-plugin","link":"#def-load-plugin-module-path-str-path-optional-plugin","children":[]},{"level":3,"title":"def load_plugins(*plugin_dir: str, *, ignore_warning: bool = True) -> set[Plugin]","slug":"def-load-plugins-plugin-dir-str-ignore-warning-bool-true-set-plugin","link":"#def-load-plugins-plugin-dir-str-ignore-warning-bool-true-set-plugin","children":[]},{"level":3,"title":"def format_display_name(display_name: str, plugin_type: PluginType) -> str","slug":"def-format-display-name-display-name-str-plugin-type-plugintype-str","link":"#def-format-display-name-display-name-str-plugin-type-plugintype-str","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":2.14,"words":641},"filePathRelative":"en/dev/api/plugin/load.md","localizedDate":"August 21, 2024","autoDesc":true}');export{y as comp,b as data};

View File

@ -0,0 +1,20 @@
import{_ as n,o as s,c as a,e as t}from"./app-BvUYPzLF.js";const e={},o=t(`<h1 id="liteyuki-log" tabindex="-1"><a class="header-anchor" href="#liteyuki-log"><span>liteyuki.log</span></a></h1><p><strong>Description</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/7/27 上午9:12 @Author : snowykami @Email : snowykami@outlook.com @File : log.py @Software: PyCharm</p><h3 id="def-get-format-level-str-str" tabindex="-1"><a class="header-anchor" href="#def-get-format-level-str-str"><span><em><strong>def</strong></em> <code>get_format(level: str) -&gt; str</code></span></a></h3><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/log.py#L34" target="_blank">View on 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">get_format</span><span class="token punctuation">(</span>level<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">str</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> level <span class="token operator">==</span> <span class="token string">&#39;DEBUG&#39;</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> debug_format
<span class="token keyword">else</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> default_format
</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></div></details><h3 id="def-init-log-config-dict" tabindex="-1"><a class="header-anchor" href="#def-init-log-config-dict"><span><em><strong>def</strong></em> <code>init_log(config: dict)</code></span></a></h3><p><strong>Description</strong>: </p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/log.py#L41" target="_blank">View on 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_log</span><span class="token punctuation">(</span>config<span class="token punctuation">:</span> <span class="token builtin">dict</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
在语言加载完成后执行
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>remove<span class="token punctuation">(</span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>add<span class="token punctuation">(</span>sys<span class="token punctuation">.</span>stdout<span class="token punctuation">,</span> level<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">,</span> diagnose<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> <span class="token builtin">format</span><span class="token operator">=</span>get_format<span class="token punctuation">(</span>config<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">&#39;log_level&#39;</span><span class="token punctuation">,</span> <span class="token string">&#39;INFO&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
show_icon <span class="token operator">=</span> config<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">&#39;log_icon&#39;</span><span class="token punctuation">,</span> <span class="token boolean">True</span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>level<span class="token punctuation">(</span><span class="token string">&#39;DEBUG&#39;</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">&#39;&lt;blue&gt;&#39;</span><span class="token punctuation">,</span> icon<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token string">&#39;🐛&#39;</span> <span class="token keyword">if</span> show_icon <span class="token keyword">else</span> <span class="token string">&#39;&#39;</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">DEBUG&quot;</span></span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>level<span class="token punctuation">(</span><span class="token string">&#39;INFO&#39;</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">&#39;&lt;normal&gt;&#39;</span><span class="token punctuation">,</span> icon<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token string">&#39;&#39;</span> <span class="token keyword">if</span> show_icon <span class="token keyword">else</span> <span class="token string">&#39;&#39;</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">INFO&quot;</span></span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>level<span class="token punctuation">(</span><span class="token string">&#39;SUCCESS&#39;</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">&#39;&lt;green&gt;&#39;</span><span class="token punctuation">,</span> icon<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token string">&#39;&#39;</span> <span class="token keyword">if</span> show_icon <span class="token keyword">else</span> <span class="token string">&#39;&#39;</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">SUCCESS&quot;</span></span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>level<span class="token punctuation">(</span><span class="token string">&#39;WARNING&#39;</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">&#39;&lt;yellow&gt;&#39;</span><span class="token punctuation">,</span> icon<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token string">&#39;&#39;</span> <span class="token keyword">if</span> show_icon <span class="token keyword">else</span> <span class="token string">&#39;&#39;</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">WARNING&quot;</span></span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>level<span class="token punctuation">(</span><span class="token string">&#39;ERROR&#39;</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">&#39;&lt;red&gt;&#39;</span><span class="token punctuation">,</span> icon<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token string">&#39;&#39;</span> <span class="token keyword">if</span> show_icon <span class="token keyword">else</span> <span class="token string">&#39;&#39;</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">ERROR&quot;</span></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>`,8),p=[o];function i(l,c){return s(),a("div",null,p)}const u=n(e,[["render",i],["__file","log.html.vue"]]),k=JSON.parse('{"path":"/en/dev/api/log.html","title":"liteyuki.log","lang":"en-US","frontmatter":{"title":"liteyuki.log","lastUpdated":false,"description":"liteyuki.log Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/27 9:12 @Author : snowykami @Email : snowykami@outlook.com @File : log.py ...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/log.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/log.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.log"}],["meta",{"property":"og:description","content":"liteyuki.log Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/27 9:12 @Author : snowykami @Email : snowykami@outlook.com @File : log.py ..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.log\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def get_format(level: str) -> str","slug":"def-get-format-level-str-str","link":"#def-get-format-level-str-str","children":[]},{"level":3,"title":"def init_log(config: dict)","slug":"def-init-log-config-dict","link":"#def-init-log-config-dict","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.61,"words":184},"filePathRelative":"en/dev/api/log.md","localizedDate":"August 21, 2024","autoDesc":true}');export{u as comp,k as data};

View File

@ -0,0 +1,20 @@
import{_ as n,o as s,c as a,e as t}from"./app-BvUYPzLF.js";const e={},o=t(`<h1 id="liteyuki-log" tabindex="-1"><a class="header-anchor" href="#liteyuki-log"><span>liteyuki.log</span></a></h1><p><strong>说明</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/7/27 上午9:12 @Author : snowykami @Email : snowykami@outlook.com @File : log.py @Software: PyCharm</p><h3 id="def-get-format-level-str-str" tabindex="-1"><a class="header-anchor" href="#def-get-format-level-str-str"><span><em><strong>def</strong></em> <code>get_format(level: str) -&gt; str</code></span></a></h3><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/log.py#L34" 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">get_format</span><span class="token punctuation">(</span>level<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">str</span><span class="token punctuation">:</span>
<span class="token keyword">if</span> level <span class="token operator">==</span> <span class="token string">&#39;DEBUG&#39;</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> debug_format
<span class="token keyword">else</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> default_format
</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></div></details><h3 id="def-init-log-config-dict" tabindex="-1"><a class="header-anchor" href="#def-init-log-config-dict"><span><em><strong>def</strong></em> <code>init_log(config: dict)</code></span></a></h3><p><strong></strong>: </p><details><summary><b></b> <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/log.py#L41" 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_log</span><span class="token punctuation">(</span>config<span class="token punctuation">:</span> <span class="token builtin">dict</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
在语言加载完成后执行
Returns:
&quot;&quot;&quot;</span>
logger<span class="token punctuation">.</span>remove<span class="token punctuation">(</span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>add<span class="token punctuation">(</span>sys<span class="token punctuation">.</span>stdout<span class="token punctuation">,</span> level<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">,</span> diagnose<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> <span class="token builtin">format</span><span class="token operator">=</span>get_format<span class="token punctuation">(</span>config<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">&#39;log_level&#39;</span><span class="token punctuation">,</span> <span class="token string">&#39;INFO&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
show_icon <span class="token operator">=</span> config<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token string">&#39;log_icon&#39;</span><span class="token punctuation">,</span> <span class="token boolean">True</span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>level<span class="token punctuation">(</span><span class="token string">&#39;DEBUG&#39;</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">&#39;&lt;blue&gt;&#39;</span><span class="token punctuation">,</span> icon<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token string">&#39;🐛&#39;</span> <span class="token keyword">if</span> show_icon <span class="token keyword">else</span> <span class="token string">&#39;&#39;</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">DEBUG&quot;</span></span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>level<span class="token punctuation">(</span><span class="token string">&#39;INFO&#39;</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">&#39;&lt;normal&gt;&#39;</span><span class="token punctuation">,</span> icon<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token string">&#39;&#39;</span> <span class="token keyword">if</span> show_icon <span class="token keyword">else</span> <span class="token string">&#39;&#39;</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">INFO&quot;</span></span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>level<span class="token punctuation">(</span><span class="token string">&#39;SUCCESS&#39;</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">&#39;&lt;green&gt;&#39;</span><span class="token punctuation">,</span> icon<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token string">&#39;&#39;</span> <span class="token keyword">if</span> show_icon <span class="token keyword">else</span> <span class="token string">&#39;&#39;</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">SUCCESS&quot;</span></span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>level<span class="token punctuation">(</span><span class="token string">&#39;WARNING&#39;</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">&#39;&lt;yellow&gt;&#39;</span><span class="token punctuation">,</span> icon<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token string">&#39;&#39;</span> <span class="token keyword">if</span> show_icon <span class="token keyword">else</span> <span class="token string">&#39;&#39;</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">WARNING&quot;</span></span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>level<span class="token punctuation">(</span><span class="token string">&#39;ERROR&#39;</span><span class="token punctuation">,</span> color<span class="token operator">=</span><span class="token string">&#39;&lt;red&gt;&#39;</span><span class="token punctuation">,</span> icon<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f&quot;</span><span class="token interpolation"><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token string">&#39;&#39;</span> <span class="token keyword">if</span> show_icon <span class="token keyword">else</span> <span class="token string">&#39;&#39;</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token string">ERROR&quot;</span></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>`,8),p=[o];function l(i,c){return s(),a("div",null,p)}const u=n(e,[["render",l],["__file","log.html.vue"]]),k=JSON.parse('{"path":"/dev/api/log.html","title":"liteyuki.log","lang":"zh-CN","frontmatter":{"title":"liteyuki.log","lastUpdated":false,"description":"liteyuki.log : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/27 9:12 @Author : snowykami @Email : snowykami@outlook.com @File : log.py @Software...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/log.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/log.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot "}],["meta",{"property":"og:title","content":"liteyuki.log"}],["meta",{"property":"og:description","content":"liteyuki.log : Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/27 9:12 @Author : snowykami @Email : snowykami@outlook.com @File : log.py @Software..."}],["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.log\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def get_format(level: str) -> str","slug":"def-get-format-level-str-str","link":"#def-get-format-level-str-str","children":[]},{"level":3,"title":"def init_log(config: dict)","slug":"def-init-log-config-dict","link":"#def-init-log-config-dict","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":5}]},"readingTime":{"minutes":0.64,"words":192},"filePathRelative":"dev/api/log.md","localizedDate":"2024819","autoDesc":true}');export{u as comp,k as data};

View File

@ -0,0 +1,101 @@
import{_ as n,o as s,c as a,e as t}from"./app-BvUYPzLF.js";const e={},p=t(`<h1 id="liteyuki-core-manager" tabindex="-1"><a class="header-anchor" href="#liteyuki-core-manager"><span>liteyuki.core.manager</span></a></h1><p><strong>Description</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/7/27 上午11:12 @Author : snowykami @Email : snowykami@outlook.com @File : manager.py @Software: PyCharm</p><h3 id="class-channeldeliver" tabindex="-1"><a class="header-anchor" href="#class-channeldeliver"><span><em><strong>class</strong></em> <code>ChannelDeliver</code></span></a></h3><h4 id="def-init-self-active-channel-any-passive-channel-any-channel-deliver-active-channel-channel-any-channel-deliver-passive-channel-tuple-str-dict-publish-channel-tuple-str-any" tabindex="-1"><a class="header-anchor" href="#def-init-self-active-channel-any-passive-channel-any-channel-deliver-active-channel-channel-any-channel-deliver-passive-channel-tuple-str-dict-publish-channel-tuple-str-any"><span><em><strong>def</strong></em> <code>__init__(self, active: Channel[Any], passive: Channel[Any], channel_deliver_active: Channel[Channel[Any]], channel_deliver_passive: Channel[tuple[str, dict]], publish: Channel[tuple[str, Any]])</code></span></a></h4><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/core/manager.py#L43" target="_blank">View on 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> active<span class="token punctuation">:</span> Channel<span class="token punctuation">[</span>Any<span class="token punctuation">]</span><span class="token punctuation">,</span> passive<span class="token punctuation">:</span> Channel<span class="token punctuation">[</span>Any<span class="token punctuation">]</span><span class="token punctuation">,</span> channel_deliver_active<span class="token punctuation">:</span> Channel<span class="token punctuation">[</span>Channel<span class="token punctuation">[</span>Any<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">,</span> channel_deliver_passive<span class="token punctuation">:</span> Channel<span class="token punctuation">[</span><span class="token builtin">tuple</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">,</span> <span class="token builtin">dict</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">,</span> publish<span class="token punctuation">:</span> Channel<span class="token punctuation">[</span><span class="token builtin">tuple</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 punctuation">:</span>
self<span class="token punctuation">.</span>active <span class="token operator">=</span> active
self<span class="token punctuation">.</span>passive <span class="token operator">=</span> passive
self<span class="token punctuation">.</span>channel_deliver_active <span class="token operator">=</span> channel_deliver_active
self<span class="token punctuation">.</span>channel_deliver_passive <span class="token operator">=</span> channel_deliver_passive
self<span class="token punctuation">.</span>publish <span class="token operator">=</span> publish
</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></div></details><h3 id="class-processmanager" tabindex="-1"><a class="header-anchor" href="#class-processmanager"><span><em><strong>class</strong></em> <code>ProcessManager</code></span></a></h3><h4 id="def-init-self-lifespan-lifespan" tabindex="-1"><a class="header-anchor" href="#def-init-self-lifespan-lifespan"><span><em><strong>def</strong></em> <code>__init__(self, lifespan: Lifespan)</code></span></a></h4><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/core/manager.py#L86" target="_blank">View on 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> lifespan<span class="token punctuation">:</span> <span class="token string">&#39;Lifespan&#39;</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
self<span class="token punctuation">.</span>lifespan <span class="token operator">=</span> lifespan
self<span class="token punctuation">.</span>targets<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> <span class="token builtin">tuple</span><span class="token punctuation">[</span>Callable<span class="token punctuation">,</span> <span class="token builtin">tuple</span><span class="token punctuation">,</span> <span class="token builtin">dict</span><span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
self<span class="token punctuation">.</span>processes<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> Process<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></div></details><h4 id="async-def-run-process-self-name-str" tabindex="-1"><a class="header-anchor" href="#async-def-run-process-self-name-str"><span><em><strong>async def</strong></em> <code>_run_process(self, name: str)</code></span></a></h4><p><strong>Description</strong>: task</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>name:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/core/manager.py#L91" target="_blank">View on 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_process</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
开启后自动监控进程并添加到进程字典中会阻塞请创建task
Args:
name:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> name <span class="token keyword">not</span> <span class="token keyword">in</span> self<span class="token punctuation">.</span>targets<span class="token punctuation">:</span>
<span class="token keyword">raise</span> KeyError<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Process </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> not found.&#39;</span></span><span class="token punctuation">)</span>
chan_active <span class="token operator">=</span> get_channel<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;</span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string">-active&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">_start_process</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
process <span class="token operator">=</span> Process<span class="token punctuation">(</span>target<span class="token operator">=</span>self<span class="token punctuation">.</span>targets<span class="token punctuation">[</span>name<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> args<span class="token operator">=</span>self<span class="token punctuation">.</span>targets<span class="token punctuation">[</span>name<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> kwargs<span class="token operator">=</span>self<span class="token punctuation">.</span>targets<span class="token punctuation">[</span>name<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> daemon<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>processes<span class="token punctuation">[</span>name<span class="token punctuation">]</span> <span class="token operator">=</span> process
process<span class="token punctuation">.</span>start<span class="token punctuation">(</span><span class="token punctuation">)</span>
_start_process<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
data <span class="token operator">=</span> <span class="token keyword">await</span> chan_active<span class="token punctuation">.</span>async_receive<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">if</span> data <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Stopping process </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>before_process_shutdown<span class="token punctuation">(</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>terminate<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
<span class="token keyword">break</span>
<span class="token keyword">elif</span> data <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Restarting process </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string">&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>before_process_shutdown<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">await</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>before_process_restart<span class="token punctuation">(</span><span class="token punctuation">)</span>
self<span class="token punctuation">.</span>terminate<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
_start_process<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">continue</span>
<span class="token keyword">else</span><span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string">&#39;Unknown data received, ignored.&#39;</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 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><h4 id="async-def-start-all-self" tabindex="-1"><a class="header-anchor" href="#async-def-start-all-self"><span><em><strong>async def</strong></em> <code>start_all(self)</code></span></a></h4><p><strong>Description</strong>: asyncio task</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/core/manager.py#L131" target="_blank">View on 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">start_all</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
对外启动方法启动所有进程创建asyncio task
&quot;&quot;&quot;</span>
<span class="token punctuation">[</span>asyncio<span class="token punctuation">.</span>create_task<span class="token punctuation">(</span>chan<span class="token punctuation">.</span>start_receive_loop<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">for</span> chan <span class="token keyword">in</span> get_channels<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>values<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span>asyncio<span class="token punctuation">.</span>create_task<span class="token punctuation">(</span>sm<span class="token punctuation">.</span>start_receive_loop<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">for</span> sm <span class="token keyword">in</span> <span class="token punctuation">[</span>shared_memory<span class="token punctuation">]</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span>asyncio<span class="token punctuation">.</span>create_task<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_run_process<span class="token punctuation">(</span>name<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">for</span> name <span class="token keyword">in</span> self<span class="token punctuation">.</span>targets<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></div></details><h4 id="def-add-target-self-name-str-target-target-func-args-tuple-kwargs-none" tabindex="-1"><a class="header-anchor" href="#def-add-target-self-name-str-target-target-func-args-tuple-kwargs-none"><span><em><strong>def</strong></em> <code>add_target(self, name: str, target: TARGET_FUNC, args: tuple = (), kwargs = None)</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>name: </li><li>target: </li><li>args: </li><li>kwargs: chan_activechan_passive</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/core/manager.py#L139" target="_blank">View on 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">add_target</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> target<span class="token punctuation">:</span> TARGET_FUNC<span class="token punctuation">,</span> args<span class="token punctuation">:</span> <span class="token builtin">tuple</span><span class="token operator">=</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> kwargs<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
添加进程
Args:
name: 进程名用于获取和唯一标识
target: 进程函数
args: 进程函数参数
kwargs: 进程函数关键字参数通常会默认传入chan_active和chan_passive
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> kwargs <span class="token keyword">is</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
kwargs <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
chan_active<span class="token punctuation">:</span> Channel <span class="token operator">=</span> Channel<span class="token punctuation">(</span>name<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f&#39;</span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string">-active&#39;</span></span><span class="token punctuation">)</span>
chan_passive<span class="token punctuation">:</span> Channel <span class="token operator">=</span> Channel<span class="token punctuation">(</span>name<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f&#39;</span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string">-passive&#39;</span></span><span class="token punctuation">)</span>
channel_deliver <span class="token operator">=</span> ChannelDeliver<span class="token punctuation">(</span>active<span class="token operator">=</span>chan_active<span class="token punctuation">,</span> passive<span class="token operator">=</span>chan_passive<span class="token punctuation">,</span> channel_deliver_active<span class="token operator">=</span>channel_deliver_active_channel<span class="token punctuation">,</span> channel_deliver_passive<span class="token operator">=</span>channel_deliver_passive_channel<span class="token punctuation">,</span> publish<span class="token operator">=</span>publish_channel<span class="token punctuation">)</span>
self<span class="token punctuation">.</span>targets<span class="token punctuation">[</span>name<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">(</span>_delivery_channel_wrapper<span class="token punctuation">,</span> <span class="token punctuation">(</span>target<span class="token punctuation">,</span> channel_deliver<span class="token punctuation">,</span> shared_memory<span class="token punctuation">,</span> <span class="token operator">*</span>args<span class="token punctuation">)</span><span class="token punctuation">,</span> kwargs<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 class="line-number"></div></div></div></details><h4 id="def-join-all-self" tabindex="-1"><a class="header-anchor" href="#def-join-all-self"><span><em><strong>def</strong></em> <code>join_all(self)</code></span></a></h4><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/core/manager.py#L164" target="_blank">View on 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">join_all</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span>name<span class="token punctuation">,</span> process<span class="token punctuation">)</span> <span class="token keyword">in</span> self<span class="token punctuation">.</span>targets<span class="token punctuation">:</span>
process<span class="token punctuation">.</span>join<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></div></details><h4 id="def-terminate-self-name-str" tabindex="-1"><a class="header-anchor" href="#def-terminate-self-name-str"><span><em><strong>def</strong></em> <code>terminate(self, name: str)</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>name:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/core/manager.py#L168" target="_blank">View on 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">terminate</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
终止进程并从进程字典中删除
Args:
name:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> name <span class="token keyword">not</span> <span class="token keyword">in</span> self<span class="token punctuation">.</span>processes<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Process </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> not found.&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">return</span>
process <span class="token operator">=</span> self<span class="token punctuation">.</span>processes<span class="token punctuation">[</span>name<span class="token punctuation">]</span>
process<span class="token punctuation">.</span>terminate<span class="token punctuation">(</span><span class="token punctuation">)</span>
process<span class="token punctuation">.</span>join<span class="token punctuation">(</span>TIMEOUT<span class="token punctuation">)</span>
<span class="token keyword">if</span> process<span class="token punctuation">.</span>is_alive<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
process<span class="token punctuation">.</span>kill<span class="token punctuation">(</span><span class="token punctuation">)</span>
logger<span class="token punctuation">.</span>success<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Process </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> terminated.&#39;</span></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 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-terminate-all-self" tabindex="-1"><a class="header-anchor" href="#def-terminate-all-self"><span><em><strong>def</strong></em> <code>terminate_all(self)</code></span></a></h4><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/core/manager.py#L187" target="_blank">View on 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">terminate_all</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">for</span> name <span class="token keyword">in</span> self<span class="token punctuation">.</span>targets<span class="token punctuation">:</span>
self<span class="token punctuation">.</span>terminate<span class="token punctuation">(</span>name<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></div></details><h4 id="def-is-process-alive-self-name-str-bool" tabindex="-1"><a class="header-anchor" href="#def-is-process-alive-self-name-str-bool"><span><em><strong>def</strong></em> <code>is_process_alive(self, name: str) -&gt; bool</code></span></a></h4><p><strong>Description</strong>: </p><p><strong>Arguments</strong>:</p><blockquote><ul><li>name:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/core/manager.py#L191" target="_blank">View on 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">is_process_alive</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">bool</span><span class="token punctuation">:</span>
<span class="token triple-quoted-string string">&quot;&quot;&quot;
检查进程是否存活
Args:
name:
Returns:
&quot;&quot;&quot;</span>
<span class="token keyword">if</span> name <span class="token keyword">not</span> <span class="token keyword">in</span> self<span class="token punctuation">.</span>targets<span class="token punctuation">:</span>
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&#39;Process </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> not found.&#39;</span></span><span class="token punctuation">)</span>
<span class="token keyword">return</span> self<span class="token punctuation">.</span>processes<span class="token punctuation">[</span>name<span class="token punctuation">]</span><span class="token punctuation">.</span>is_alive<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>`,36),o=[p];function i(c,l){return s(),a("div",null,o)}const r=n(e,[["render",i],["__file","manager.html.vue"]]),k=JSON.parse('{"path":"/en/dev/api/core/manager.html","title":"liteyuki.core.manager","lang":"en-US","frontmatter":{"title":"liteyuki.core.manager","lastUpdated":false,"description":"liteyuki.core.manager Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/27 11:12 @Author : snowykami @Email : snowykami@outlook.com @File...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/core/manager.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/core/manager.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.core.manager"}],["meta",{"property":"og:description","content":"liteyuki.core.manager Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/27 11:12 @Author : snowykami @Email : snowykami@outlook.com @File..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["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.core.manager\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class ChannelDeliver","slug":"class-channeldeliver","link":"#class-channeldeliver","children":[]},{"level":3,"title":"class ProcessManager","slug":"class-processmanager","link":"#class-processmanager","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":2.71,"words":812},"filePathRelative":"en/dev/api/core/manager.md","localizedDate":"August 21, 2024","autoDesc":true}');export{r as comp,k as data};

View File

@ -0,0 +1 @@
import{_ as t,o as a,c as i,b as e,d as o}from"./app-BvUYPzLF.js";const n={},r=e("h1",{id:"liteyuki-plugin-manager",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#liteyuki-plugin-manager"},[e("span",null,"liteyuki.plugin.manager")])],-1),l=e("p",null,[e("strong",null,"说明"),o(": Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved")],-1),m=e("p",null,"@Time : 2024/7/23 下午11:59 @Author : snowykami @Email : snowykami@outlook.com @File : manager.py @Software: PyCharm",-1),p=[r,l,m];function s(u,c){return a(),i("div",null,p)}const g=t(n,[["render",s],["__file","manager.html.vue"]]),h=JSON.parse('{"path":"/dev/api/plugin/manager.html","title":"liteyuki.plugin.manager","lang":"zh-CN","frontmatter":{"title":"liteyuki.plugin.manager","lastUpdated":false,"description":"liteyuki.plugin.manager 说明: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 下午11:59 @Author : snowykami @Email : snowykami@outlook.com @File : mana...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/plugin/manager.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/plugin/manager.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki.plugin.manager"}],["meta",{"property":"og:description","content":"liteyuki.plugin.manager 说明: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 下午11:59 @Author : snowykami @Email : snowykami@outlook.com @File : mana..."}],["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.plugin.manager\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":0.1,"words":29},"filePathRelative":"dev/api/plugin/manager.md","localizedDate":"2024年8月19日","autoDesc":true}');export{g as comp,h as data};

Some files were not shown because too many files have changed in this diff Show More