-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from noneplugin/feat/orm
- Loading branch information
Showing
8 changed files
with
769 additions
and
676 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
*__pycache__/ | ||
dist/ | ||
.vscode/ | ||
.env | ||
data.db |
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 |
---|---|---|
|
@@ -18,33 +18,21 @@ | |
EventToMe, | ||
ShellCommandArgv, | ||
) | ||
from nonebot.plugin import PluginMetadata | ||
from nonebot.plugin import PluginMetadata, inherit_supported_adapters | ||
from nonebot.rule import ArgumentParser, Rule | ||
from nonebot.typing import T_State | ||
|
||
require("nonebot_plugin_saa") | ||
require("nonebot_plugin_session") | ||
require("nonebot_plugin_userinfo") | ||
require("nonebot_plugin_datastore") | ||
require("nonebot_plugin_orm") | ||
require("nonebot_plugin_htmlrender") | ||
|
||
from nonebot_plugin_saa import Image, MessageFactory | ||
from nonebot_plugin_saa import __plugin_meta__ as saa_plugin_meta | ||
from nonebot_plugin_session import SessionIdType, SessionLevel | ||
from nonebot_plugin_session import __plugin_meta__ as session_plugin_meta | ||
from nonebot_plugin_session import extract_session | ||
from nonebot_plugin_userinfo import __plugin_meta__ as userinfo_plugin_meta | ||
from nonebot_plugin_session import SessionIdType, SessionLevel, extract_session | ||
from nonebot_plugin_userinfo import get_user_info | ||
|
||
assert saa_plugin_meta.supported_adapters | ||
assert session_plugin_meta.supported_adapters | ||
assert userinfo_plugin_meta.supported_adapters | ||
supported_adapters = ( | ||
saa_plugin_meta.supported_adapters | ||
& session_plugin_meta.supported_adapters | ||
& userinfo_plugin_meta.supported_adapters | ||
) | ||
|
||
from . import migrations | ||
from .config import Config | ||
from .game import AiPlayer, Game, Player | ||
|
||
|
@@ -61,12 +49,15 @@ | |
type="application", | ||
homepage="https://github.com/noneplugin/nonebot-plugin-chess", | ||
config=Config, | ||
supported_adapters=supported_adapters, | ||
supported_adapters=inherit_supported_adapters( | ||
"nonebot_plugin_saa", "nonebot_plugin_session", "nonebot_plugin_userinfo" | ||
), | ||
extra={ | ||
"unique_name": "chess", | ||
"example": "@小Q 国际象棋人机lv5\ne2e4\n结束下棋", | ||
"author": "meetwq <[email protected]>", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"orm_version_location": migrations, | ||
}, | ||
) | ||
|
||
|
@@ -217,17 +208,12 @@ def set_timeout(matcher: Matcher, cid: str, timeout: float = 600): | |
timers[cid] = timer | ||
|
||
|
||
async def handle_chess( | ||
bot: Bot, | ||
matcher: Matcher, | ||
event: Event, | ||
argv: List[str], | ||
): | ||
async def handle_chess(bot: Bot, matcher: Matcher, event: Event, argv: List[str]): | ||
async def new_player(event: Event) -> Player: | ||
user_id = event.get_user_id() | ||
user_name = "" | ||
if user_info := await get_user_info(bot, event, user_id=user_id): | ||
user_name = user_info.user_name | ||
user_name = user_info.user_displayname or user_info.user_name | ||
return Player(user_id, user_name) | ||
|
||
async def send(msgs: Union[str, Iterable[Union[str, bytes]]] = "") -> NoReturn: | ||
|
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,53 @@ | ||
"""init_db | ||
修订 ID: 32c01e50814d | ||
父修订: | ||
创建时间: 2023-10-19 15:33:59.636036 | ||
""" | ||
from __future__ import annotations | ||
|
||
from collections.abc import Sequence | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
revision: str = "32c01e50814d" | ||
down_revision: str | Sequence[str] | None = None | ||
branch_labels: str | Sequence[str] | None = "nonebot_plugin_chess" | ||
depends_on: str | Sequence[str] | None = None | ||
|
||
|
||
def upgrade(name: str = "") -> None: | ||
if name: | ||
return | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"nonebot_plugin_chess_gamerecord", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("game_id", sa.String(length=128), nullable=False), | ||
sa.Column("session_id", sa.String(length=128), nullable=False), | ||
sa.Column("start_time", sa.DateTime(), nullable=False), | ||
sa.Column("update_time", sa.DateTime(), nullable=False), | ||
sa.Column("player_white_id", sa.String(length=64), nullable=False), | ||
sa.Column("player_white_name", sa.Text(), nullable=False), | ||
sa.Column("player_white_is_ai", sa.Boolean(), nullable=False), | ||
sa.Column("player_white_level", sa.Integer(), nullable=False), | ||
sa.Column("player_black_id", sa.String(length=64), nullable=False), | ||
sa.Column("player_black_name", sa.Text(), nullable=False), | ||
sa.Column("player_black_is_ai", sa.Boolean(), nullable=False), | ||
sa.Column("player_black_level", sa.Integer(), nullable=False), | ||
sa.Column("start_fen", sa.Text(), nullable=False), | ||
sa.Column("moves", sa.Text(), nullable=False), | ||
sa.Column("is_game_over", sa.Boolean(), nullable=False), | ||
sa.PrimaryKeyConstraint("id", name=op.f("pk_nonebot_plugin_chess_gamerecord")), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(name: str = "") -> None: | ||
if name: | ||
return | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("nonebot_plugin_chess_gamerecord") | ||
# ### end Alembic commands ### |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.