From bbeea86fd52bd9668794befc98a5854846ede1e0 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Sat, 26 Sep 2020 14:40:08 +0800 Subject: [PATCH] :label: update pyi --- nonebot/adapters/cqhttp.py | 69 ++++++++++++++++++++- nonebot/adapters/cqhttp.pyi | 119 +++++++++++++++++++++++++++++++++++- poetry.lock | 15 ++--- 3 files changed, 192 insertions(+), 11 deletions(-) diff --git a/nonebot/adapters/cqhttp.py b/nonebot/adapters/cqhttp.py index dc7ad38a..8d886919 100644 --- a/nonebot/adapters/cqhttp.py +++ b/nonebot/adapters/cqhttp.py @@ -28,14 +28,29 @@ from nonebot.adapters import BaseBot, BaseEvent, BaseMessage, BaseMessageSegment def log(level: str, message: str): + """ + :说明: + + 用于打印 CQHTTP 日志。 + + :参数: + + * ``level: str``: 日志等级 + * ``message: str``: 日志信息 + """ return logger.opt(colors=True).log(level, "CQHTTP | " + message) def escape(s: str, *, escape_comma: bool = True) -> str: """ - 对字符串进行 CQ 码转义。 + :说明: - ``escape_comma`` 参数控制是否转义逗号(``,``)。 + 对字符串进行 CQ 码转义。 + + :参数: + + * ``s: str``: 需要转义的字符串 + * ``escape_comma: bool``: 是否转义逗号(``,``)。 """ s = s.replace("&", "&") \ .replace("[", "[") \ @@ -46,7 +61,15 @@ def escape(s: str, *, escape_comma: bool = True) -> str: def unescape(s: str) -> str: - """对字符串进行 CQ 码去转义。""" + """ + :说明: + + 对字符串进行 CQ 码去转义。 + + :参数: + + * ``s: str``: 需要转义的字符串 + """ return s.replace(",", ",") \ .replace("[", "[") \ .replace("]", "]") \ @@ -54,10 +77,21 @@ def unescape(s: str) -> str: def _b2s(b: Optional[bool]) -> Optional[str]: + """转换布尔值为字符串。""" return b if b is None else str(b).lower() async def _check_reply(bot: "Bot", event: "Event"): + """ + :说明: + + 检查消息中存在的回复,去除并赋值 ``event.reply``, ``event.to_me`` + + :参数: + + * ``bot: Bot``: Bot 对象 + * ``event: Event``: Event 对象 + """ if event.type != "message": return @@ -74,6 +108,16 @@ async def _check_reply(bot: "Bot", event: "Event"): def _check_at_me(bot: "Bot", event: "Event"): + """ + :说明: + + 检查消息开头或结尾是否存在 @机器人,去除并赋值 ``event.to_me`` + + :参数: + + * ``bot: Bot``: Bot 对象 + * ``event: Event``: Event 对象 + """ if event.type != "message": return @@ -119,6 +163,16 @@ def _check_at_me(bot: "Bot", event: "Event"): def _check_nickname(bot: "Bot", event: "Event"): + """ + :说明: + + 检查消息开头是否存在,去除并赋值 ``event.to_me`` + + :参数: + + * ``bot: Bot``: Bot 对象 + * ``event: Event``: Event 对象 + """ if event.type != "message": return @@ -146,6 +200,15 @@ def _check_nickname(bot: "Bot", event: "Event"): def _handle_api_result(result: Optional[Dict[str, Any]]) -> Any: + """ + :说明: + + 处理 API 请求返回值。 + + :参数: + + * ``result: Optional[Dict[str, Any]]``: API 返回数据 + """ if isinstance(result, dict): if result.get("status") == "failed": raise ActionFailed(retcode=result.get("retcode")) diff --git a/nonebot/adapters/cqhttp.pyi b/nonebot/adapters/cqhttp.pyi index d6ddd6d9..bb64d07b 100644 --- a/nonebot/adapters/cqhttp.pyi +++ b/nonebot/adapters/cqhttp.pyi @@ -1,5 +1,110 @@ from nonebot.adapters import BaseBot -from nonebot.typing import Any, Dict, List, Union, Message, Optional +from nonebot.typing import Any, Dict, List, Union, Optional + + +def log(level: str, message: str): + """ + :说明: + + 用于打印 CQHTTP 日志。 + + :参数: + + * ``level: str``: 日志等级 + * ``message: str``: 日志信息 + """ + ... + + +def escape(s: str, *, escape_comma: bool = True) -> str: + """ + :说明: + + 对字符串进行 CQ 码转义。 + + :参数: + + * ``s: str``: 需要转义的字符串 + * ``escape_comma: bool``: 是否转义逗号(``,``)。 + """ + ... + + +def unescape(s: str) -> str: + """ + :说明: + + 对字符串进行 CQ 码去转义。 + + :参数: + + * ``s: str``: 需要转义的字符串 + """ + ... + + +def _b2s(b: Optional[bool]) -> Optional[str]: + """转换布尔值为字符串。""" + ... + + +async def _check_reply(bot: "Bot", event: "Event"): + """ + :说明: + + 检查消息中存在的回复,去除并赋值 ``event.reply``, ``event.to_me`` + + :参数: + + * ``bot: Bot``: Bot 对象 + * ``event: Event``: Event 对象 + """ + ... + + +def _check_at_me(bot: "Bot", event: "Event"): + """ + :说明: + + 检查消息开头或结尾是否存在 @机器人,去除并赋值 ``event.to_me`` + + :参数: + + * ``bot: Bot``: Bot 对象 + * ``event: Event``: Event 对象 + """ + ... + + +def _check_nickname(bot: "Bot", event: "Event"): + """ + :说明: + + 检查消息开头是否存在,去除并赋值 ``event.to_me`` + + :参数: + + * ``bot: Bot``: Bot 对象 + * ``event: Event``: Event 对象 + """ + ... + + +def _handle_api_result(result: Optional[Dict[str, Any]]) -> Any: + """ + :说明: + + 处理 API 请求返回值。 + + :参数: + + * ``result: Optional[Dict[str, Any]]``: API 返回数据 + """ + ... + + +class ResultStore: + ... class Bot(BaseBot): @@ -674,3 +779,15 @@ class Bot(BaseBot): * ``self_id``: 机器人 QQ 号 """ ... + + +class Event: + ... + + +class MessageSegment: + ... + + +class Message: + ... diff --git a/poetry.lock b/poetry.lock index 10ae5b4c..4ea7d8cd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -197,7 +197,7 @@ description = "Chromium HSTS Preload list as a Python package and updated daily" name = "hstspreload" optional = false python-versions = ">=3.6" -version = "2020.9.15" +version = "2020.9.23" [package.source] reference = "aliyun" @@ -338,7 +338,7 @@ description = "Python logging made (stupidly) simple" name = "loguru" optional = false python-versions = ">=3.5" -version = "0.5.2" +version = "0.5.3" [package.dependencies] colorama = ">=0.3.4" @@ -884,11 +884,12 @@ type = "legacy" url = "https://mirrors.aliyun.com/pypi/simple" [extras] +cli = [] full = [] scheduler = ["apscheduler"] [metadata] -content-hash = "3a0f821e8ecef5548fa95e88cee11ff12910d08bed1633d8d03280f65d0bc1bf" +content-hash = "9e0ffcd353df841f9ae33d5bd302366e8bb7b0b1ba78b24904f2947bd793b768" lock-version = "1.0" python-versions = "^3.7" @@ -942,8 +943,8 @@ hpack = [ {file = "hpack-3.0.0.tar.gz", hash = "sha256:8eec9c1f4bfae3408a3f30500261f7e6a65912dc138526ea054f9ad98892e9d2"}, ] hstspreload = [ - {file = "hstspreload-2020.9.15-py3-none-any.whl", hash = "sha256:c09f02dd4b7e3953a8353836aea964b868b22905bdb6d8932ca4b273df0f820f"}, - {file = "hstspreload-2020.9.15.tar.gz", hash = "sha256:059fc2ead7bb83ea9e85d06c1afc7112413f1d2a81e6448bd276af6bced035ac"}, + {file = "hstspreload-2020.9.23-py3-none-any.whl", hash = "sha256:d0b5ee3f9f2aa7d2f0c5e8fe7b3b6605eef26a302ba373e0d5a76e7d8e871504"}, + {file = "hstspreload-2020.9.23.tar.gz", hash = "sha256:35822733ba67cfb4efc6cd7d1230b509f0bd42c90eeb329faf2fe679f801e40f"}, ] html2text = [ {file = "html2text-2020.1.16-py3-none-any.whl", hash = "sha256:c7c629882da0cf377d66f073329ccf34a12ed2adf0169b9285ae4e63ef54c82b"}, @@ -988,8 +989,8 @@ jinja2 = [ {file = "Jinja2-2.11.2.tar.gz", hash = "sha256:89aab215427ef59c34ad58735269eb58b1a5808103067f7bb9d5836c651b3bb0"}, ] loguru = [ - {file = "loguru-0.5.2-py3-none-any.whl", hash = "sha256:a5e5e196b9958feaf534ac2050171d16576bae633074ce3e73af7dda7e9a58ae"}, - {file = "loguru-0.5.2.tar.gz", hash = "sha256:5aecbf13bc8e2f6e5a5d0475460a345b44e2885464095ea7de44e8795857ad33"}, + {file = "loguru-0.5.3-py3-none-any.whl", hash = "sha256:f8087ac396b5ee5f67c963b495d615ebbceac2796379599820e324419d53667c"}, + {file = "loguru-0.5.3.tar.gz", hash = "sha256:b28e72ac7a98be3d28ad28570299a393dfcd32e5e3f6a353dec94675767b6319"}, ] markupsafe = [ {file = "MarkupSafe-1.1.1-cp27-cp27m-macosx_10_6_intel.whl", hash = "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161"},