mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Migrated a few formatters
This commit is contained in:
parent
77bdac1349
commit
f09862c277
|
@ -253,6 +253,51 @@ def compact_delete_delete_redir(ctx, change) -> DiscordMessage:
|
||||||
comment=parsed_comment)
|
comment=parsed_comment)
|
||||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||||
|
|
||||||
|
# delete/restore - Restoring a page
|
||||||
|
|
||||||
|
@formatter.embed(event="delete/restore", mode="embed")
|
||||||
|
def embed_delete_restore(ctx, change) -> DiscordMessage:
|
||||||
|
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"] = _("Restored {article}").format(article=sanitize_to_markdown(change["title"]))
|
||||||
|
embed["description"] = ctx.parsedcomment
|
||||||
|
return embed
|
||||||
|
|
||||||
|
|
||||||
|
@formatter.compact(event="delete/restore", mode="compact")
|
||||||
|
def compact_delete_restore(ctx, change) -> DiscordMessage:
|
||||||
|
page_link = clean_link(create_article_path(sanitize_to_url(change["title"])))
|
||||||
|
author, author_url = compact_author(ctx, change)
|
||||||
|
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
|
||||||
|
content = _("[{author}]({author_url}) restored [{article}]({article_url}){comment}").format(author=author,
|
||||||
|
author_url=author_url,
|
||||||
|
article=sanitize_to_markdown(change["title"]),
|
||||||
|
article_url=page_link,
|
||||||
|
comment=parsed_comment)
|
||||||
|
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||||
|
|
||||||
|
# delete/event - Deleting an event with revdelete feature
|
||||||
|
|
||||||
|
@formatter.embed(event="delete/event", mode="embed")
|
||||||
|
def embed_delete_event(ctx, change) -> DiscordMessage:
|
||||||
|
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
|
||||||
|
embed_helper(ctx, embed, change)
|
||||||
|
embed['url'] = create_article_path("Special:RecentChanges")
|
||||||
|
embed["title"] = _("Changed visibility of log events")
|
||||||
|
embed["description"] = ctx.parsedcomment
|
||||||
|
return embed
|
||||||
|
|
||||||
|
|
||||||
|
@formatter.compact(event="delete/event", mode="compact")
|
||||||
|
def compact_delete_event(ctx, change) -> DiscordMessage:
|
||||||
|
page_link = clean_link(create_article_path(sanitize_to_url(change["title"])))
|
||||||
|
author, author_url = compact_author(ctx, change)
|
||||||
|
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
|
||||||
|
content = _("[{author}]({author_url}) changed visibility of log events{comment}").format(author=author,
|
||||||
|
author_url=author_url, comment=parsed_comment)
|
||||||
|
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||||
|
|
||||||
# move/move - Moving pages
|
# move/move - Moving pages
|
||||||
|
|
||||||
|
|
||||||
|
@ -326,6 +371,7 @@ def embed_protect_move_prot(ctx, change):
|
||||||
embed["title"] = _("Moved protection settings from {redirect}{article} to {title}").format(
|
embed["title"] = _("Moved protection settings from {redirect}{article} to {title}").format(
|
||||||
redirect="⤷ " if "redirect" in change else "", article=sanitize_to_markdown(change["logparams"]["oldtitle_title"]),
|
redirect="⤷ " if "redirect" in change else "", article=sanitize_to_markdown(change["logparams"]["oldtitle_title"]),
|
||||||
title=sanitize_to_markdown(change["title"]))
|
title=sanitize_to_markdown(change["title"]))
|
||||||
|
embed["description"] = ctx.parsedcomment
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
@formatter.compact(event="protect/move_prot", mode="compact")
|
@formatter.compact(event="protect/move_prot", mode="compact")
|
||||||
|
@ -418,7 +464,7 @@ def compact_protect_unprotect(ctx, change):
|
||||||
author=author, author_url=author_url, article=sanitize_to_markdown(change["title"]), article_url=link, comment=ctx.parsedcomment)
|
author=author, author_url=author_url, article=sanitize_to_markdown(change["title"]), article_url=link, comment=ctx.parsedcomment)
|
||||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||||
|
|
||||||
# block/block
|
# block/block - Blocking an user
|
||||||
def block_expiry(change: dict) -> str:
|
def block_expiry(change: dict) -> str:
|
||||||
if change["logparams"]["duration"] in ["infinite", "indefinite", "infinity", "never"]:
|
if change["logparams"]["duration"] in ["infinite", "indefinite", "infinity", "never"]:
|
||||||
return _("for infinity and beyond")
|
return _("for infinity and beyond")
|
||||||
|
@ -481,6 +527,8 @@ def embed_block_block(ctx, change):
|
||||||
if block_flags:
|
if block_flags:
|
||||||
embed.add_field(_("Block flags"), ", ".join(block_flags)) # TODO Translate flags into MW messages, this requires making additional request in init_request since we want to get all messages with prefix (amprefix) block-log-flags- and that parameter is exclusive with ammessages
|
embed.add_field(_("Block flags"), ", ".join(block_flags)) # TODO Translate flags into MW messages, this requires making additional request in init_request since we want to get all messages with prefix (amprefix) block-log-flags- and that parameter is exclusive with ammessages
|
||||||
embed["title"] = _("Blocked {blocked_user} {time}").format(blocked_user=user, time=block_expiry(change))
|
embed["title"] = _("Blocked {blocked_user} {time}").format(blocked_user=user, time=block_expiry(change))
|
||||||
|
embed["description"] = ctx.parsedcomment
|
||||||
|
return embed
|
||||||
|
|
||||||
@formatter.compact(event="block/block", mode="compact")
|
@formatter.compact(event="block/block", mode="compact")
|
||||||
def compact_block_block(ctx, change):
|
def compact_block_block(ctx, change):
|
||||||
|
@ -537,6 +585,7 @@ def embed_block_reblock(ctx, change):
|
||||||
embed["url"] = create_article_path(sanitize_to_url(change["title"]))
|
embed["url"] = create_article_path(sanitize_to_url(change["title"]))
|
||||||
user = change["title"].split(':', 1)[1]
|
user = change["title"].split(':', 1)[1]
|
||||||
embed["title"] = _("Changed block settings for {blocked_user}").format(blocked_user=sanitize_to_markdown(user))
|
embed["title"] = _("Changed block settings for {blocked_user}").format(blocked_user=sanitize_to_markdown(user))
|
||||||
|
embed["description"] = ctx.parsedcomment
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
|
|
||||||
|
@ -547,4 +596,46 @@ def compact_block_reblock(ctx, change):
|
||||||
user = change["title"].split(':', 1)[1]
|
user = change["title"].split(':', 1)[1]
|
||||||
content = _("[{author}]({author_url}) changed block settings for [{blocked_user}]({user_url}){comment}").format(
|
content = _("[{author}]({author_url}) changed block settings for [{blocked_user}]({user_url}){comment}").format(
|
||||||
author=author, author_url=author_url, blocked_user=user, user_url=link, comment=ctx.parsedcomment)
|
author=author, author_url=author_url, blocked_user=user, user_url=link, comment=ctx.parsedcomment)
|
||||||
|
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||||
|
|
||||||
|
|
||||||
|
# block/unblock - Unblocking an user
|
||||||
|
|
||||||
|
@formatter.embed(event="block/unblock", mode="embed")
|
||||||
|
def embed_block_unblock(ctx, change):
|
||||||
|
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"]))
|
||||||
|
user = change["title"].split(':', 1)[1]
|
||||||
|
embed["title"] = _("Unblocked {blocked_user}").format(blocked_user=user)
|
||||||
|
embed["description"] = ctx.parsedcomment
|
||||||
|
return embed
|
||||||
|
|
||||||
|
|
||||||
|
@formatter.compact(event="block/unblock")
|
||||||
|
def compact_block_unblock(ctx, change):
|
||||||
|
author, author_url = compact_author(ctx, change)
|
||||||
|
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
|
||||||
|
user = change["title"].split(':', 1)[1]
|
||||||
|
content = _("[{author}]({author_url}) unblocked [{blocked_user}]({user_url}){comment}").format(author=author,
|
||||||
|
author_url=author_url,
|
||||||
|
blocked_user=user,
|
||||||
|
user_url=link,
|
||||||
|
comment=ctx.parsedcomment)
|
||||||
|
|
||||||
|
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||||
|
|
||||||
|
# suppressed - Custom event for whenever there is limited information available about the event due to revdel
|
||||||
|
|
||||||
|
@formatter.embed(event="suppressed", mode="embed")
|
||||||
|
def embed_suppressed(ctx, change):
|
||||||
|
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
|
||||||
|
embed["url"] = create_article_path("")
|
||||||
|
embed["title"] = _("Action has been hidden by administration")
|
||||||
|
embed["author"]["name"] = _("Unknown")
|
||||||
|
return embed
|
||||||
|
|
||||||
|
@formatter.compact(event="suppressed", mode="compact")
|
||||||
|
def compact_suppressed(ctx, change):
|
||||||
|
content = _("An action has been hidden by administration.")
|
||||||
|
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
|
@ -167,9 +167,7 @@ def compact_formatter(action, change, parsed_comment, categories, recent_changes
|
||||||
elif action == "block/reblock":
|
elif action == "block/reblock":
|
||||||
|
|
||||||
elif action == "block/unblock":
|
elif action == "block/unblock":
|
||||||
link = link_formatter(create_article_path(change["title"]))
|
|
||||||
user = change["title"].split(':', 1)[1]
|
|
||||||
content = _("[{author}]({author_url}) unblocked [{blocked_user}]({user_url}){comment}").format(author=author, author_url=author_url, blocked_user=user, user_url=link, comment=parsed_comment)
|
|
||||||
elif action == "curseprofile/comment-created":
|
elif action == "curseprofile/comment-created":
|
||||||
link = link_formatter(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"])))
|
link = link_formatter(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"])))
|
||||||
target_user = change["title"].split(':', 1)[1]
|
target_user = change["title"].split(':', 1)[1]
|
||||||
|
@ -284,18 +282,9 @@ def compact_formatter(action, change, parsed_comment, categories, recent_changes
|
||||||
"[{author}]({author_url}) imported [{article}]({article_url}) with {count} revisions{comment}", change["logparams"]["count"]).format(
|
"[{author}]({author_url}) imported [{article}]({article_url}) with {count} revisions{comment}", change["logparams"]["count"]).format(
|
||||||
author=author, author_url=author_url, article=change["title"], article_url=link, count=change["logparams"]["count"], comment=parsed_comment)
|
author=author, author_url=author_url, article=change["title"], article_url=link, count=change["logparams"]["count"], comment=parsed_comment)
|
||||||
elif action == "delete/restore":
|
elif action == "delete/restore":
|
||||||
link = link_formatter(create_article_path(change["title"]))
|
|
||||||
content = _("[{author}]({author_url}) restored [{article}]({article_url}){comment}").format(author=author, author_url=author_url, article=change["title"], article_url=link, comment=parsed_comment)
|
|
||||||
elif action == "delete/event":
|
elif action == "delete/event":
|
||||||
content = _("[{author}]({author_url}) changed visibility of log events{comment}").format(author=author, author_url=author_url, comment=parsed_comment)
|
|
||||||
if AUTO_SUPPRESSION_ENABLED:
|
|
||||||
try:
|
|
||||||
logparams = change["logparams"]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
for revid in logparams.get("ids", []):
|
|
||||||
delete_messages(dict(revid=revid))
|
|
||||||
elif action == "import/interwiki":
|
elif action == "import/interwiki":
|
||||||
link = link_formatter(create_article_path(change["title"]))
|
link = link_formatter(create_article_path(change["title"]))
|
||||||
source_link = link_formatter(create_article_path(change["logparams"]["interwiki_title"]))
|
source_link = link_formatter(create_article_path(change["logparams"]["interwiki_title"]))
|
||||||
|
@ -605,7 +594,7 @@ def compact_formatter(action, change, parsed_comment, categories, recent_changes
|
||||||
author=author, author_url=author_url, old_name=change["logparams"]["olduser"], new_name=change["logparams"]["newuser"], link=link, comment=parsed_comment
|
author=author, author_url=author_url, old_name=change["logparams"]["olduser"], new_name=change["logparams"]["newuser"], link=link, comment=parsed_comment
|
||||||
)
|
)
|
||||||
elif action == "suppressed":
|
elif action == "suppressed":
|
||||||
content = _("An action has been hidden by administration.")
|
|
||||||
else:
|
else:
|
||||||
logger.warning("No entry for {event} with params: {params}".format(event=action, params=change))
|
logger.warning("No entry for {event} with params: {params}".format(event=action, params=change))
|
||||||
if not settings.get("support", None):
|
if not settings.get("support", None):
|
||||||
|
@ -656,9 +645,7 @@ def embed_formatter(action, change, parsed_comment, categories, recent_changes):
|
||||||
elif action == "block/reblock":
|
elif action == "block/reblock":
|
||||||
|
|
||||||
elif action == "block/unblock":
|
elif action == "block/unblock":
|
||||||
link = create_article_path(change["title"])
|
|
||||||
user = change["title"].split(':', 1)[1]
|
|
||||||
embed["title"] = _("Unblocked {blocked_user}").format(blocked_user=user)
|
|
||||||
elif action == "curseprofile/comment-created":
|
elif action == "curseprofile/comment-created":
|
||||||
if settings["appearance"]["embed"]["show_edit_changes"]:
|
if settings["appearance"]["embed"]["show_edit_changes"]:
|
||||||
parsed_comment = recent_changes.pull_comment(change["logparams"]["4:comment_id"])
|
parsed_comment = recent_changes.pull_comment(change["logparams"]["4:comment_id"])
|
||||||
|
@ -763,18 +750,9 @@ def embed_formatter(action, change, parsed_comment, categories, recent_changes):
|
||||||
"Imported {article} with {count} revisions", change["logparams"]["count"]).format(
|
"Imported {article} with {count} revisions", change["logparams"]["count"]).format(
|
||||||
article=change["title"], count=change["logparams"]["count"])
|
article=change["title"], count=change["logparams"]["count"])
|
||||||
elif action == "delete/restore":
|
elif action == "delete/restore":
|
||||||
link = create_article_path(change["title"])
|
|
||||||
embed["title"] = _("Restored {article}").format(article=change["title"])
|
|
||||||
elif action == "delete/event":
|
elif action == "delete/event":
|
||||||
link = create_article_path("Special:RecentChanges")
|
|
||||||
embed["title"] = _("Changed visibility of log events")
|
|
||||||
if AUTO_SUPPRESSION_ENABLED:
|
|
||||||
try:
|
|
||||||
logparams = change["logparams"]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
redact_messages(logparams.get("ids", []), 1, logparams.get("new", {}))
|
|
||||||
elif action == "import/interwiki":
|
elif action == "import/interwiki":
|
||||||
link = create_article_path(change["title"])
|
link = create_article_path(change["title"])
|
||||||
embed["title"] = ngettext("Imported {article} with {count} revision from \"{source}\"",
|
embed["title"] = ngettext("Imported {article} with {count} revision from \"{source}\"",
|
||||||
|
@ -999,9 +977,7 @@ def embed_formatter(action, change, parsed_comment, categories, recent_changes):
|
||||||
embed["title"] = _("Renamed user \"{old_name}\" to \"{new_name}\"").format(old_name=change["logparams"]["olduser"], new_name=change["logparams"]["newuser"])
|
embed["title"] = _("Renamed user \"{old_name}\" to \"{new_name}\"").format(old_name=change["logparams"]["olduser"], new_name=change["logparams"]["newuser"])
|
||||||
link = create_article_path("User:"+change["logparams"]["newuser"])
|
link = create_article_path("User:"+change["logparams"]["newuser"])
|
||||||
elif action == "suppressed":
|
elif action == "suppressed":
|
||||||
link = create_article_path("")
|
|
||||||
embed["title"] = _("Action has been hidden by administration")
|
|
||||||
embed["author"]["name"] = _("Unknown")
|
|
||||||
else:
|
else:
|
||||||
logger.warning("No entry for {event} with params: {params}".format(event=action, params=change))
|
logger.warning("No entry for {event} with params: {params}".format(event=action, params=change))
|
||||||
link = create_article_path("Special:RecentChanges")
|
link = create_article_path("Special:RecentChanges")
|
||||||
|
|
|
@ -272,6 +272,13 @@ def rc_processor(change, changed_categories):
|
||||||
discord_message: Optional[DiscordMessage] = default_message(identification_string, formatter_hooks)(context, change)
|
discord_message: Optional[DiscordMessage] = default_message(identification_string, formatter_hooks)(context, change)
|
||||||
if identification_string in ("delete/delete", "delete/delete_redir") and AUTO_SUPPRESSION_ENABLED:
|
if identification_string in ("delete/delete", "delete/delete_redir") and AUTO_SUPPRESSION_ENABLED:
|
||||||
delete_messages(dict(pageid=change.get("pageid")))
|
delete_messages(dict(pageid=change.get("pageid")))
|
||||||
|
elif identification_string == "delete/event" and AUTO_SUPPRESSION_ENABLED:
|
||||||
|
logparams = change.get('logparams', {"ids": []})
|
||||||
|
if settings["appearance"]["mode"] == "embed":
|
||||||
|
redact_messages(logparams.get("ids", []), 1, logparams.get("new", {}))
|
||||||
|
else:
|
||||||
|
for revid in logparams.get("ids", []):
|
||||||
|
delete_messages(dict(revid=revid))
|
||||||
for hook in post_hooks:
|
for hook in post_hooks:
|
||||||
hook(discord_message, metadata)
|
hook(discord_message, metadata)
|
||||||
send_to_discord(discord_message, metadata)
|
send_to_discord(discord_message, metadata)
|
||||||
|
|
Loading…
Reference in a new issue