mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Migrated more formatters
This commit is contained in:
parent
094925573a
commit
46e9318e02
|
@ -298,6 +298,34 @@ def compact_delete_event(ctx, change) -> DiscordMessage:
|
|||
author_url=author_url, comment=parsed_comment)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||
|
||||
# delete/revision - Deleting revision information
|
||||
|
||||
@formatter.embed(event="delete/revision", mode="embed")
|
||||
def embed_delete_revision(ctx, change) -> DiscordMessage:
|
||||
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
|
||||
embed_helper(ctx, embed, change)
|
||||
amount = len(change["logparams"]["ids"])
|
||||
embed['url'] = create_article_path(sanitize_to_url(change["title"]))
|
||||
embed["title"] = ngettext("Changed visibility of revision on page {article} ",
|
||||
"Changed visibility of {amount} revisions on page {article} ", amount).format(
|
||||
article=change["title"], amount=amount)
|
||||
embed["description"] = ctx.parsedcomment
|
||||
return embed
|
||||
|
||||
|
||||
@formatter.compact(event="delete/revision", mode="compact")
|
||||
def compact_delete_revision(ctx, change) -> DiscordMessage:
|
||||
author, author_url = compact_author(ctx, change)
|
||||
amount = len(change["logparams"]["ids"])
|
||||
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
|
||||
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
|
||||
content = ngettext(
|
||||
"[{author}]({author_url}) changed visibility of revision on page [{article}]({article_url}){comment}",
|
||||
"[{author}]({author_url}) changed visibility of {amount} revisions on page [{article}]({article_url}){comment}",
|
||||
amount).format(author=author, author_url=author_url,
|
||||
article=change["title"], article_url=link, amount=amount, comment=parsed_comment)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||
|
||||
# move/move - Moving pages
|
||||
|
||||
|
||||
|
@ -639,3 +667,103 @@ def embed_suppressed(ctx, change):
|
|||
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)
|
||||
|
||||
|
||||
# import/upload - Importing pages by uploading exported XML files
|
||||
|
||||
@formatter.embed(event="import/upload", mode="embed")
|
||||
def embed_import_upload(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"]))
|
||||
embed["title"] = ngettext("Imported {article} with {count} revision",
|
||||
"Imported {article} with {count} revisions", change["logparams"]["count"]).format(
|
||||
article=sanitize_to_markdown(change["title"]), count=change["logparams"]["count"])
|
||||
return embed
|
||||
|
||||
|
||||
@formatter.compact(event="import/upload", mode="compact")
|
||||
def compact_import_upload(ctx, change):
|
||||
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 = ngettext("[{author}]({author_url}) imported [{article}]({article_url}) with {count} revision{comment}",
|
||||
"[{author}]({author_url}) imported [{article}]({article_url}) with {count} revisions{comment}",
|
||||
change["logparams"]["count"]).format(
|
||||
author=author, author_url=author_url, article=sanitize_to_markdown(change["title"]), article_url=link,
|
||||
count=change["logparams"]["count"], comment=parsed_comment)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||
|
||||
# import/interwiki - Importing interwiki entries
|
||||
|
||||
@formatter.embed(event="import/interwiki", mode="embed")
|
||||
def embed_import_interwiki(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"]))
|
||||
embed["title"] = ngettext("Imported {article} with {count} revision from \"{source}\"",
|
||||
"Imported {article} with {count} revisions from \"{source}\"",
|
||||
change["logparams"]["count"]).format(
|
||||
article=sanitize_to_markdown(change["title"]), count=change["logparams"]["count"], source=sanitize_to_markdown(change["logparams"]["interwiki_title"]))
|
||||
return embed
|
||||
|
||||
@formatter.compact(event="import/interwiki", mode="compact")
|
||||
def compact_import_interwiki(ctx, change):
|
||||
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
|
||||
author, author_url = compact_author(ctx, change)
|
||||
source_link = clean_link(create_article_path(change["logparams"]["interwiki_title"]))
|
||||
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
|
||||
content = ngettext(
|
||||
"[{author}]({author_url}) imported [{article}]({article_url}) with {count} revision from [{source}]({source_url}){comment}",
|
||||
"[{author}]({author_url}) imported [{article}]({article_url}) with {count} revisions from [{source}]({source_url}){comment}",
|
||||
change["logparams"]["count"]).format(
|
||||
author=author, author_url=author_url, article=sanitize_to_markdown(change["title"]), article_url=link,
|
||||
count=change["logparams"]["count"], source=sanitize_to_markdown(change["logparams"]["interwiki_title"]), source_url=source_link,
|
||||
comment=parsed_comment)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||
|
||||
# rights/rights - Assigning rights groups
|
||||
def get_changed_groups(change: dict, separator: str):
|
||||
"""Creates strings comparing the changes between the user groups for the user"""
|
||||
old_groups = {_(x) for x in change["logparams"]["oldgroups"]} # translate all groups and pull them into a set
|
||||
new_groups = {_(x) for x in change["logparams"]["newgroups"]}
|
||||
added = separator.join(["+ " + x for x in new_groups-old_groups]) # add + before every string and join them with separator
|
||||
removed = separator.join(["- " + x for x in old_groups-new_groups])
|
||||
return added, removed
|
||||
|
||||
@formatter.embed(event="rights/rights", mode="embed")
|
||||
def embed_rights_rights(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("User:{}".format(change["title"].split(":")[1])))
|
||||
if ctx.event == "rights/rights":
|
||||
embed["title"] = _("Changed group membership for {target}").format(target=change["title"].split(":")[1])
|
||||
else:
|
||||
author_url = ""
|
||||
embed.set_author(_("System"), author_url)
|
||||
embed["title"] = _("{target} got autopromoted to a new usergroup").format(
|
||||
target=change["title"].split(":")[1])
|
||||
# if len(change["logparams"]["oldgroups"]) < len(change["logparams"]["newgroups"]):
|
||||
# embed["thumbnail"]["url"] = "https://i.imgur.com/WnGhF5g.gif"
|
||||
added, removed = get_changed_groups(change, "\n")
|
||||
reason = ": {desc}".format(desc=ctx.parsedcomment) if change.get("parsedcomment", None) else ""
|
||||
embed["description"] = _("{reason}\n{added}{linebreak}{removed}").format(added=added, removed=removed, reason=reason,
|
||||
linebreak="\n" if added else "")
|
||||
return embed
|
||||
|
||||
@formatter.compact(event="rights/rights")
|
||||
def compact_rights_rights(ctx, change):
|
||||
link = clean_link(create_article_path(sanitize_to_url("User:{user}".format(user=change["title"].split(":")[1]))))
|
||||
added, removed = get_changed_groups(change, ", ")
|
||||
author, author_url = compact_author(ctx, change)
|
||||
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
|
||||
if ctx.event == "rights/rights":
|
||||
content = _(
|
||||
"[{author}]({author_url}) changed group membership for [{target}]({target_url}) {added} {removed}{comment}").format(
|
||||
author=author, author_url=author_url, target=change["title"].split(":")[1], target_url=link,
|
||||
added=added, removed=removed, comment=parsed_comment)
|
||||
else:
|
||||
content = _("{author} autopromoted [{target}]({target_url}) {added} {removed}{comment}").format(
|
||||
author=_("System"), author_url=author_url, target=change["title"].split(":")[1], target_url=link,
|
||||
added=added, removed=removed, comment=parsed_comment)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||
|
|
|
@ -237,25 +237,7 @@ def compact_formatter(action, change, parsed_comment, categories, recent_changes
|
|||
field=profile_field_name(change["logparams"]['4:section'], False),
|
||||
desc=BeautifulSoup(change["parsedcomment"], "lxml").get_text())
|
||||
elif action in ("rights/rights", "rights/autopromote"):
|
||||
link = link_formatter(create_article_path("User:{user}".format(user=change["title"].split(":")[1])))
|
||||
old_groups = []
|
||||
new_groups = []
|
||||
for name in change["logparams"]["oldgroups"]:
|
||||
old_groups.append(_(name))
|
||||
for name in change["logparams"]["newgroups"]:
|
||||
new_groups.append(_(name))
|
||||
if len(old_groups) == 0:
|
||||
old_groups = [_("none")]
|
||||
if len(new_groups) == 0:
|
||||
new_groups = [_("none")]
|
||||
|
||||
if action == "rights/rights":
|
||||
content = _("[{author}]({author_url}) changed group membership for [{target}]({target_url}) from {old_groups} to {new_groups}{comment}").format(author=author, author_url=author_url, target=change["title"].split(":")[1], target_url=link, old_groups=", ".join(old_groups), new_groups=', '.join(new_groups), comment=parsed_comment)
|
||||
else:
|
||||
content = _("{author} autopromoted [{target}]({target_url}) from {old_groups} to {new_groups}{comment}").format(
|
||||
author=_("System"), author_url=author_url, target=change["title"].split(":")[1], target_url=link,
|
||||
old_groups=", ".join(old_groups), new_groups=', '.join(new_groups),
|
||||
comment=parsed_comment)
|
||||
elif action == "protect/protect":
|
||||
|
||||
elif action == "protect/modify":
|
||||
|
@ -263,34 +245,15 @@ def compact_formatter(action, change, parsed_comment, categories, recent_changes
|
|||
elif action == "protect/unprotect":
|
||||
|
||||
elif action == "delete/revision":
|
||||
amount = len(change["logparams"]["ids"])
|
||||
link = link_formatter(create_article_path(change["title"]))
|
||||
content = ngettext("[{author}]({author_url}) changed visibility of revision on page [{article}]({article_url}){comment}",
|
||||
"[{author}]({author_url}) changed visibility of {amount} revisions on page [{article}]({article_url}){comment}", amount).format(author=author, author_url=author_url,
|
||||
article=change["title"], article_url=link, amount=amount, comment=parsed_comment)
|
||||
if AUTO_SUPPRESSION_ENABLED:
|
||||
try:
|
||||
logparams = change["logparams"]
|
||||
pageid = change["pageid"]
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
delete_messages(dict(pageid=pageid))
|
||||
|
||||
elif action == "import/upload":
|
||||
link = link_formatter(create_article_path(change["title"]))
|
||||
content = ngettext("[{author}]({author_url}) imported [{article}]({article_url}) with {count} revision{comment}",
|
||||
"[{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)
|
||||
|
||||
elif action == "delete/restore":
|
||||
|
||||
elif action == "delete/event":
|
||||
|
||||
elif action == "import/interwiki":
|
||||
link = link_formatter(create_article_path(change["title"]))
|
||||
source_link = link_formatter(create_article_path(change["logparams"]["interwiki_title"]))
|
||||
content = ngettext("[{author}]({author_url}) imported [{article}]({article_url}) with {count} revision from [{source}]({source_url}){comment}",
|
||||
"[{author}]({author_url}) imported [{article}]({article_url}) with {count} revisions from [{source}]({source_url}){comment}", change["logparams"]["count"]).format(
|
||||
author=author, author_url=author_url, article=change["title"], article_url=link, count=change["logparams"]["count"], source=change["logparams"]["interwiki_title"], source_url=source_link, comment=parsed_comment)
|
||||
|
||||
elif action == "abusefilter/modify":
|
||||
link = link_formatter(create_article_path("Special:AbuseFilter/history/{number}/diff/prev/{historyid}".format(number=change["logparams"]['newId'], historyid=change["logparams"]["historyId"])))
|
||||
content = _("[{author}]({author_url}) edited abuse filter [number {number}]({filter_url})").format(author=author, author_url=author_url, number=change["logparams"]['newId'], filter_url=link)
|
||||
|
@ -702,29 +665,7 @@ def embed_formatter(action, change, parsed_comment, categories, recent_changes):
|
|||
else:
|
||||
embed["title"] = _("Deleted a comment on their own profile")
|
||||
elif action in ("rights/rights", "rights/autopromote"):
|
||||
link = create_article_path("User:{}".format(change["title"].split(":")[1]))
|
||||
if action == "rights/rights":
|
||||
embed["title"] = _("Changed group membership for {target}").format(target=change["title"].split(":")[1])
|
||||
else:
|
||||
author_url = ""
|
||||
embed.set_author(_("System"), author_url)
|
||||
embed["title"] = _("{target} got autopromoted to a new usergroup").format(
|
||||
target=change["title"].split(":")[1])
|
||||
if len(change["logparams"]["oldgroups"]) < len(change["logparams"]["newgroups"]):
|
||||
embed["thumbnail"]["url"] = "https://i.imgur.com/WnGhF5g.gif"
|
||||
old_groups = []
|
||||
new_groups = []
|
||||
for name in change["logparams"]["oldgroups"]:
|
||||
old_groups.append(_(name))
|
||||
for name in change["logparams"]["newgroups"]:
|
||||
new_groups.append(_(name))
|
||||
if len(old_groups) == 0:
|
||||
old_groups = [_("none")]
|
||||
if len(new_groups) == 0:
|
||||
new_groups = [_("none")]
|
||||
reason = ": {desc}".format(desc=parsed_comment) if parsed_comment != _("No description provided") else ""
|
||||
parsed_comment = _("Groups changed from {old_groups} to {new_groups}{reason}").format(
|
||||
old_groups=", ".join(old_groups), new_groups=', '.join(new_groups), reason=reason)
|
||||
|
||||
elif action == "protect/protect":
|
||||
|
||||
elif action == "protect/modify":
|
||||
|
@ -732,32 +673,15 @@ def embed_formatter(action, change, parsed_comment, categories, recent_changes):
|
|||
elif action == "protect/unprotect":
|
||||
|
||||
elif action == "delete/revision":
|
||||
amount = len(change["logparams"]["ids"])
|
||||
link = create_article_path(change["title"])
|
||||
embed["title"] = ngettext("Changed visibility of revision on page {article} ",
|
||||
"Changed visibility of {amount} revisions on page {article} ", amount).format(
|
||||
article=change["title"], amount=amount)
|
||||
if AUTO_SUPPRESSION_ENABLED:
|
||||
try:
|
||||
logparams = change["logparams"]
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
redact_messages(logparams.get("ids", []), 0, logparams.get("new", {}))
|
||||
|
||||
elif action == "import/upload":
|
||||
link = create_article_path(change["title"])
|
||||
embed["title"] = ngettext("Imported {article} with {count} revision",
|
||||
"Imported {article} with {count} revisions", change["logparams"]["count"]).format(
|
||||
article=change["title"], count=change["logparams"]["count"])
|
||||
|
||||
elif action == "delete/restore":
|
||||
|
||||
elif action == "delete/event":
|
||||
|
||||
elif action == "import/interwiki":
|
||||
link = create_article_path(change["title"])
|
||||
embed["title"] = ngettext("Imported {article} with {count} revision from \"{source}\"",
|
||||
"Imported {article} with {count} revisions from \"{source}\"", change["logparams"]["count"]).format(
|
||||
article=change["title"], count=change["logparams"]["count"], source=change["logparams"]["interwiki_title"])
|
||||
|
||||
elif action == "abusefilter/modify":
|
||||
link = create_article_path("Special:AbuseFilter/history/{number}/diff/prev/{historyid}".format(number=change["logparams"]['newId'], historyid=change["logparams"]["historyId"]))
|
||||
embed["title"] = _("Edited abuse filter number {number}").format(number=change["logparams"]['newId'])
|
||||
|
|
|
@ -272,12 +272,19 @@ def rc_processor(change, changed_categories):
|
|||
return
|
||||
context.event = identification_string
|
||||
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: # TODO Move it into a hook?
|
||||
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 logid in logparams.get("ids", []):
|
||||
delete_messages(dict(logid=logid))
|
||||
elif identification_string == "delete/revision" and AUTO_SUPPRESSION_ENABLED:
|
||||
logparams = change.get('logparams', {"ids": []})
|
||||
if settings["appearance"]["mode"] == "embed":
|
||||
redact_messages(logparams.get("ids", []), 0, logparams.get("new", {}))
|
||||
else:
|
||||
for revid in logparams.get("ids", []):
|
||||
delete_messages(dict(revid=revid))
|
||||
|
|
Loading…
Reference in a new issue