1
0
Fork 0

Added silent notification option (Closes #9)

This commit is contained in:
Casey 2022-08-26 21:24:36 +03:00
parent 855596c666
commit 9024f14f40
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
2 changed files with 12 additions and 4 deletions

View File

@ -54,6 +54,10 @@ show-post-link = yes
; Should we show link to original author before post content? ; Should we show link to original author before post content?
show-boost-from = yes show-boost-from = yes
; Should we make posts silent?
; https://core.telegram.org/bots/api#sendmessage `disable_notification`
silent = true
; Discord integration ; Discord integration
[module/discord] [module/discord]
type = discord type = discord

View File

@ -42,11 +42,13 @@ class TelegramIntegration(BaseIntegration):
chat_id: Union[str, int], chat_id: Union[str, int],
show_post_link: bool = True, show_post_link: bool = True,
show_boost_from: bool = True, show_boost_from: bool = True,
silent: bool = True,
): ):
self.token = token self.token = token
self.chat_id = chat_id self.chat_id = chat_id
self.show_post_link = show_post_link self.show_post_link = show_post_link
self.show_boost_from = show_boost_from self.show_boost_from = show_boost_from
self.silent = silent
async def _tg_request(self, method: str, **kwargs) -> TGResponse: async def _tg_request(self, method: str, **kwargs) -> TGResponse:
url = self.API_URL.format(self.token, method) url = self.API_URL.format(self.token, method)
@ -59,7 +61,7 @@ class TelegramIntegration(BaseIntegration):
return await self._tg_request( return await self._tg_request(
"sendMessage", "sendMessage",
parse_mode="HTML", parse_mode="HTML",
disable_notification=True, disable_notification=self.silent,
disable_web_page_preview=True, disable_web_page_preview=True,
chat_id=self.chat_id, chat_id=self.chat_id,
text=text, text=text,
@ -73,7 +75,7 @@ class TelegramIntegration(BaseIntegration):
return await self._tg_request( return await self._tg_request(
"send%s" % self.MEDIA_MAPPING[media.type].title(), "send%s" % self.MEDIA_MAPPING[media.type].title(),
parse_mode="HTML", parse_mode="HTML",
disable_notification=True, disable_notification=self.silent,
disable_web_page_preview=True, disable_web_page_preview=True,
chat_id=self.chat_id, chat_id=self.chat_id,
caption=text, caption=text,
@ -105,7 +107,7 @@ class TelegramIntegration(BaseIntegration):
return await self._tg_request( return await self._tg_request(
"sendMediaGroup", "sendMediaGroup",
disable_notification=True, disable_notification=self.silent,
disable_web_page_preview=True, disable_web_page_preview=True,
chat_id=self.chat_id, chat_id=self.chat_id,
media=media_list, media=media_list,
@ -116,7 +118,7 @@ class TelegramIntegration(BaseIntegration):
) -> TGResponse: ) -> TGResponse:
return await self._tg_request( return await self._tg_request(
"sendPoll", "sendPoll",
disable_notification=True, disable_notification=self.silent,
disable_web_page_preview=True, disable_web_page_preview=True,
chat_id=self.chat_id, chat_id=self.chat_id,
question=f"Poll:{poll.id}", question=f"Poll:{poll.id}",
@ -196,8 +198,10 @@ class TelegramIntegration(BaseIntegration):
"chat_id={chat!r} " "chat_id={chat!r} "
"show_post_link={show_post_link!r} " "show_post_link={show_post_link!r} "
"show_boost_from={show_boost_from!r} " "show_boost_from={show_boost_from!r} "
"silent={silent!r}>"
).format( ).format(
chat=self.chat_id, chat=self.chat_id,
show_post_link=self.show_post_link, show_post_link=self.show_post_link,
show_boost_from=self.show_boost_from, show_boost_from=self.show_boost_from,
silent=self.silent
) )