Conditional webbrowser import (#4261)

This commit is contained in:
Balázs Triszka 2023-11-28 00:04:36 +01:00 committed by GitHub
parent cf3bc71e1d
commit 584735afe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,11 @@
from .. import types, functions from .. import types, functions
from ... import password as pwd_mod from ... import password as pwd_mod
from ...errors import BotResponseTimeoutError from ...errors import BotResponseTimeoutError
import webbrowser try:
import webbrowser
except ModuleNotFoundError:
pass
import sys
import os import os
@ -112,7 +116,8 @@ class MessageButton:
bot=self._bot, peer=self._chat, start_param=self.button.query bot=self._bot, peer=self._chat, start_param=self.button.query
)) ))
elif isinstance(self.button, types.KeyboardButtonUrl): elif isinstance(self.button, types.KeyboardButtonUrl):
return webbrowser.open(self.button.url) if "webbrowser" in sys.modules:
return webbrowser.open(self.button.url)
elif isinstance(self.button, types.KeyboardButtonGame): elif isinstance(self.button, types.KeyboardButtonGame):
req = functions.messages.GetBotCallbackAnswerRequest( req = functions.messages.GetBotCallbackAnswerRequest(
peer=self._chat, msg_id=self._msg_id, game=True peer=self._chat, msg_id=self._msg_id, game=True