From ddeaadb300dbae90dbf23de4e26a566d96eb4535 Mon Sep 17 00:00:00 2001 From: Frisk Date: Sat, 8 May 2021 01:21:38 +0200 Subject: [PATCH] Migrated spritesheet extension related logs --- extensions/base/sprite.py | 91 +++++++++++++++++++++++++++++++++++++++ src/rc_formatters.py | 18 +++----- 2 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 extensions/base/sprite.py diff --git a/extensions/base/sprite.py b/extensions/base/sprite.py new file mode 100644 index 0000000..f1c7a80 --- /dev/null +++ b/extensions/base/sprite.py @@ -0,0 +1,91 @@ +# 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 . + +import logging +from src.discord.message import DiscordMessage +from src.api import formatter +from src.i18n import rc_formatters +from src.api.context import Context +from src.api.util import embed_helper, compact_author, create_article_path, sanitize_to_markdown, sanitize_to_url, \ + clean_link + +_ = rc_formatters.gettext +ngettext = rc_formatters.ngettext + + +# SpriteSheet - https://www.mediawiki.org/wiki/Extension:SpriteSheet +# sprite/sprite - Editing a sprite + + +@formatter.embed(event="sprite/sprite") +def embed_sprite_sprite(ctx: Context, change: dict): + embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url) + embed_helper(ctx, embed, change) + embed["url"] = create_article_path(sanitize_to_url(change["title"])) + embed["title"] = _("Edited the sprite for {article}").format(article=sanitize_to_markdown(change["title"])) + return embed + + +@formatter.compact(event="sprite/sprite") +def compact_sprite_sprite(ctx: Context, change: dict): + author, author_url = compact_author(ctx, change) + link = clean_link(create_article_path(sanitize_to_url(change["title"]))) + content = _("[{author}]({author_url}) edited the sprite for [{article}]({article_url})").format(author=author, + author_url=author_url, + article=sanitize_to_markdown(change[ + "title"]), + article_url=link) + return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content) + +# sprite/sheet - Creating a sprite sheet + + +@formatter.embed(event="sprite/sheet") +def embed_sprite_sheet(ctx: Context, change: dict): + embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url) + embed_helper(ctx, embed, change) + embed["url"] = create_article_path(sanitize_to_url(change["title"])) + embed["title"] = _("Created the sprite sheet for {article}").format(article=sanitize_to_markdown(change["title"])) + return embed + + +@formatter.compact(event="sprite/sheet") +def compact_sprite_sheet(ctx: Context, change: dict): + author, author_url = compact_author(ctx, change) + link = clean_link(create_article_path(sanitize_to_url(change["title"]))) + content = _("[{author}]({author_url}) created the sprite sheet for [{article}]({article_url})").format(author=author, author_url=author_url, article=sanitize_to_markdown(change["title"]), article_url=link) + return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content) + +# sprite/slice - Editing a slice + + +@formatter.embed(event="sprite/slice") +def embed_sprite_slice(ctx: Context, change: dict): + embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url) + embed_helper(ctx, embed, change) + embed["url"] = create_article_path(sanitize_to_url(change["title"])) + embed["title"] = _("Edited the slice for {article}").format(article=sanitize_to_markdown(change["title"])) + return embed + +@formatter.compact(event="sprite/slice") +def compact_sprite_slice(ctx: Context, change: dict): + author, author_url = compact_author(ctx, change) + link = clean_link(create_article_path(sanitize_to_url(change["title"]))) + content = _("[{author}]({author_url}) edited the slice for [{article}]({article_url})").format(author=author, + author_url=author_url, + article=sanitize_to_markdown(change[ + "title"]), + article_url=link) + return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content) diff --git a/src/rc_formatters.py b/src/rc_formatters.py index c39d855..7d2e0a5 100644 --- a/src/rc_formatters.py +++ b/src/rc_formatters.py @@ -220,14 +220,11 @@ def compact_formatter(action, change, parsed_comment, categories, recent_changes elif action == "contentmodel/new": elif action == "sprite/sprite": - link = link_formatter(create_article_path(change["title"])) - content = _("[{author}]({author_url}) edited the sprite for [{article}]({article_url})").format(author=author, author_url=author_url, article=change["title"], article_url=link) + elif action == "sprite/sheet": - link = link_formatter(create_article_path(change["title"])) - content = _("[{author}]({author_url}) created the sprite sheet for [{article}]({article_url})").format(author=author, author_url=author_url, article=change["title"], article_url=link) + elif action == "sprite/slice": - link = link_formatter(create_article_path(change["title"])) - content = _("[{author}]({author_url}) edited the slice for [{article}]({article_url})").format(author=author, author_url=author_url, article=change["title"], article_url=link) + elif action == "cargo/createtable": elif action == "cargo/deletetable": @@ -573,14 +570,11 @@ def embed_formatter(action, change, parsed_comment, categories, recent_changes): elif action == "contentmodel/new": elif action == "sprite/sprite": - link = create_article_path(change["title"]) - embed["title"] = _("Edited the sprite for {article}").format(article=change["title"]) + elif action == "sprite/sheet": - link = create_article_path(change["title"]) - embed["title"] = _("Created the sprite sheet for {article}").format(article=change["title"]) + elif action == "sprite/slice": - link = create_article_path(change["title"]) - embed["title"] = _("Edited the slice for {article}").format(article=change["title"]) + elif action == "cargo/createtable": elif action == "cargo/deletetable":