forked from noctisynth/dicer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/unvisitor/dicer
- Loading branch information
Showing
5 changed files
with
130 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "dicergirl" | ||
version = "4.0.0-beta.2" | ||
version = "4.0.0-beta.4" | ||
description = "新一代跨平台开源 TRPG 骰娘框架" | ||
authors = [ | ||
{name = "苏向夜", email = "[email protected]"}, | ||
|
@@ -20,8 +20,8 @@ classifiers = [ | |
] | ||
|
||
[project.urls] | ||
Homepage = "https://gitee.com/unvisitor/dicer" | ||
"Bug Tracker" = "https://gitee.com/unvisitor/dicer/issues" | ||
Homepage = "https://github.com/noctisynth/dicer" | ||
"Bug Tracker" = "https://github.com/noctisynth/dicer/issues" | ||
|
||
[build-system] | ||
requires = ["pdm-backend"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from nonebot.adapters import Bot | ||
from pathlib import Path | ||
from diceutils.status import StatusPool | ||
from infini.core import Core | ||
from infini.loader import Loader | ||
from infini.output import Output | ||
|
||
import importlib | ||
import sys | ||
import asyncio | ||
|
||
status = StatusPool.register("dicergirl") | ||
core: Core | ||
|
||
|
||
def get_core(): | ||
return core | ||
|
||
|
||
def hmr(output: Output = None): | ||
global core | ||
importlib.invalidate_caches() | ||
|
||
packages = status.get("bot", "packages") or [] | ||
|
||
with Loader() as loader: | ||
for package in packages: | ||
for name in [ | ||
name for name in sys.modules.keys() if name.startswith(package) | ||
]: | ||
sys.modules[name] = ( | ||
importlib.reload(sys.modules[name]) | ||
if name in sys.modules | ||
else importlib.import_module(name) | ||
) | ||
sys.modules[package] = ( | ||
importlib.reload(sys.modules[package]) | ||
if package in sys.modules | ||
else importlib.import_module(package) | ||
) | ||
|
||
loader.load(package) | ||
core = loader.into_core() | ||
|
||
if output: | ||
output.status = 0 | ||
|
||
|
||
def file_upload(bot: Bot, filepath: Path, output: Output): | ||
asyncio.run( | ||
bot.call_api( | ||
"upload_group_file", | ||
**{ | ||
"group_id": output.variables["group_id"], | ||
"file": str(filepath), | ||
"name": filepath.name, | ||
}, | ||
) | ||
) | ||
output.status = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from concurrent.futures import ThreadPoolExecutor | ||
from typing import Callable | ||
from .utils import hmr, file_upload | ||
|
||
pool = ThreadPoolExecutor(20) | ||
workflows = {"echo.hmr": hmr, "echo.upload": file_upload} | ||
|
||
|
||
def put(func: Callable): | ||
pool.submit(func) |