-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d4d676
commit 5b92a82
Showing
7 changed files
with
180 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .bot import Bot | ||
from .event import * | ||
from .file import File | ||
from .adapter import Adapter | ||
from .message import Message, MessageSegment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from typing import Callable, Any, Union, Awaitable, Type, Optional | ||
from asyncio import to_thread, iscoroutinefunction | ||
import asyncio | ||
|
||
from nonebot.drivers import ( | ||
Request, | ||
Response, | ||
ASGIMixin, | ||
WebSocket, | ||
HTTPServerSetup, | ||
HTTPClientMixin, | ||
WebSocketServerSetup | ||
) | ||
|
||
from .event import OfficalEvent | ||
from .utils import log | ||
|
||
|
||
class OfficialReplyResult: | ||
""" 公众号被动回复内容储存 """ | ||
|
||
def __init__(self) -> None: | ||
self._futures: dict[int, asyncio.Future] = {} | ||
|
||
def set_resp(self, event_id: str, resp: Response) -> None: | ||
""" 设置响应 """ | ||
if future := self._futures.get(event_id): | ||
future.set_result(resp) | ||
|
||
async def get_resp(self, event_id: str, timeout: float) -> Response: | ||
""" 获取响应 """ | ||
future = asyncio.get_event_loop().create_future() | ||
self._futures[event_id] = future | ||
try: | ||
return await asyncio.wait_for(future, timeout) | ||
finally: | ||
try: | ||
del self._futures[event_id] | ||
except: | ||
pass | ||
|
||
def clear(self, event_id: str) -> None: | ||
""" 清除响应 """ | ||
if future := self._futures.get(event_id): | ||
try: | ||
future.cancel() | ||
del self._futures[event_id] | ||
except: | ||
pass |