Skip to content

Commit

Permalink
🐛 await get_bot_self
Browse files Browse the repository at this point in the history
  • Loading branch information
j1g5awi committed Aug 19, 2024
1 parent dd00f06 commit 102162f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions nonebot_plugin_all4one/middlewares/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ async def _call_api(self, api: str, **kwargs: Any) -> Any:
def self_id(self) -> str:
return self.bot.self_id

def get_bot_self(self) -> BotSelf:
async def get_bot_self(self) -> BotSelf:
return BotSelf(
platform=self.get_platform(),
user_id=self.self_id,
**{
"supported_actions": self.get_supported_actions(),
"supported_message_segments": self.get_supported_message_segments(),
"supported_actions": await self.get_supported_actions(),
"supported_message_segments": await self.get_supported_message_segments(),
},
)

Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_all4one/middlewares/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def to_onebot_event(self, event: Event) -> list[OneBotEvent]:
if (type := event.get_type()) not in ["message", "notice", "request"]:
return []
event_dict["type"] = type
event_dict["self"] = self.get_bot_self().model_dump()
event_dict["self"] = (await self.get_bot_self()).model_dump()
if isinstance(event, MessageEvent):
event_dict["id"] = str(event.id)
event_dict["time"] = event.timestamp
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_all4one/middlewares/onebot_v11.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def to_onebot_event(self, event: Event) -> list[OneBotEvent]:
event_dict["type"] = event.post_type
if isinstance(event, MetaEvent):
return []
event_dict["self"] = self.get_bot_self().model_dump()
event_dict["self"] = (await self.get_bot_self()).model_dump()
if isinstance(event, MessageEvent):
event_dict["detail_type"] = event.message_type
event_dict["message"] = await self.to_onebot_message(event.original_message)
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_all4one/middlewares/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def to_onebot_event(self, event: Event) -> list[OneBotEvent]:
if (type := event.get_type()) not in ["message", "notice", "request"]:
return []
event_dict["type"] = type
event_dict["self"] = self.get_bot_self().model_dump()
event_dict["self"] = (await self.get_bot_self()).model_dump()
if isinstance(event, MessageEvent):
event_dict["time"] = event.date
event_dict["detail_type"] = event.get_event_name().split(".")[1]
Expand Down
8 changes: 5 additions & 3 deletions nonebot_plugin_all4one/onebotimpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ async def get_status(self, **kwargs: Any) -> Status:
return Status(
good=True,
bots=[
BotStatus(self=middleware.get_bot_self(), online=True)
BotStatus(self=await middleware.get_bot_self(), online=True)
for middleware in self.middlewares.values()
],
)
Expand Down Expand Up @@ -471,7 +471,7 @@ async def bot_connect(self, bot: Bot) -> None:
sub_type="",
status=Status(
good=True,
bots=[BotStatus(self=middleware.get_bot_self(), online=True)],
bots=[BotStatus(self=await middleware.get_bot_self(), online=True)],
),
)
await queue.put(event)
Expand All @@ -488,7 +488,9 @@ async def bot_disconnect(self, bot: Bot) -> None:
sub_type="",
status=Status(
good=True,
bots=[BotStatus(self=middleware.get_bot_self(), online=False)],
bots=[
BotStatus(self=await middleware.get_bot_self(), online=False)
],
),
)
await queue.put(event)
Expand Down

0 comments on commit 102162f

Please sign in to comment.