Skip to content

Commit

Permalink
Merge pull request #12 from XiYang6666/correct-spelling
Browse files Browse the repository at this point in the history
✏️ correct spelling
  • Loading branch information
RF-Tar-Railt committed Sep 24, 2023
2 parents 167d97f + 9a4e274 commit 26cf9d0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion nonebot/adapters/red/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, driver: Driver, **kwargs: Any):
if self.red_config.red_auto_detect and not self._bots:
try:
from .auto_detect import get_config # type: ignore

log("INFO", "Auto detect chronocat config...")
self._bots = get_config()
log("SUCCESS", f"Auto detect {len(self._bots)} bots.")
Expand Down Expand Up @@ -116,7 +117,7 @@ async def _forward_ws(self, bot_info: BotInfo) -> None:
)
log(
"ERROR",
"Please consider using other red-procotol server "
"Please consider using other red-protocol server "
"like Chronocat LiteLoaderQQNT Plugin.",
)
log(
Expand Down
15 changes: 11 additions & 4 deletions nonebot/adapters/red/auto_detect.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import yaml
import os
from pathlib import Path
from typing import Literal, List
from typing import List, Literal

import yaml
from pydantic import BaseModel

from .bot import BotInfo

# get `home` path
home = Path(os.path.expanduser("~"))
# get `config` path
config = home / "chronocat.yml"


class Server(BaseModel):
type: Literal["red", "satori"] = "red"
token: str
Expand All @@ -19,7 +22,11 @@ class Server(BaseModel):
def get_config() -> List[BotInfo]:
if not config.exists():
return []
with open(config, "r", encoding="utf-8") as f:
with open(config, encoding="utf-8") as f:
data = yaml.safe_load(f)
servers = [Server.parse_obj(server) for server in data["servers"]]
return [BotInfo(port=server.port, token=server.token) for server in servers if server.type == "red"]
return [
BotInfo(port=server.port, token=server.token)
for server in servers
if server.type == "red"
]
2 changes: 1 addition & 1 deletion nonebot/adapters/red/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class Config(BaseModel, extra=Extra.ignore):
"""bot 配置"""

red_auto_detect: bool = False
"""是否自动检测 chronocat 配置,默认为 False"""
"""是否自动检测 chronocat 配置,默认为 False"""
1 change: 1 addition & 0 deletions nonebot/adapters/red/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def is_private(self) -> bool:
"""是否为私聊消息"""
return self.chatType == ChatType.FRIEND


class PrivateMessageEvent(MessageEvent):
"""好友消息事件"""

Expand Down
2 changes: 1 addition & 1 deletion nonebot/adapters/red/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ async def export(self, bot: "Bot") -> List[dict]:
"replayMsgId": seg.data["msg_id"],
"replayMsgSeq": seg.data["msg_seq"],
"senderUin": seg.data["sender_uin"],
"sebderUinStr": str(seg.data["sender_uin"]),
"senderUinStr": str(seg.data["sender_uin"]),
},
}
)
Expand Down

0 comments on commit 26cf9d0

Please sign in to comment.