Skip to content

Commit

Permalink
fix: check bot account before sending notification
Browse files Browse the repository at this point in the history
  • Loading branch information
siderai committed May 23, 2023
1 parent 702c796 commit 62c0d39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions botx/bots/mixins/requests/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ async def call_method( # noqa: WPS211
"""
if credentials is not None:
debug_bot_id = credentials.bot_id
host = cast(str, credentials.host)
bot_id = cast(UUID, credentials.bot_id)
method.configure(
host=host,
host=cast(CredentialsSearchProtocol, self).get_account_by_bot_id(bot_id).host,
token=cast(CredentialsSearchProtocol, self).get_token_for_bot(bot_id),
)
else:
Expand Down
9 changes: 8 additions & 1 deletion botx/models/messages/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,17 @@ def __init__(self, message: IncomingMessage, bot: "bots.Bot") -> None:
self.credentials = SendingCredentials(
sync_id=self.sync_id,
bot_id=self.bot_id,
host=self.host,
host=self.get_host_by_bot_id(self.bot, self.bot_id),
chat_id=self.group_chat_id,
)

@classmethod
def get_host_by_bot_id(cls, bot: "bots.Bot", bot_id: UUID) -> str:
for account in bot.bot_accounts:
if account.bot_id == bot_id:
return account.host
raise ValueError("Not found account by bot_id")

@classmethod
def from_dict(cls, message: dict, bot: "bots.Bot") -> Message:
"""Parse incoming dict into message.
Expand Down

0 comments on commit 62c0d39

Please sign in to comment.