🎨 add store components

This commit is contained in:
yanyongyu 2021-12-29 21:09:31 +08:00
parent 39fd8b2dcd
commit c7f428795b
15 changed files with 193 additions and 17 deletions

View File

@ -7,7 +7,9 @@ from nonebot.log import logger
def init():
driver = nonebot.get_driver()
try:
_module = importlib.import_module(f"nonebot_plugin_docs.drivers.{driver.type}")
_module = importlib.import_module(
f"nonebot_plugin_docs.drivers.{driver.type.split('+')[0]}"
)
except ImportError:
logger.warning(f"Driver {driver.type} not supported")
return

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-plugin-docs"
version = "2.0.0-alpha.11"
version = "2.0.0-beta.1"
description = "View NoneBot2 Docs Locally"
authors = ["yanyongyu <yyy@nonebot.dev>"]
license = "MIT"

View File

@ -10,6 +10,10 @@ options:
# 深入
:::danger 警告
进阶部分尚未更新完成
:::
## 它如何工作?
如同[概览](../README.md)所言:
@ -36,7 +40,7 @@ options:
2. **调用 `API`**, 在**事件处理**的过程中,`nonebot` 可以通过 `bot` 调用协议端指定的 `API` 来获取更多数据,或者反馈响应给协议端; `nonebot` 也可以通过调用 `API` 向协议端主动请求数据或者主动推送数据。
<!-- 在**指南**模块, 我们已经叙述了[如何配置 nonebot](../guide/tutorial/configuration.md), [如何注册协议适配器](../guide/getting-started.md)[如何加载插件](../guide/loading-a-plugin.md), 在这里便不再赘述。 -->
在**指南**模块, 我们已经叙述了[如何配置 nonebot](../tutorial/configuration.md), [如何注册协议适配器](../tutorial/register-adapter.md)[如何加载插件](../tutorial/plugin/load-plugin.md), 在这里便不再赘述。
下面,我们将对**事件处理** **调用 API**进行说明。
@ -44,7 +48,7 @@ options:
我们可以先看事件处理的流程图:
<!-- ![handle-event](../guide/images/Handle-Event.png) -->
![handle-event](./images/Handle-Event.png)
在流程图里,我们可以看到,`nonebot` 会有三个阶段来处理事件:
@ -94,14 +98,14 @@ options:
关于`hook`的更多信息,可以查阅[这里](./runtime-hook.md)
:::
<!-- 2. **Matcher**与**matcher**,在**指南**中,我们讲述了[如何注册事件响应器](../guide/creating-a-matcher.md),这里的事件响应器或者说 `Matcher` 并不是一个具体的实例 `instance`,而是一个具有特定属性的类 `class`。只有当 `Matcher` **响应事件**时,才会实例化为具体的 `instance`,也就是 `matcher`。`matcher` 可以认为是 `nonebot` 处理 `Event` 的基本单位,运行 `matcher` 是`nonebot`工作的主要内容。 -->
2. **Matcher**与**matcher**,在**指南**中,我们讲述了[如何注册事件响应器](../tutorial/plugin/create-matcher.md),这里的事件响应器或者说 `Matcher` 并不是一个具体的实例 `instance`,而是一个具有特定属性的类 `class`。只有当 `Matcher` **响应事件**时,才会实例化为具体的 `instance`,也就是 `matcher`。`matcher` 可以认为是 `nonebot` 处理 `Event` 的基本单位,运行 `matcher` 是`nonebot`工作的主要内容。
3. **handler**,或者说**事件处理函数**, 它们可以认为是 `nonebot` 处理 `Event` 的最小单位。在不考虑 `hook` 的情况下,**运行 matcher 就是顺序运行 matcher.handlers**,这句话换种表达方式就是,`handler` 只有添加到 `matcher.handlers` 时,才可以参与到 `nonebot` 的工作中来。
::: tip
如何让 `handler` 添加到 `matcher.handlers`
<!-- 一方面,我们可以参照[这里](../guide/creating-a-handler.md)利用装饰器来添加;另一方面,我们在用 `on()` 或者 `on_*()` 注册事件响应器时,可以添加 `handlers=[handler1, handler2, ...]` 这样的关键词参数来添加。 -->
一方面,我们可以参照[这里](../tutorial/plugin/create-handler.md)利用装饰器来添加;另一方面,我们在用 `on()` 或者 `on_*()` 注册事件响应器时,可以添加 `handlers=[handler1, handler2, ...]` 这样的关键词参数来添加。
:::

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

