-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
502f8c9
commit e021f4d
Showing
12 changed files
with
294 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[flake8] | ||
max-line-length = 110 | ||
extend-ignore = | ||
# See https://github.com/PyCQA/pycodestyle/issues/373 | ||
E203, | ||
|
||
exclude = .git, | ||
__pypackages__ |
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,19 @@ | ||
{ | ||
// 使用 IntelliSense 了解相关属性。 | ||
// 悬停以查看现有属性的描述。 | ||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python: 当前文件", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "${file}", | ||
"console": "integratedTerminal", | ||
"justMyCode": false, | ||
"env": { | ||
"PYTHONPATH": "__pypackages__/3.9/lib" | ||
} | ||
} | ||
] | ||
} |
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,13 @@ | ||
{ | ||
"python.analysis.extraPaths": [ | ||
"__pypackages__/3.9/lib" | ||
], | ||
"python.autoComplete.extraPaths": [ | ||
"__pypackages__/3.9/lib" | ||
], | ||
"cSpell.words": [ | ||
"behaviour", | ||
"behaviours" | ||
], | ||
"restructuredtext.languageServer.disabled": true | ||
} |
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 @@ | ||
__version__ = "1.0.0-pre1" |
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,21 @@ | ||
import toml | ||
from pydantic import BaseModel | ||
|
||
from .path import config | ||
|
||
|
||
class XConfig(BaseModel): | ||
__scope__: str | ||
"""toml 位置""" | ||
|
||
__dest__: str | ||
"""配置文件名""" | ||
|
||
def __init__(self): | ||
path = config.joinpath(f"{self.__dest__}.toml") | ||
path.touch(exist_ok=True) | ||
value = toml.loads(path.read_text()) | ||
for key in self.__scope__.split("."): | ||
if key: | ||
value = value[key] | ||
super().__init__(**value) |
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,11 @@ | ||
from pathlib import Path | ||
|
||
root: Path = Path(__file__).parent.parent | ||
|
||
asset: Path = Path(root, "asset") | ||
|
||
asset.mkdir(parents=True, exist_ok=True) | ||
|
||
config: Path = Path(root, "config") | ||
|
||
config.mkdir(parents=True, exist_ok=True) |
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,44 @@ | ||
from graia.ariadne.app import Ariadne | ||
from graia.ariadne.console import Console | ||
from graia.ariadne.console.saya import ConsoleBehaviour | ||
from graia.ariadne.message.commander import Commander | ||
from graia.ariadne.message.commander.saya import CommanderBehaviour | ||
from graia.ariadne.model import MiraiSession | ||
from graia.saya import Saya | ||
from graia.saya.builtins.broadcast import BroadcastBehaviour | ||
from graia.scheduler import GraiaScheduler | ||
from graia.scheduler.saya.behaviour import GraiaSchedulerBehaviour | ||
from prompt_toolkit.styles.style import Style | ||
from pydantic.networks import AnyHttpUrl | ||
|
||
import module | ||
from library import __version__ as lib_version | ||
from library.config import XConfig | ||
|
||
|
||
class SessionConfig(XConfig): | ||
__scope__: str = "session" | ||
__dest__: str = "global" | ||
host: AnyHttpUrl | ||
account: int | ||
verify_key: str | ||
|
||
|
||
if __name__ == """__main__""": | ||
ariadne = Ariadne(MiraiSession(**SessionConfig().dict())) | ||
saya = ariadne.create(Saya) | ||
con = ariadne.create(Console) | ||
con.l_prompt = f"Xenon {lib_version} > " | ||
con.style = Style([("", "blue")]) | ||
ariadne.create(GraiaScheduler) | ||
ariadne.create(Commander) | ||
saya.install_behaviours( | ||
ariadne.create(BroadcastBehaviour), | ||
ariadne.create(GraiaSchedulerBehaviour), | ||
ariadne.create(ConsoleBehaviour), | ||
ariadne.create(CommanderBehaviour), | ||
) | ||
with saya.module_context(): | ||
for mod in module.__all__: | ||
saya.require(f"module.{mod}") | ||
ariadne.launch_blocking() |
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,7 @@ | ||
import os | ||
|
||
__all__ = [ | ||
s.removesuffix(".py") | ||
for s in os.listdir(os.path.dirname(__file__)) | ||
if s.endswith(".py") and not s.startswith("_") | ||
] |
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,39 @@ | ||
import json | ||
|
||
import aiohttp | ||
from graia.ariadne.app import Ariadne | ||
from graia.ariadne.event.message import MessageEvent | ||
from graia.ariadne.message.chain import MessageChain | ||
from graia.ariadne.message.commander import Arg | ||
from graia.ariadne.message.commander.saya import CommandSchema | ||
from graia.ariadne.message.element import Image | ||
from graia.saya.channel import Channel | ||
|
||
UUID_ADDRESS_STRING = "https://api.mojang.com/users/profiles/minecraft/{name}" | ||
|
||
|
||
RENDER_ADDR = { | ||
"original": "https://crafatar.com/skins/{uuid}", | ||
"body": "https://crafatar.com/renders/body/{uuid}?overlay", | ||
"head": "https://crafatar.com/renders/head/{uuid}?overlay", | ||
"avatar": "https://crafatar.com/avatars/{uuid}?overlay", | ||
} | ||
|
||
channel = Channel.current() | ||
|
||
|
||
@channel.use( | ||
CommandSchema( | ||
"[skin|皮肤] {name}", | ||
{"option": Arg("[--选项|--option|-O] {option}", str, "")}, | ||
) | ||
) | ||
async def get_skin(name: str, option: str, event: MessageEvent, ariadne: Ariadne): | ||
try: | ||
async with aiohttp.ClientSession() as client: | ||
uuid_resp = await client.get(UUID_ADDRESS_STRING.format(name=name)) | ||
uuid = json.loads(await uuid_resp.text())["id"] | ||
url = RENDER_ADDR.get(option, RENDER_ADDR["body"]).format(uuid=uuid) | ||
await ariadne.sendMessage(event, MessageChain.create([Image(url=url)]), quote=True) | ||
except Exception as e: | ||
await ariadne.sendMessage(event, MessageChain([f"无法获取皮肤: {e!r}"])) |
Oops, something went wrong.