Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自动识别 System 字段拉平 #15

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions actions/v12/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ async def get_file_fragmented(

match stage:
case "prepare":
type_checker.check_aruments(file_id)
type_checker.check_arguments(file_id)
return return_object.get(
0,
name=file_name,
total_size=len(content),
sha256=hashlib.sha256(content).hexdigest()
)
case "transfer":
type_checker.check_aruments(file_id, offset, size)
type_checker.check_arguments(file_id, offset, size)
return return_object.get(
0,
data=base64.b64encode(content[offset:offset + size]).decode("utf-8") # type: ignore
Expand All @@ -159,7 +159,7 @@ async def upload_file_fragmented(
match stage:

case "prepare":
type_checker.check_aruments(name, total_size)
type_checker.check_arguments(name, total_size)
uploading_files[file_id := str(uuid.uuid1())] = {
"name": name,
"content": [0] * total_size
Expand All @@ -169,15 +169,15 @@ async def upload_file_fragmented(
)

case "transfer":
type_checker.check_aruments(file_id, offset, data)
type_checker.check_arguments(file_id, offset, data)
byte_offset = 0
for byte in list(base64.b64decode(data)):
uploading_files[file_id]["content"][offset + byte_offset] = byte
byte_offset += 1
return return_object.get()

case "finish":
type_checker.check_aruments(file_id, offset, sha256)
type_checker.check_arguments(file_id, offset, sha256)
file_name = uploading_files[file_id]['name']
with open(f".cache/files/{file_name}", "wb") as f:
f.write(bytes(uploading_files.pop(file_id)["content"]))
Expand All @@ -202,7 +202,7 @@ async def upload_file(
match type:

case "url":
type_checker.check_aruments(name, url)
type_checker.check_arguments(name, url)
is_successful = await upload_file_from_url(
url,
headers,
Expand All @@ -218,14 +218,14 @@ async def upload_file(
)

case "name":
type_checker.check_aruments(name, path)
type_checker.check_arguments(name, path)
is_successful = upload_file_from_path(name, path)
if not is_successful[0]:
return return_object.get(32001, is_successful[1])
return return_object.get(0, file_id=register_saved_file(name))

case "data":
type_checker.check_aruments(name, data)
type_checker.check_arguments(name, data)
is_successful = upload_file_from_data(name, data)
if not is_successful[0]:
return return_object.get(32001, is_successful[1])
Expand Down Expand Up @@ -262,7 +262,7 @@ async def clean_files() -> None:
file_list.pop(file_id)
continue
if file_id in cached_url_list:
if config["system"].get("cahce_first"):
if config["system"].get("cache_first"):
logger.warning(f"文件 {file_list[file_id]} ({file_id}) 已被缓存,正在删除储存文件")
file_list.pop(file_id)
continue
Expand Down
2 changes: 2 additions & 0 deletions call_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def get_action_function(action: str, protocol_version: int) -> Callable | None:
Returns:
Callable: 动作执行函数
"""
if config["system"].get("action_isolation"):
return action_list[f"v{protocol_version}"].get(action)
if action in action_list.get(f"v{protocol_version}", {}).keys():
return action_list[f"v{protocol_version}"][action]
for actions in action_list.values():
Expand Down
16 changes: 12 additions & 4 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ OneDisc 高级设置(无特殊需要不建议更改)

| 类型 | 必须 | 默认值 |
|:----------:|:----:|:----------------------:|
| 布尔 | 否 | `faise` |
| 布尔 | 否 | `false` |

如启用,将在发送 `CQ:face` 时使用 QQ 表情包静态图

Expand Down Expand Up @@ -185,6 +185,14 @@ OneBot V12 心跳元事件设置

`upload_file` 及相关动作下载出错时的重试次数

### 隔离动作(`action_isolation`)

| 类型 | 必须 | 默认值 |
|:----------:|:----:|:----------:|
| 布尔 | 否 | `false` |

启用后将禁止跨协议访问动作

### 是否忽略自身事件(`ignore_self_events`)

| 类型 | 必须 | 默认值 |
Expand Down Expand Up @@ -220,11 +228,11 @@ OneBot V12 心跳元事件设置

OneBot V11 中,私聊消息事件(`message.private`)的 `sub_type` 字段内容

### 缓存优先(`cahce_first`)
### 缓存优先(`cache_first`)

| 类型 | 必须 | 默认值 |
|:---------:|:----:|:----------------:|
| 布尔 | 否 | `flase` |
| 布尔 | 否 | `false` |

此项为 `true` 时,当同一文件同时存在于缓存 URL 索引和本地储存库(`.cache/files`)时,优先保留缓存(删除本地储存文件)

Expand All @@ -242,7 +250,7 @@ OneBot V11 中,私聊消息事件(`message.private`)的 `sub_type` 字段

| 类型 | 必须 | 默认值 |
|:---------:|:----:|:----------------:|
| 布尔 | 否 | `flase` |
| 布尔 | 否 | `false` |

如为`false`,将在发送消息并解析到不支持的消息段时返回 `10005` 错误

Expand Down
2 changes: 1 addition & 1 deletion utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def read_local_config() -> dict:
# config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.json')
with open("config.json", 'r', encoding='utf-8') as f:
config = json.load(f)
if config.get("flatten_system"):
if not config.get("system"):
config["system"] = config.copy()
return config

Expand Down
2 changes: 1 addition & 1 deletion utils/type_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class BadParam(Exception): pass

def check_aruments(*args) -> None:
def check_arguments(*args) -> None:
if None in args:
raise BadParam("None is not allowed")

Expand Down
Loading