Skip to content

Commit

Permalink
🔖 version 0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Dec 30, 2024
1 parent 23cb1a7 commit 50b6e29
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,27 @@ app.run()
编写插件:

```python
from arclet.entari import Session, MessageCreatedEvent, metadata, listen
from arclet.entari import BasicConfModel, Session, MessageCreatedEvent, plugin

metadata(

class Config(BasicConfModel):
name: str


plugin.metadata(
name="Hello, World!",
author=["Arclet"],
version="0.1.0",
description="A simple plugin that replies 'Hello, World!' to every message."
description="A simple plugin that replies 'Hello, World!' to every message.",
config=Config
)
# or __plugin_metadata__ = PluginMetadata(...)

@listen(MessageCreatedEvent) # or plugin.dispatch(MessageCreatedEvent)
config = plugin.get_config(Config)

@plugin.listen(MessageCreatedEvent) # or plugin.dispatch(MessageCreatedEvent)
async def _(session: Session):
await session.send("Hello, World!")
await session.send(f"Hello, World! {config.name}")
```

加载插件:
Expand All @@ -108,15 +116,14 @@ async def _(session: Session):
from arclet.entari import Entari, WS, load_plugin

app = Entari(WS(port=5140, path="satori"))
load_plugin("example_plugin")
load_plugin("example_plugin", {"name": "Entari"})
load_plugin("::echo")
load_plugin("::auto_reload", {"watch_dirs": ["plugins"]})

app.run()
```



## 配置文件

```yaml
Expand All @@ -130,6 +137,7 @@ basic:
log_level: INFO
prefix: ["/"]
plugins:
$files: ["./plugins"]
$prelude: ["::auto_reload"]
.record_message:
record_send: true
Expand All @@ -153,6 +161,8 @@ plugins:
- `log_level`: 日志等级
- `prefix`: 指令前缀, 可留空
- `plugins`: 插件配置
- `$files`: 额外的插件配置文件搜索目录
- `$prelude`: 预加载插件列表
- `.record_message`: 消息日志并配置
- `record_send`: 是否记录发送消息 (默认为 `true`)
- `.commands`: 指令插件配置 (适用于所有使用了 `command.on/command.command` 的插件)
Expand Down
4 changes: 2 additions & 2 deletions arclet/entari/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from arclet.letoderea import bind as bind
from arclet.letoderea import es as es
from satori import ArgvInteraction as ArgvInteraction
from satori import At as At
from satori import Audio as Audio
Expand Down Expand Up @@ -51,8 +50,10 @@
from .plugin import Plugin as Plugin
from .plugin import PluginMetadata as PluginMetadata
from .plugin import add_service as add_service
from .plugin import collect_disposes as collect_disposes
from .plugin import declare_static as declare_static
from .plugin import keeping as keeping
from .plugin import listen as listen
from .plugin import load_plugin as load_plugin
from .plugin import load_plugins as load_plugins
from .plugin import metadata as metadata
Expand All @@ -65,6 +66,5 @@
WS = WebsocketsInfo
WH = WebhookInfo
filter_ = Filter
listen = es.on

__version__ = "0.10.5"
2 changes: 1 addition & 1 deletion arclet/entari/builtins/help.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from dataclasses import field
import random
from typing import Optional

from arclet.alconna import (
Expand Down
3 changes: 2 additions & 1 deletion arclet/entari/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from dataclasses import dataclass, fields, is_dataclass
from dataclasses import dataclass
from dataclasses import field as field
from dataclasses import fields, is_dataclass
from inspect import Signature
import json
import os
Expand Down
15 changes: 14 additions & 1 deletion arclet/entari/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from os import PathLike
from pathlib import Path
from typing import Any, overload
from typing import Any, Callable, overload

from arclet.letoderea import es
from tarina import init_spec

from ..config import C, EntariConfig, config_model_validate
Expand Down Expand Up @@ -133,6 +134,9 @@ def plugin_config(model_type: type[C] | None = None):
return plugin.config


get_config = plugin_config


def declare_static():
"""声明当前插件为静态插件"""
if not (plugin := _current_plugin.get(None)):
Expand All @@ -148,6 +152,12 @@ def add_service(serv: TS | type[TS]) -> TS:
return plugin.service(serv)


def collect_disposes(*disposes: Callable[[], None]):
if not (plugin := _current_plugin.get(None)):
raise LookupError("no plugin context found")
plugin.collect(*disposes)


def find_plugin(name: str) -> Plugin | None:
if name in plugin_service.plugins:
return plugin_service.plugins[name]
Expand All @@ -168,3 +178,6 @@ def find_plugin_by_file(file: str) -> Plugin | None:
return plugin
path1 = path1.parent
return None


listen = es.on
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "arclet-entari"
version = "0.10.5"
version = "0.11.0"
description = "Simple IM Framework based on satori-python"
authors = [
{name = "RF-Tar-Railt",email = "[email protected]"},
Expand Down

0 comments on commit 50b6e29

Please sign in to comment.