Skip to content

Commit

Permalink
使用yarl.URL替代pathlib
Browse files Browse the repository at this point in the history
  • Loading branch information
eya46 committed Jan 28, 2024
1 parent 58e461d commit 69e16f3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
61 changes: 42 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<div align="center">

# NoneBot Plugin eNatFrp
SakuraFrp管理插件
# 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.0.1+-blueviolet)
![NoneBot](https://img.shields.io/badge/nonebot-2.1.0+-red.svg)
</div>

## 安装方式
Expand Down Expand Up @@ -38,28 +38,51 @@ SakuraFrp管理插件
- 我的信息│用户信息
- 公告 `<index: int = 0>`
- 授权 `<id: int> <ip: str>`
-计算机列表
- 计算机列表

## 配置项

### 非必要配置项

- `natfrp_api`: natfrp api地址
- `natfrp_token`: natfrp api token
- `natfrp_at`: 是否at
- `natfrp_reply`: 是否回复
- `natfrp_use_start`: 是否使用nb配置的command_start
- `natfrp_use_sep`: 是否使用nb配置的command_sep

- `natfrp_cmd_help`: `frp帮助`
- `natfrp_cmd_powerOn`: `开机`
- `natfrp_cmd_tunnels`: `隧道状态`
- `natfrp_cmd_trafficHistory`: `流量` `流量历史`
- `natfrp_cmd_trafficPlans`: `流量包` `流量套餐`
- `natfrp_cmd_userInfo`: `我的信息` `用户信息`
- `natfrp_cmd_announcement`: `公告`
- `natfrp_cmd_auth`: `授权`
- `natfrp_cmd_showPCs`: `计算机列表`
```dotenv
# str
# natfrp api地址
natfrp_api=
# natfrp api token
natfrp_token=
# bool
# 是否at
natfrp_at=
# 是否回复
natfrp_reply=
# 是否使用nb配置的command_start
natfrp_use_start=
# 是否使用nb配置的command_sep
# 以下是命令文本 List[str]
natfrp_use_sep=
# frp帮助
natfrp_cmd_help=
# 开机
natfrp_cmd_powerOn=
# 隧道状态
natfrp_cmd_tunnels=
# 流量 流量历史
natfrp_cmd_trafficHistory=
# 流量包 流量套餐
natfrp_cmd_trafficPlans=
# 我的信息 用户信息
natfrp_cmd_userInfo=
# 公告
natfrp_cmd_announcement=
# 授权
natfrp_cmd_auth=
# 计算机列表
natfrp_cmd_showPCs=
```



## 依赖项

Expand Down
12 changes: 4 additions & 8 deletions nonebot_plugin_enatfrp/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import PurePosixPath
from typing import TYPE_CHECKING, Protocol, Any, Literal, Dict
from urllib.parse import urlparse, urlunparse

from yarl import URL

from .tools import request

Expand All @@ -12,18 +12,14 @@ async def __call__(self, **data: Any) -> Any:

class API:
def __init__(self, api: str, token: str):
self.api = api
self.api = URL(api)
self.headers = {"Authorization": f"Bearer {token}"}

def get_api(self, path: str) -> str:
u = urlparse(self.api)
return urlunparse(u._replace(path=(PurePosixPath(u.path) / path).as_posix())) # type:ignore

async def call_api(
self,
path: str, method: Literal["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"], **data: Any
) -> Any:
return await request(method, self.get_api(path), self.headers, **data)
return await request(method, str(self.api / path), self.headers, **data)

async def system_bulletin(self) -> list:
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-plugin-enatfrp"
version = "0.1.5"
version = "0.1.6"
description = "SakuraFrp管理插件"
authors = ["eya46 <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 69e16f3

Please sign in to comment.