diff --git a/telegram/bot.py b/telegram/bot.py index fae7a4a22..6df6a5081 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -85,6 +85,8 @@ class Bot(TelegramObject): private_key_password (:obj:`bytes`, optional): Password for above private key. default_parse_mode (:obj:`str`, optional): Default parse mode used if not set explicitly in method call. See the constants in :class:`telegram.ParseMode` for the available modes. + default_disable_notification (:obj:`bool`, optional): Default setting for the + `disable_notification` parameter used if not set explicitly in method call. """ @@ -118,12 +120,20 @@ class Bot(TelegramObject): return instance - def __init__(self, token, base_url=None, base_file_url=None, request=None, private_key=None, - private_key_password=None, default_parse_mode=None): + def __init__(self, + token, + base_url=None, + base_file_url=None, + request=None, + private_key=None, + private_key_password=None, + default_parse_mode=None, + default_disable_notification=None): self.token = self._validate_token(token) # Gather default - self.defaults = Defaults(parse_mode=default_parse_mode) + self.defaults = Defaults(parse_mode=default_parse_mode, + disable_notification=default_disable_notification) if base_url is None: base_url = 'https://api.telegram.org/bot' diff --git a/telegram/ext/updater.py b/telegram/ext/updater.py index 6cb3516b8..cef70d4a8 100644 --- a/telegram/ext/updater.py +++ b/telegram/ext/updater.py @@ -58,9 +58,10 @@ class Updater(object): persistence (:class:`telegram.ext.BasePersistence`): Optional. The persistence class to store data that should be persistent over restarts. use_context (:obj:`bool`, optional): ``True`` if using context based callbacks. - default_parse_mode (:obj:`str`, optional): Default parse mode used if not set explicitly in + default_parse_mode (:obj:`str`): Optional. Default parse mode used if not set explicitly in method call. See the constants in :class:`telegram.ParseMode` for the available modes. - + default_disable_notification (:obj:`bool`): Optional. Default setting for the + `disable_notification` parameter used if not set explicitly in method call. Args: token (:obj:`str`, optional): The bot's token given by the @BotFather. base_url (:obj:`str`, optional): Base_url for the bot. @@ -85,6 +86,8 @@ class Updater(object): store data that should be persistent over restarts. default_parse_mode (:obj:`str`, optional): Default parse mode used if not set explicitly in method call. See the constants in :class:`telegram.ParseMode` for the available modes. + default_disable_notification (:obj:`bool`, optional): Default setting for the + `disable_notification` parameter used if not set explicitly in method call. Note: You must supply either a :attr:`bot` or a :attr:`token` argument. @@ -107,6 +110,7 @@ class Updater(object): request_kwargs=None, persistence=None, default_parse_mode=None, + default_disable_notification=None, use_context=False): if (token is None) and (bot is None): @@ -140,7 +144,8 @@ class Updater(object): self._request = Request(**request_kwargs) self.bot = Bot(token, base_url, request=self._request, private_key=private_key, private_key_password=private_key_password, - default_parse_mode=default_parse_mode) + default_parse_mode=default_parse_mode, + default_disable_notification=default_disable_notification) self.user_sig_handler = user_sig_handler self.update_queue = Queue() self.job_queue = JobQueue() diff --git a/telegram/utils/helpers.py b/telegram/utils/helpers.py index c2d22dec7..260d0d27f 100644 --- a/telegram/utils/helpers.py +++ b/telegram/utils/helpers.py @@ -264,16 +264,21 @@ class Defaults: Attributes: parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width toxt or URLs in your bot's message. + disable_notification (:obj:`bool`): Optional. Sends the message silently. Users will + receive a notification with no sound. Parameters: parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width toxt or URLs in your bot's message. + disable_notification (:obj:`bool`, optional): Sends the message silently. Users will + receive a notification with no sound. """ - def __init__(self, parse_mode=None): + def __init__(self, parse_mode=None, disable_notification=None): self.parse_mode = parse_mode + self.disable_notification = disable_notification def __hash__(self): - return hash((self.parse_mode)) + return hash((self.parse_mode, self.disable_notification)) def __eq__(self, other): if isinstance(other, Defaults): diff --git a/tests/test_chat.py b/tests/test_chat.py index b3b693e3f..c2d7c65ec 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -181,9 +181,9 @@ class TestChat(object): def test_instance_method_send_sticker(self, monkeypatch, chat): def test(*args, **kwargs): - return args[1] == chat.id and args[2] == 'test_sticker' + return args[0] == chat.id and args[1] == 'test_sticker' - monkeypatch.setattr('telegram.Bot.send_sticker', test) + monkeypatch.setattr(chat.bot, 'send_sticker', test) assert chat.send_sticker('test_sticker') def test_instance_method_send_video(self, monkeypatch, chat): @@ -195,9 +195,9 @@ class TestChat(object): def test_instance_method_send_video_note(self, monkeypatch, chat): def test(*args, **kwargs): - return args[1] == chat.id and args[2] == 'test_video_note' + return args[0] == chat.id and args[1] == 'test_video_note' - monkeypatch.setattr('telegram.Bot.send_video_note', test) + monkeypatch.setattr(chat.bot, 'send_video_note', test) assert chat.send_video_note('test_video_note') def test_instance_method_send_voice(self, monkeypatch, chat): @@ -216,9 +216,9 @@ class TestChat(object): def test_instance_method_send_poll(self, monkeypatch, chat): def test(*args, **kwargs): - return args[1] == chat.id and args[2] == 'test_poll' + return args[0] == chat.id and args[1] == 'test_poll' - monkeypatch.setattr('telegram.Bot.send_poll', test) + monkeypatch.setattr(chat.bot, 'send_poll', test) assert chat.send_poll('test_poll') def test_equality(self):