View File

@ -11,7 +11,7 @@ options:
## 应用
<!-- 如同 `Rule` 一样, `Permission` 可以在[注册事件响应器](../guide/creating-a-matcher)时添加 `permission` 参数来加以应用,这样 `Nonebot` 会在事件响应时检测事件主体的权限。下面我们以 `SUPERUSER` 为例,对该机制的应用做一下介绍。 -->
如同 `Rule` 一样, `Permission` 可以在[注册事件响应器](../tutorial/plugin/create-matcher.md)时添加 `permission` 参数来加以应用,这样 `Nonebot` 会在事件响应时检测事件主体的权限。下面我们以 `SUPERUSER` 为例,对该机制的应用做一下介绍。
```python
from nonebot.permission import SUPERUSER

View File

@ -9,7 +9,7 @@ options:
## 前注
<!-- 本章节仅包含插件发布流程指导,插件开发请查阅 **[创建插件](../guide/creating-a-plugin.md)** 章节与 **[Plugin API 文档](../api/plugin.md)** 。 -->
本章节仅包含插件发布流程指导,插件开发请查阅 **[创建插件](../tutorial/plugin/config-plugin.md)** 章节与 **[Plugin API 文档](../api/plugin.md)** 。
## 插件发布流程

View File

View File

@ -30,7 +30,9 @@
"file-loader": "^6.2.0",
"prism-react-renderer": "^1.2.1",
"react": "^17.0.1",
"react-color": "^2.19.3",
"react-dom": "^17.0.1",
"react-paginate": "^8.1.0",
"url-loader": "^4.1.1"
},
"devDependencies": {

View File

@ -1,5 +1,23 @@
import React from "react";
import drivers from "../../static/drivers.json";
import { useFilteredObjs } from "../libs/store";
export default function Driver() {
return <></>;
const {
filter,
setFilter,
filteredObjs: filteredDrivers,
} = useFilteredObjs(drivers);
return (
<>
<div>
<input
value={filter}
onChange={(event) => setFilter(event.target.value)}
/>
</div>
<div>{filteredDrivers.toString()}</div>
</>
);
}

View File

@ -0,0 +1,5 @@
import ReactPaginate from "react-paginate";
export function usePagination() {
return {};
}

View File

@ -0,0 +1,45 @@
import { useState } from "react";
type Tag = {
label: string;
color: string;
};
type Obj = {
module_name?: string;
project_link?: string;
name: string;
desc: string;
author: string;
homepage: string;
tags: Tag[];
is_official: boolean;
};
export function filterObjs(filter: string, objs: Obj[]): Obj[] {
return objs.filter((o) => {
return (
o.module_name?.indexOf(filter) != -1 ||
o.project_link?.indexOf(filter) != -1 ||
o.name.indexOf(filter) != -1 ||
o.desc.indexOf(filter) != -1 ||
o.author.indexOf(filter) != -1
);
});
}
type useFilteredObjsReturn = {
filter: string;
setFilter: (filter: string) => void;
filteredObjs: Obj[];
};
export function useFilteredObjs(objs: Obj[]): useFilteredObjsReturn {
const [filter, setFilter] = useState<string>("");
const filteredObjs = filterObjs(filter, objs);
return {
filter,
setFilter,
filteredObjs,
};
}

View File

@ -10,30 +10,30 @@ import styles from "../css/index.module.css";
export default function Home() {
const firstFeature: Feature = {
title: "Develop",
title: "开发",
tagline: "fast to code",
description: "仅需两步,即可开始编写你的机器人",
} as const;
const secondFeatures = [
{
title: "Plugin",
title: "插件",
tagline: "build bot with plugins",
description: "插件化开发,模块化管理",
},
{
title: "Multi-Platform",
title: "跨平台",
tagline: "write once run everywhere",
description: "支持多种平台,以及多样的事件响应方式",
},
] as const;
const thirdFeatures = [
{
title: "Async",
title: "异步",
tagline: "asynchronous first",
description: "异步优先式开发,提高运行效率",
},
{
title: "DI",
title: "依赖注入",
tagline: "bultin dependency injection system",
description: "简单清晰的依赖注入系统,内置依赖函数减少用户代码",
},

View File

@ -0,0 +1,52 @@
[
{
"module_name": "nonebot.drivers.fastapi",
"project_link": "",
"name": "FastAPI",
"desc": "FastAPI 驱动器",
"author": "yanyongyu",
"homepage": "https://v2.nonebot.dev/docs/tutorial/choose-driver",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.drivers.quart",
"project_link": "quart",
"name": "Quart",
"desc": "Quart 驱动器",
"author": "yanyongyu",
"homepage": "https://v2.nonebot.dev/docs/tutorial/choose-driver",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.drivers.httpx",
"project_link": "",
"name": "HTTPX",
"desc": "HTTPX 驱动器",
"author": "yanyongyu",
"homepage": "https://v2.nonebot.dev/docs/tutorial/choose-driver",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.drivers.websockets",
"project_link": "websockets",
"name": "websockets",
"desc": "websockets 驱动器",
"author": "yanyongyu",
"homepage": "https://v2.nonebot.dev/docs/tutorial/choose-driver",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.drivers.aiohttp",
"project_link": "",
"name": "AIOHTTP",
"desc": "AIOHTTP 驱动器",
"author": "yanyongyu",
"homepage": "https://v2.nonebot.dev/docs/tutorial/choose-driver",
"tags": [],
"is_official": true
}
]

View File

@ -7,6 +7,7 @@
"node",
"@docusaurus/module-type-aliases",
"docusaurus-theme-nonepress"
]
],
"resolveJsonModule": true
}
}

View File

@ -1494,6 +1494,11 @@
dependencies:
"@hapi/hoek" "^9.0.0"
"@icons/material@^0.2.4":
version "0.2.4"
resolved "https://registry.npm.taobao.org/@icons/material/download/@icons/material-0.2.4.tgz#e90c9f71768b3736e76d7dd6783fc6c2afa88bc8"
integrity sha1-6QyfcXaLNzbnbX3WeD/Gwq+oi8g=
"@mdx-js/mdx@1.6.22", "@mdx-js/mdx@^1.6.21":
version "1.6.22"
resolved "https://registry.npmmirror.com/@mdx-js/mdx/download/@mdx-js/mdx-1.6.22.tgz#8a723157bf90e78f17dc0f27995398e6c731f1ba"
@ -4972,6 +4977,11 @@ locate-path@^5.0.0:
dependencies:
p-locate "^4.1.0"
lodash-es@^4.17.15:
version "4.17.21"
resolved "https://registry.nlark.com/lodash-es/download/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha1-Q+YmxG5lkbd1C+srUBFzkMYJ4+4=
lodash.assignin@^4.0.9:
version "4.2.0"
resolved "https://registry.npm.taobao.org/lodash.assignin/download/lodash.assignin-4.2.0.tgz#ba8df5fb841eb0a3e8044232b0e263a8dc6a28a2"
@ -5057,7 +5067,7 @@ lodash.uniq@4.5.0, lodash.uniq@^4.5.0:
resolved "https://registry.npm.taobao.org/lodash.uniq/download/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
lodash@^4.17.14, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21:
lodash@^4.0.1, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.npmmirror.com/lodash/download/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
@ -5112,6 +5122,11 @@ markdown-escapes@^1.0.0:
resolved "https://registry.npmmirror.com/markdown-escapes/download/markdown-escapes-1.0.4.tgz#c95415ef451499d7602b91095f3c8e8975f78535"
integrity sha1-yVQV70UUmddgK5EJXzyOiXX3hTU=
material-colors@^1.2.1:
version "1.2.6"
resolved "https://registry.nlark.com/material-colors/download/material-colors-1.2.6.tgz#6d1958871126992ceecc72f4bcc4d8f010865f46"
integrity sha1-bRlYhxEmmSzuzHL0vMTY8BCGX0Y=
mdast-squeeze-paragraphs@^4.0.0:
version "4.0.0"
resolved "https://registry.nlark.com/mdast-squeeze-paragraphs/download/mdast-squeeze-paragraphs-4.0.0.tgz#7c4c114679c3bee27ef10b58e2e015be79f1ef97"
@ -6099,7 +6114,7 @@ prompts@^2.4.0, prompts@^2.4.1:
kleur "^3.0.3"
sisteransi "^1.0.5"
prop-types@^15.6.2, prop-types@^15.7.2:
prop-types@^15.5.10, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
version "15.8.0"
resolved "https://registry.npmmirror.com/prop-types/download/prop-types-15.8.0.tgz#d237e624c45a9846e469f5f31117f970017ff588"
integrity sha512-fDGekdaHh65eI3lMi5OnErU6a8Ighg2KjcjQxO7m8VHyWjcPyj5kiOgV1LQDOOOgVy3+5FgjXvdSSX7B8/5/4g==
@ -6215,6 +6230,19 @@ rc@^1.2.8:
minimist "^1.2.0"
strip-json-comments "~2.0.1"
react-color@^2.19.3:
version "2.19.3"
resolved "https://registry.npmmirror.com/react-color/download/react-color-2.19.3.tgz#ec6c6b4568312a3c6a18420ab0472e146aa5683d"
integrity sha1-7GxrRWgxKjxqGEIKsEcuFGqlaD0=
dependencies:
"@icons/material" "^0.2.4"
lodash "^4.17.15"
lodash-es "^4.17.15"
material-colors "^1.2.1"
prop-types "^15.5.10"
reactcss "^1.2.0"
tinycolor2 "^1.4.1"
react-cool-onclickoutside@^1.6.2:
version "1.7.0"
resolved "https://registry.npmmirror.com/react-cool-onclickoutside/download/react-cool-onclickoutside-1.7.0.tgz#abc844e14852220fe15f81d7ef44976d15cd9980"
@ -6296,6 +6324,13 @@ react-loadable-ssr-addon-v5-slorber@^1.0.1:
dependencies:
"@babel/runtime" "^7.10.3"
react-paginate@^8.1.0:
version "8.1.0"
resolved "https://registry.npmmirror.com/react-paginate/download/react-paginate-8.1.0.tgz#8c4c6c5b7d90e8a4f33653262204fd32c5dfd207"
integrity sha512-XK8cgcX8Zk4De6F4Iozd91a2xm/U+mdD4SB5k4xcBabqZj86U20N7kMiMzOFk1AEGCj6Kg1374xXK03dz7BTRA==
dependencies:
prop-types "^15.6.1"
react-router-config@^5.1.1:
version "5.1.1"
resolved "https://registry.nlark.com/react-router-config/download/react-router-config-5.1.1.tgz#0f4263d1a80c6b2dc7b9c1902c9526478194a988"
@ -6345,6 +6380,13 @@ react@^17.0.1:
loose-envify "^1.1.0"
object-assign "^4.1.1"
reactcss@^1.2.0:
version "1.2.3"
resolved "https://registry.npm.taobao.org/reactcss/download/reactcss-1.2.3.tgz#c00013875e557b1cf0dfd9a368a1c3dab3b548dd"
integrity sha1-wAATh15Vexzw39mjaKHD2rO1SN0=
dependencies:
lodash "^4.0.1"
read-cache@^1.0.0:
version "1.0.0"
resolved "https://registry.npm.taobao.org/read-cache/download/read-cache-1.0.0.tgz#e664ef31161166c9751cdbe8dbcf86b5fb58f774"
@ -7258,6 +7300,11 @@ tiny-warning@^1.0.0, tiny-warning@^1.0.3:
resolved "https://registry.npm.taobao.org/tiny-warning/download/tiny-warning-1.0.3.tgz#94a30db453df4c643d0fd566060d60a875d84754"
integrity sha1-lKMNtFPfTGQ9D9VmBg1gqHXYR1Q=
tinycolor2@^1.4.1:
version "1.4.2"
resolved "https://registry.npm.taobao.org/tinycolor2/download/tinycolor2-1.4.2.tgz#3f6a4d1071ad07676d7fa472e1fac40a719d8803"
integrity sha1-P2pNEHGtB2dtf6Ry4frECnGdiAM=
tmp@^0.2.1:
version "0.2.1"
resolved "https://registry.nlark.com/tmp/download/tmp-0.2.1.tgz#8457fc3037dcf4719c251367a1af6500ee1ccf14"