# This file is part of Recent changes Goat compatible Discord webhook (RcGcDw). # # RcGcDw is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # RcGcDw is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with RcGcDw. If not, see . from textwrap import shorten from src.discord.message import DiscordMessage from src.api import formatter from src.api.context import Context from src.api.util import embed_helper, compact_author, sanitize_to_markdown, sanitize_to_url, compact_summary # Comments - https://www.mediawiki.org/wiki/Extension:Comments # comments/add - Adding a comment @formatter.embed(event="comments/add") def embed_comments_add(ctx: Context, change: dict) -> DiscordMessage: embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url) embed_helper(ctx, embed, change) embed["title"] = ctx._("Commented on {page}").format(page=sanitize_to_markdown(change["title"])) embed["url"] = "{url}#comment-{commentid}".format(url=ctx.client.create_article_path(sanitize_to_url(change["title"])), commentid=change.get("logparams", {}).get("commentid", "0")) return embed @formatter.compact(event="comments/add") def compact_comments_add(ctx: Context, change: dict): author, author_url = compact_author(ctx, change) parsed_comment = compact_summary(ctx) content = ctx._("[{author}]({author_url}) commented on [{page}]({page_link}): {comment}").format( author=author, author_url=author_url, page=sanitize_to_markdown(change["title"]), page_link="{url}#comment-{commentid}".format(url=ctx.client.create_article_path(sanitize_to_url(change["title"])), commentid=change.get("logparams", {}).get("commentid", "0")), comment=sanitize_to_markdown(shorten(parsed_comment, width=100, placeholder="…")) ) return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content) # comments/delete - Deleting a comment @formatter.embed(event="comments/delete") def embed_comments_delete(ctx: Context, change: dict) -> DiscordMessage: embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url) embed_helper(ctx, embed, change) embed["title"] = ctx._("Deleted a comment on {page}").format(page=sanitize_to_markdown(change["title"])) embed["url"] = ctx.client.create_article_path(sanitize_to_url(change["title"])) return embed @formatter.compact(event="comments/delete") def compact_comments_delete(ctx: Context, change: dict): author, author_url = compact_author(ctx, change) content = ctx._("[{author}]({author_url}) deleted a comment on {page}]({page_link})").format( author=author, author_url=author_url, page=sanitize_to_markdown(change["title"]), page_link=ctx.client.create_article_path(sanitize_to_url(change["title"])) ) return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)