RcGcDb/extensions/base/sprite.py

87 lines
4.7 KiB
Python
Raw Normal View History

2022-07-24 20:02:25 +00:00
# This file is part of Recent changes Goat compatible Discord webhook (RcGcDw).
2021-07-08 11:33:10 +00:00
#
2022-07-24 20:02:25 +00:00
# RcGcDw is free software: you can redistribute it and/or modify
2021-07-08 11:33:10 +00:00
# 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
2022-07-24 20:02:25 +00:00
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
2021-07-08 11:33:10 +00:00
import logging
from src.discord.message import DiscordMessage
from src.api import formatter
from src.api.context import Context
2022-10-03 13:34:36 +00:00
from src.api.util import embed_helper, compact_author, sanitize_to_markdown, sanitize_to_url, clean_link
2021-07-08 11:33:10 +00:00
# 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):
2022-10-03 13:34:36 +00:00
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
2021-07-08 11:33:10 +00:00
embed_helper(ctx, embed, change)
2022-10-03 13:34:36 +00:00
embed["url"] = ctx.client.create_article_path(sanitize_to_url(change["title"]))
2022-07-24 20:02:25 +00:00
embed["title"] = ctx._("Edited the sprite for {article}").format(article=sanitize_to_markdown(change["title"]))
2021-07-08 11:33:10 +00:00
return embed
@formatter.compact(event="sprite/sprite")
def compact_sprite_sprite(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
2022-10-03 13:34:36 +00:00
link = clean_link(ctx.client.create_article_path(sanitize_to_url(change["title"])))
2022-07-24 20:02:25 +00:00
content = ctx._("[{author}]({author_url}) edited the sprite for [{article}]({article_url})").format(author=author,
2021-07-08 11:33:10 +00:00
author_url=author_url,
article=sanitize_to_markdown(change[
"title"]),
article_url=link)
2022-10-03 13:34:36 +00:00
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
2021-07-08 11:33:10 +00:00
# sprite/sheet - Creating a sprite sheet
@formatter.embed(event="sprite/sheet")
def embed_sprite_sheet(ctx: Context, change: dict):
2022-10-03 13:34:36 +00:00
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
2021-07-08 11:33:10 +00:00
embed_helper(ctx, embed, change)
2022-10-03 13:34:36 +00:00
embed["url"] = ctx.client.create_article_path(sanitize_to_url(change["title"]))
2022-07-24 20:02:25 +00:00
embed["title"] = ctx._("Created the sprite sheet for {article}").format(article=sanitize_to_markdown(change["title"]))
2021-07-08 11:33:10 +00:00
return embed
@formatter.compact(event="sprite/sheet")
def compact_sprite_sheet(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
2022-10-03 13:34:36 +00:00
link = clean_link(ctx.client.create_article_path(sanitize_to_url(change["title"])))
2022-07-24 20:02:25 +00:00
content = ctx._("[{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)
2022-10-03 13:34:36 +00:00
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
2021-07-08 11:33:10 +00:00
# sprite/slice - Editing a slice
@formatter.embed(event="sprite/slice")
def embed_sprite_slice(ctx: Context, change: dict):
2022-10-03 13:34:36 +00:00
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
2021-07-08 11:33:10 +00:00
embed_helper(ctx, embed, change)
2022-10-03 13:34:36 +00:00
embed["url"] = ctx.client.create_article_path(sanitize_to_url(change["title"]))
2022-07-24 20:02:25 +00:00
embed["title"] = ctx._("Edited the slice for {article}").format(article=sanitize_to_markdown(change["title"]))
2021-07-08 11:33:10 +00:00
return embed
@formatter.compact(event="sprite/slice")
def compact_sprite_slice(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
2022-10-03 13:34:36 +00:00
link = clean_link(ctx.client.create_article_path(sanitize_to_url(change["title"])))
2022-07-24 20:02:25 +00:00
content = ctx._("[{author}]({author_url}) edited the slice for [{article}]({article_url})").format(author=author,
2021-07-08 11:33:10 +00:00
author_url=author_url,
article=sanitize_to_markdown(change[
"title"]),
article_url=link)
2022-10-03 13:34:36 +00:00
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)