mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Updated talk_notify.py with capability to change default language of webhook messages
This commit is contained in:
parent
f648b19cdd
commit
774854c338
|
@ -12,6 +12,9 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
|
||||
import gettext
|
||||
from typing import Callable, Optional
|
||||
|
||||
from src.api.context import Context
|
||||
from src.discord.message import DiscordMessage, DiscordMessageMetadata
|
||||
from src.discord.queue import send_to_discord
|
||||
|
@ -23,6 +26,7 @@ from src.configloader import settings
|
|||
# "hooks": {
|
||||
# "talk_notify": {
|
||||
# "default": ["https://discord.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],
|
||||
# "lang": "en",
|
||||
# "namespace": {
|
||||
# "10001": ["https://discord.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],
|
||||
# "10003": ["https://discord.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],
|
||||
|
@ -72,13 +76,18 @@ def talk_notify_hook(context: Context, change: dict):
|
|||
bold = ""
|
||||
if abs(edit_size) > 500:
|
||||
bold = "**"
|
||||
translator: Optional[Callable] = None
|
||||
if settings["lang"] != talk_notify.get("lang", settings["lang"]):
|
||||
translator = gettext.translation('formatters', localedir='locale', languages=[talk_notify.get("lang", settings["lang"])]).gettext
|
||||
else:
|
||||
translator = context.gettext
|
||||
if context.event == "edit":
|
||||
content = context._(
|
||||
content = translator(
|
||||
"[{author}]({author_url}) edited [{article}]({edit_link}){comment} {bold}({sign}{edit_size}){bold}").format(
|
||||
author=author, author_url=author_url, article=sanitize_to_markdown(change["title"]).replace("\\:", ":"), edit_link=edit_link, comment=parsed_comment,
|
||||
edit_size=edit_size, sign=sign, bold=bold)
|
||||
else:
|
||||
content = context._(
|
||||
content = translator(
|
||||
"[{author}]({author_url}) created [{article}]({edit_link}){comment} {bold}({sign}{edit_size}){bold}").format(
|
||||
author=author, author_url=author_url, article=sanitize_to_markdown(change["title"]).replace("\\:", ":"), edit_link=edit_link, comment=parsed_comment,
|
||||
edit_size=edit_size, sign=sign, bold=bold)
|
||||
|
|
Loading…
Reference in a new issue