Skip to content

Commit

Permalink
✨ dynamic timer task
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Dec 14, 2024
1 parent 0998855 commit 0be566c
Show file tree
Hide file tree
Showing 18 changed files with 481 additions and 482 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ app.run()
编写插件:

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

metadata(
name="Hello, World!",
Expand All @@ -95,7 +95,7 @@ metadata(
)
# or __plugin_metadata__ = PluginMetadata(...)

@MessageCreatedEvent.dispatch()
@plugin.dispatch(MessageCreatedEvent)
async def _(session: Session):
await session.send("Hello, World!")
```
Expand Down
1 change: 1 addition & 0 deletions arclet/entari/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from .message import MessageChain as MessageChain
from .plugin import Plugin as Plugin
from .plugin import PluginMetadata as PluginMetadata
from .plugin import declare_static as declare_static
from .plugin import dispose as dispose_plugin # noqa: F401
from .plugin import keeping as keeping
from .plugin import load_plugin as load_plugin
Expand Down
6 changes: 4 additions & 2 deletions arclet/entari/builtins/auto_reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
from launart.status import Phase
from watchfiles import PythonFilter, awatch

from arclet.entari import Plugin, dispose_plugin, load_plugin, metadata
from arclet.entari import Plugin, declare_static, dispose_plugin, load_plugin, metadata
from arclet.entari.config import EntariConfig
from arclet.entari.event.config import ConfigReload
from arclet.entari.logger import log
from arclet.entari.plugin import find_plugin, find_plugin_by_file

declare_static()


class Config:
watch_dirs: list[str] = ["."]
Expand Down Expand Up @@ -66,7 +68,7 @@ async def watch(self):
async for event in awatch(*self.dirs, watch_filter=PythonFilter()):
for change in event:
if plugin := find_plugin_by_file(change[1]):
if plugin.id == "arclet.entari.builtins.auto_reload" or plugin.is_static:
if plugin.is_static:
logger("INFO", f"Plugin <y>{plugin.id!r}</y> is static, ignored.")
continue
logger("INFO", f"Detected change in <blue>{plugin.id!r}</blue>, reloading...")
Expand Down
2 changes: 1 addition & 1 deletion arclet/entari/command/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from tarina.string import split
from tarina.trie import CharTrie

from ..event.base import MessageCreatedEvent
from ..event.command import CommandExecute
from ..event.config import ConfigReload
from ..event.protocol import MessageCreatedEvent
from ..message import MessageChain
from ..plugin import RootlessPlugin
from ..session import Session
Expand Down
4 changes: 2 additions & 2 deletions arclet/entari/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from tarina.generic import get_origin

from .config import EntariConfig
from .event.base import MessageCreatedEvent, event_parse
from .event.config import ConfigReload
from .event.lifespan import AccountUpdate
from .event.protocol import MessageCreatedEvent, event_parse
from .event.send import SendResponse
from .logger import log
from .plugin import load_plugin, plugin_config, requires
Expand Down Expand Up @@ -130,7 +130,7 @@ def __init__(
log.core.opt(colors=True).debug(f"Log level set to <y><c>{log_level}</c></y>")
requires(*EntariConfig.instance.prelude_plugin)
for plug in EntariConfig.instance.prelude_plugin:
load_plugin(plug, static=True)
load_plugin(plug, prelude=True)
requires(*EntariConfig.instance.plugin)
for plug in EntariConfig.instance.plugin:
load_plugin(plug)
Expand Down
4 changes: 2 additions & 2 deletions arclet/entari/event/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .protocol import MessageCreatedEvent as MessageCreatedEvent
from .protocol import MessageEvent as MessageEvent
from .base import MessageCreatedEvent as MessageCreatedEvent
from .base import MessageEvent as MessageEvent
Loading

0 comments on commit 0be566c

Please sign in to comment.