Skip to content

Commit

Permalink
更新依赖\format\LICENSE
Browse files Browse the repository at this point in the history
  • Loading branch information
eya46 committed Sep 3, 2024
1 parent b6880ce commit 156857f
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 122 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright (c) 2020 NoneBot Team
Copyright (c) 2024 eya46

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# SakuraFrp管理插件

![License](https://img.shields.io/github/license/eya46/nonebot_plugin_enatfrp)
![Python](https://img.shields.io/badge/python-3.8+-blue.svg)
![NoneBot](https://img.shields.io/badge/nonebot-2.2.0+-red.svg)
![Python](https://img.shields.io/badge/python-3.9+-blue.svg)
![NoneBot](https://img.shields.io/badge/nonebot-2.3.0+-red.svg)
</div>

## 安装方式
Expand Down Expand Up @@ -86,5 +86,8 @@ natfrp_cmd_showPCs=

## 依赖项

- [nonebot2](https://github.com/nonebot/nonebot2)[httpx] ^2.2.0
- [plugin-alconna](https://github.com/nonebot/plugin-alconna) >=0.35.0,<1.0.0
```toml
python = "^3.9"
nonebot2 = { version = ">=2.3.0", extras = ["httpx"] }
nonebot-plugin-alconna = ">=0.52.2"
```
21 changes: 9 additions & 12 deletions generate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from collections import Counter
from functools import cache
from pathlib import PurePosixPath, Path
from typing import Type, Iterable, Tuple, List, Union, Optional, Any, Set
from typing import Union, Optional, Any
from collections.abc import Iterable
from urllib.parse import urlparse, urlunparse

import httpx
Expand Down Expand Up @@ -46,11 +47,11 @@ def get_api() -> OpenAPI:
return api


def list2str(data: List[Any], seq: str = ",") -> str:
def list2str(data: list[Any], seq: str = ",") -> str:
return seq.join(map(str, data))


def type2pyType(type_: Union[DataType, List[DataType]]) -> List[str]:
def type2pyType(type_: Union[DataType, list[DataType]]) -> list[str]:
if isinstance(type_, DataType):
type_ = [type_]
return [
Expand Down Expand Up @@ -83,7 +84,7 @@ def operation2description(operation: Operation) -> str:
)


def yield_api(paths: Paths) -> Iterable[Tuple[str, str, Optional[Operation]]]:
def yield_api(paths: Paths) -> Iterable[tuple[str, str, Optional[Operation]]]:
"""
:return: path,method,Operation
"""
Expand All @@ -101,7 +102,7 @@ def get_path_count(if_print: bool = False) -> Counter:
d[ppp] += 1
if if_print:
for i in d:
print(f"{i} -> {d[i]}")
pass
return d


Expand All @@ -125,7 +126,7 @@ def get_defName(path: str, method: str, strict: bool = False):

def parameter2annotated(
parameter: Optional[Union[Reference, Schema]], url: str = BASE_URL
) -> Optional[Set[Tuple[str, str, Tuple]]]:
) -> Optional[set[tuple[str, str, tuple]]]:
if parameter is None:
return None
if isinstance(parameter, Reference):
Expand Down Expand Up @@ -163,7 +164,7 @@ def get_defParameters(method: str, operation: Operation):

# 获取返回值

def urlContent2py(content: dict) -> Type:
def urlContent2py(content: dict) -> type:
return {
"application/json": str
}[content]
Expand All @@ -173,11 +174,7 @@ def main():
api = get_api()
for path, method, op in yield_api(api.paths):
# print(f"{path}[{method}] -> {get_defName(path, method)}")
print(f"""async def {get_defName(path, method)}(self):
\"\"\"
{operation2description(op)}
method: {method.upper()}
\"\"\"""")
pass


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_enatfrp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require("nonebot_plugin_alconna")

from typing_extensions import Annotated
from typing import Annotated
from typing import Literal

from nonebot_plugin_alconna import Alconna, Match, AlconnaMatch, Args
Expand Down
9 changes: 2 additions & 7 deletions nonebot_plugin_enatfrp/api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
from typing import TYPE_CHECKING, Protocol, Any, Literal, Dict
from typing import Any, Literal

from yarl import URL

from .tools import request

if TYPE_CHECKING:
class _ApiCall(Protocol):
async def __call__(self, **data: Any) -> Any:
...


class API:
def __init__(self, api: Any, token: str):
Expand Down Expand Up @@ -160,7 +155,7 @@ async def tunnel_delete(self, ids: str) -> dict:
"""
return await self.call_api("tunnel/delete", "POST", ids=ids)

async def tunnel_traffic(self, id_: int) -> Dict[str, int]:
async def tunnel_traffic(self, id_: int) -> dict[str, int]:
"""
获取流量使用记录
tag: 隧道管理
Expand Down
20 changes: 10 additions & 10 deletions nonebot_plugin_enatfrp/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, List
from typing import Optional

from nonebot.plugin import get_plugin_config
from pydantic import BaseModel, Field, AnyUrl
Expand All @@ -12,15 +12,15 @@ class Config(BaseModel):
use_start: bool = Field(default=True, alias="natfrp_use_start")
use_sep: bool = Field(default=False, alias="natfrp_use_sep")

cmd_help: List[str] = Field(default=["frp帮助"], alias="natfrp_cmd_help")
cmd_powerOn: List[str] = Field(default=["开机"], alias="natfrp_cmd_powerOn")
cmd_tunnels: List[str] = Field(default=["隧道状态"], alias="natfrp_cmd_tunnels")
cmd_trafficHistory: List[str] = Field(default=["流量", "流量历史"], alias="natfrp_cmd_trafficHistory")
cmd_trafficPlans: List[str] = Field(default=["流量包", "流量套餐"], alias="natfrp_cmd_trafficPlans")
cmd_userInfo: List[str] = Field(default=["我的信息", "用户信息"], alias="natfrp_cmd_userInfo")
cmd_announcement: List[str] = Field(default=["公告"], alias="natfrp_cmd_announcement")
cmd_auth: List[str] = Field(default=["授权"], alias="natfrp_cmd_auth")
cmd_showPCs: List[str] = Field(default=["计算机列表"], alias="natfrp_cmd_showPCs")
cmd_help: list[str] = Field(default=["frp帮助"], alias="natfrp_cmd_help")
cmd_powerOn: list[str] = Field(default=["开机"], alias="natfrp_cmd_powerOn")
cmd_tunnels: list[str] = Field(default=["隧道状态"], alias="natfrp_cmd_tunnels")
cmd_trafficHistory: list[str] = Field(default=["流量", "流量历史"], alias="natfrp_cmd_trafficHistory")
cmd_trafficPlans: list[str] = Field(default=["流量包", "流量套餐"], alias="natfrp_cmd_trafficPlans")
cmd_userInfo: list[str] = Field(default=["我的信息", "用户信息"], alias="natfrp_cmd_userInfo")
cmd_announcement: list[str] = Field(default=["公告"], alias="natfrp_cmd_announcement")
cmd_auth: list[str] = Field(default=["授权"], alias="natfrp_cmd_auth")
cmd_showPCs: list[str] = Field(default=["计算机列表"], alias="natfrp_cmd_showPCs")


config: Config = get_plugin_config(Config)
Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_enatfrp/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from functools import wraps
from html import unescape
from json import loads
from typing import Union, Any, Callable, Optional, List
from typing import Union, Any, Callable, Optional

from arclet.alconna import Alconna
from nonebot import get_driver
Expand Down Expand Up @@ -67,7 +67,7 @@ async def request(method: str, url: str, headers, **data) -> Any:
"all": "all"
}

HELPS: List[str] = []
HELPS: list[str] = []


async def send(msg: Union[Any, UniMessage]) -> Receipt:
Expand Down
Loading

0 comments on commit 156857f

Please sign in to comment.