Task number 1 from #204

This commit is contained in:
Frisk 2021-05-16 16:22:18 +02:00
parent 6cfedcb5ee
commit 2430d50de4
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
5 changed files with 83 additions and 64 deletions

View file

@ -19,7 +19,7 @@ from src.discord.message import DiscordMessage
from src.api import formatter
from src.i18n import formatters_i18n
from src.api.context import Context
from src.api.util import embed_helper, compact_author, create_article_path, sanitize_to_markdown, sanitize_to_url
from src.api.util import embed_helper, compact_author, create_article_path, sanitize_to_markdown, sanitize_to_url, compact_summary
_ = formatters_i18n.gettext
ngettext = formatters_i18n.ngettext
@ -41,7 +41,7 @@ def embed_datadump_generate(ctx: Context, change: dict) -> DiscordMessage:
@formatter.compact(event="mdatadump/generate")
def compact_datadump_generate(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) generated *{file}* dump{comment}").format(
author=author, author_url=author_url, file=change["logparams"]["filename"],
comment=parsed_comment
@ -63,7 +63,7 @@ def embed_datadump_delete(ctx: Context, change: dict) -> DiscordMessage:
@formatter.compact(event="mdatadump/delete")
def compact_datadump_delete(ctx: Context, change: dict) -> DiscordMessage:
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) deleted *{file}* dump{comment}").format(
author=author, author_url=author_url, file=change["logparams"]["filename"],
comment=parsed_comment

View file

@ -18,7 +18,7 @@ from src.discord.message import DiscordMessage
from src.api import formatter
from src.i18n import formatters_i18n
from src.api.context import Context
from src.api.util import embed_helper, compact_author, create_article_path, sanitize_to_markdown, sanitize_to_url
from src.api.util import embed_helper, compact_author, create_article_path, sanitize_to_markdown, sanitize_to_url, compact_summary
_ = formatters_i18n.gettext
ngettext = formatters_i18n.ngettext
@ -41,7 +41,7 @@ def embed_managewiki_settings(ctx: Context, change: dict):
@formatter.compact(event="managewiki/settings")
def compact_managewiki_settings(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) changed wiki settings{reason}".format(author=author, author_url=author_url, reason=parsed_comment))
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -60,7 +60,7 @@ def embed_managewiki_delete(ctx: Context, change: dict):
@formatter.compact(event="managewiki/delete")
def compact_managewiki_delete(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) deleted a wiki *{wiki_name}*{comment}").format(author=author,
author_url=author_url,
wiki_name=change[
@ -84,7 +84,7 @@ def embed_managewiki_lock(ctx: Context, change: dict):
@formatter.compact(event="managewiki/lock")
def compact_managewiki_lock(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) locked a wiki *{wiki_name}*{comment}").format(
author=author, author_url=author_url, wiki_name=change["logparams"].get("wiki", _("Unknown")),
comment=parsed_comment)
@ -107,7 +107,7 @@ def embed_managewiki_namespaces(ctx: Context, change: dict):
@formatter.compact(event="managewiki/namespaces")
def compact_managewiki_namespaces(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) modified namespace *{namespace_name}* on *{wiki_name}*{comment}").format(
author=author, author_url=author_url, namespace_name=change["logparams"].get("namespace", _("Unknown")),
wiki_name=change["logparams"].get("wiki", _("Unknown")), comment=parsed_comment)
@ -130,7 +130,7 @@ def embed_managewiki_namespaces_delete(ctx: Context, change: dict):
@formatter.compact(event="managewiki/namespaces-delete")
def compact_managewiki_namespaces_delete(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _(
"[{author}]({author_url}) deleted a namespace *{namespace_name}* on *{wiki_name}*{comment}").format(
author=author, author_url=author_url,
@ -154,7 +154,7 @@ def embed_managewiki_rights(ctx: Context, change: dict):
@formatter.compact(event="managewiki/rights")
def compact_managewiki_rights(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
group_name = change["title"].split("/permissions/", 1)[1]
content = _("[{author}]({author_url}) modified user group *{group_name}*{comment}").format(
author=author, author_url=author_url, group_name=group_name, comment=parsed_comment
@ -176,7 +176,7 @@ def embed_managewiki_undelete(ctx: Context, change: dict):
@formatter.compact(event="managewiki/undelete")
def compact_managewiki_undelete(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) undeleted a wiki *{wiki_name}*{comment}").format(
author=author, author_url=author_url, wiki_name=change["logparams"].get("wiki", _("Unknown")),
comment=parsed_comment
@ -198,7 +198,7 @@ def embed_managewiki_unlock(ctx: Context, change: dict):
@formatter.compact(event="managewiki/unlock")
def compact_managewiki_unlock(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) unlocked a wiki *{wiki_name}*{comment}").format(
author=author, author_url=author_url, wiki_name=change["logparams"].get("wiki", _("Unknown")),
comment=parsed_comment

View file

@ -24,7 +24,7 @@ from src.api import formatter
from src.i18n import formatters_i18n
from src.api.context import Context
from src.api.util import embed_helper, sanitize_to_url, parse_mediawiki_changes, clean_link, compact_author, \
create_article_path, sanitize_to_markdown
create_article_path, sanitize_to_markdown, compact_summary
from src.configloader import settings
from src.exceptions import *
@ -93,7 +93,7 @@ def embed_edit(ctx: Context, change: dict) -> DiscordMessage:
@formatter.compact(event="edit", mode="compact", aliases=["new"])
def compact_edit(ctx: Context, change: dict) -> DiscordMessage:
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
author, author_url = compact_author(ctx, change)
action = ctx.event
edit_link = clean_link("{wiki}index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format(
@ -233,7 +233,7 @@ def embed_upload_upload(ctx, change) -> DiscordMessage:
def compact_upload_revert(ctx, change) -> DiscordMessage:
author, author_url = compact_author(ctx, change)
file_link = clean_link(create_article_path(sanitize_to_url(change["title"])))
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) reverted a version of [{file}]({file_link}){comment}").format(
author=author, author_url=author_url, file=sanitize_to_markdown(change["title"]), file_link=file_link,
comment=parsed_comment)
@ -244,7 +244,7 @@ def compact_upload_revert(ctx, change) -> DiscordMessage:
def compact_upload_overwrite(ctx, change) -> DiscordMessage:
author, author_url = compact_author(ctx, change)
file_link = clean_link(create_article_path(sanitize_to_url(change["title"])))
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) uploaded a new version of [{file}]({file_link}){comment}").format(
author=author, author_url=author_url, file=sanitize_to_markdown(change["title"]), file_link=file_link,
comment=parsed_comment)
@ -255,7 +255,7 @@ def compact_upload_overwrite(ctx, change) -> DiscordMessage:
def compact_upload_upload(ctx, change) -> DiscordMessage:
author, author_url = compact_author(ctx, change)
file_link = clean_link(create_article_path(sanitize_to_url(change["title"])))
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) uploaded [{file}]({file_link}){comment}").format(author=author,
author_url=author_url,
file=sanitize_to_markdown(
@ -277,7 +277,7 @@ def embed_delete_delete(ctx, change) -> DiscordMessage:
@formatter.compact(event="delete/delete", mode="compact")
def compact_delete_delete(ctx, change) -> DiscordMessage:
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
author, author_url = compact_author(ctx, change)
page_link = clean_link(create_article_path(sanitize_to_url(change["title"])))
content = _("[{author}]({author_url}) deleted [{page}]({page_link}){comment}").format(author=author,
@ -304,7 +304,7 @@ def embed_delete_delete_redir(ctx, change) -> DiscordMessage:
def compact_delete_delete_redir(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 + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) deleted redirect by overwriting [{page}]({page_link}){comment}").format(
author=author, author_url=author_url, page=change["title"], page_link=page_link,
comment=parsed_comment)
@ -327,7 +327,7 @@ def embed_delete_restore(ctx, change) -> DiscordMessage:
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 + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) restored [{article}]({article_url}){comment}").format(author=author,
author_url=author_url,
article=sanitize_to_markdown(
@ -352,7 +352,7 @@ def embed_delete_event(ctx, change) -> DiscordMessage:
@formatter.compact(event="delete/event", mode="compact")
def compact_delete_event(ctx, change) -> DiscordMessage:
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) changed visibility of log events{comment}").format(author=author,
author_url=author_url,
comment=parsed_comment)
@ -378,7 +378,7 @@ 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 + ")*"
parsed_comment = compact_summary(ctx)
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}",
@ -413,10 +413,11 @@ def compact_move_move(ctx, change) -> DiscordMessage:
link = clean_link(create_article_path(sanitize_to_url(change["logparams"]['target_title'])))
redirect_status = _("without making a redirect") if "suppressredirect" in change["logparams"] else _(
"with a redirect")
parsed_comment = compact_summary(ctx)
content = _(
"[{author}]({author_url}) moved {redirect}*{article}* to [{target}]({target_url}) {made_a_redirect}{comment}").format(
author=author, author_url=author_url, redirect="" if "redirect" in change else "", article=change["title"],
target=sanitize_to_markdown(change["logparams"]['target_title']), target_url=link, comment=ctx.parsedcomment,
target=sanitize_to_markdown(change["logparams"]['target_title']), target_url=link, comment=parsed_comment,
made_a_redirect=redirect_status)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -446,11 +447,12 @@ def compact_move_move_redir(ctx, change) -> DiscordMessage:
link = clean_link(create_article_path(sanitize_to_url(change["logparams"]['target_title'])))
redirect_status = _("without making a redirect") if "suppressredirect" in change["logparams"] else _(
"with a redirect")
parsed_comment = compact_summary(ctx)
content = _(
"[{author}]({author_url}) moved {redirect}*{article}* over redirect to [{target}]({target_url}) {made_a_redirect}{comment}").format(
author=author, author_url=author_url, redirect="" if "redirect" in change else "",
article=sanitize_to_markdown(change["title"]),
target=sanitize_to_markdown(change["logparams"]['target_title']), target_url=link, comment=ctx.parsedcomment,
target=sanitize_to_markdown(change["logparams"]['target_title']), target_url=link, comment=parsed_comment,
made_a_redirect=redirect_status)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -474,11 +476,12 @@ def embed_protect_move_prot(ctx, change):
def compact_protect_move_prot(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path(sanitize_to_url(change["logparams"]["oldtitle_title"])))
parsed_comment = compact_summary(ctx)
content = _(
"[{author}]({author_url}) moved protection settings from {redirect}*{article}* to [{target}]({target_url}){comment}").format(
author=author, author_url=author_url, redirect="" if "redirect" in change else "",
article=sanitize_to_markdown(change["logparams"]["oldtitle_title"]),
target=sanitize_to_markdown(change["title"]), target_url=link, comment=ctx.parsedcomment)
target=sanitize_to_markdown(change["title"]), target_url=link, comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -502,13 +505,14 @@ def embed_protect_protect(ctx, change):
def compact_protect_protect(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
parsed_comment = compact_summary(ctx)
content = _(
"[{author}]({author_url}) protected [{article}]({article_url}) with the following settings: {settings}{comment}").format(
author=author, author_url=author_url,
article=sanitize_to_markdown(change["title"]), article_url=link,
settings=change["logparams"].get("description", "") + (
_(" [cascading]") if "cascade" in change["logparams"] else ""),
comment=ctx.parsedcomment)
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -533,13 +537,14 @@ def embed_protect_modify(ctx, change):
def compact_protect_modify(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
parsed_comment = compact_summary(ctx)
content = _(
"[{author}]({author_url}) modified protection settings of [{article}]({article_url}) to: {settings}{comment}").format(
author=author, author_url=author_url,
article=sanitize_to_markdown(change["title"]), article_url=link,
settings=sanitize_to_markdown(change["logparams"].get("description", "")) + (
_(" [cascading]") if "cascade" in change["logparams"] else ""),
comment=ctx.parsedcomment)
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -559,9 +564,10 @@ def embed_protect_unprotect(ctx, change):
def compact_protect_unprotect(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) removed protection from [{article}]({article_url}){comment}").format(
author=author, author_url=author_url, article=sanitize_to_markdown(change["title"]), article_url=link,
comment=ctx.parsedcomment)
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -640,6 +646,7 @@ def compact_block_block(ctx, change):
user = change["title"].split(':', 1)[1]
restriction_description = ""
author, author_url = compact_author(ctx, change)
parsed_comment = compact_summary(ctx)
try:
ipaddress.ip_address(user)
link = clean_link(create_article_path("Special:Contributions/{user}".format(user=user)))
@ -678,7 +685,7 @@ def compact_block_block(ctx, change):
change),
user_url=link,
restriction_desc=restriction_description,
comment=ctx.parsedcomment)
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -698,8 +705,9 @@ def compact_block_reblock(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]
parsed_comment = compact_summary(ctx)
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=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -720,11 +728,12 @@ 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]
parsed_comment = compact_summary(ctx)
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)
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -764,7 +773,7 @@ def embed_import_upload(ctx, change):
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 + ")*"
parsed_comment = compact_summary(ctx)
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(
@ -794,7 +803,7 @@ 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 + ")*"
parsed_comment = compact_summary(ctx)
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}",
@ -844,7 +853,7 @@ 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 + ")*"
parsed_comment = compact_summary(ctx)
if ctx.event == "rights/rights":
content = _(
"[{author}]({author_url}) changed group membership for [{target}]({target_url}) {added} {removed}{comment}").format(
@ -874,7 +883,7 @@ def embed_merge_merge(ctx, change):
@formatter.compact(event="merge/merge")
def compact_merge_merge(ctx, change):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
link_dest = clean_link(create_article_path(sanitize_to_url(change["logparams"]["dest_title"])))
content = _(
@ -938,7 +947,7 @@ def embed_newusers_create2(ctx, change):
@formatter.compact(event="newusers/create2")
def compact_newusers_create2(ctx, change):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
content = _("Account [{article}]({article_url}) was created by [{author}]({author_url}){comment}").format(
article=change["title"], article_url=link, author=author, author_url=author_url, comment=parsed_comment)
@ -961,7 +970,7 @@ def embed_newusers_byemail(ctx, change):
@formatter.compact(event="newusers/byemail")
def compact_newusers_byemail(ctx, change):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
content = _(
"Account [{article}]({article_url}) was created by [{author}]({author_url}) and password was sent by email{comment}").format(
@ -1007,7 +1016,7 @@ def embed_interwiki_iw_add(ctx, change):
def compact_interwiki_iw_add(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path("Special:Interwiki"))
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _(
"[{author}]({author_url}) added an entry to the [interwiki table]({table_url}) pointing to {website} with {prefix} prefix").format(
author=author, author_url=author_url, desc=parsed_comment, prefix=change["logparams"]['0'],
@ -1034,7 +1043,7 @@ def embed_interwiki_iw_edit(ctx, change):
def compact_interwiki_iw_edit(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path("Special:Interwiki"))
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _(
"[{author}]({author_url}) edited an entry in [interwiki table]({table_url}) pointing to {website} with {prefix} prefix").format(
author=author, author_url=author_url, desc=parsed_comment, prefix=change["logparams"]['0'],
@ -1060,7 +1069,7 @@ def embed_interwiki_iw_delete(ctx, change):
def compact_interwiki_iw_delete(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path("Special:Interwiki"))
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) deleted an entry in [interwiki table]({table_url}){desc}").format(
author=author,
author_url=author_url,
@ -1090,7 +1099,7 @@ def embed_contentmodel_change(ctx, change):
def compact_contentmodel_change(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _(
"[{author}]({author_url}) changed the content model of the page [{article}]({article_url}) from {old} to {new}{comment}").format(
author=author, author_url=author_url, article=sanitize_to_markdown(change["title"]), article_url=link,
@ -1118,7 +1127,7 @@ def embed_contentmodel_new(ctx, change):
def compact_contentmodel_new(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _(
"[{author}]({author_url}) created the page [{article}]({article_url}) using a non-default content model {new}{comment}").format(
author=author, author_url=author_url, article=sanitize_to_markdown(change["title"]), article_url=link,
@ -1144,6 +1153,7 @@ def compact_managetags_create(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
ctx.client.refresh_internal_data()
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) created the [tag]({tag_url}) \"{tag}\"{comment}").format(author=author,
author_url=author_url,
tag=
@ -1152,7 +1162,7 @@ def compact_managetags_create(ctx, change):
"logparams"][
"tag"]),
tag_url=link,
comment=ctx.parsedcomment)
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -1178,6 +1188,7 @@ def compact_managetags_delete(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
ctx.client.refresh_internal_data()
parsed_comment = compact_summary(ctx)
if change["logparams"]["count"] == 0:
content = _("[{author}]({author_url}) deleted the [tag]({tag_url}) \"{tag}\"{comment}").format(author=author,
author_url=author_url,
@ -1186,7 +1197,7 @@ def compact_managetags_delete(ctx, change):
"logparams"][
"tag"]),
tag_url=link,
comment=ctx.parsedcomment)
comment=parsed_comment)
else:
content = ngettext(
"[{author}]({author_url}) deleted the [tag]({tag_url}) \"{tag}\" and removed it from {count} revision or log entry{comment}",
@ -1194,7 +1205,7 @@ def compact_managetags_delete(ctx, change):
change["logparams"]["count"]).format(author=author, author_url=author_url,
tag=sanitize_to_markdown(change["logparams"]["tag"]),
tag_url=link, count=change["logparams"]["count"],
comment=ctx.parsedcomment)
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -1214,6 +1225,7 @@ def embed_managetags_activate(ctx, change):
def compact_managetags_activate(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) activated the [tag]({tag_url}) \"{tag}\"{comment}").format(author=author,
author_url=author_url,
tag=sanitize_to_markdown(
@ -1221,7 +1233,7 @@ def compact_managetags_activate(ctx, change):
"logparams"][
"tag"]),
tag_url=link,
comment=ctx.parsedcomment)
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -1241,6 +1253,7 @@ def embed_managetags_deactivate(ctx, change):
def compact_managetags_deactivate(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) deactivated the [tag]({tag_url}) \"{tag}\"{comment}").format(author=author,
author_url=author_url,
tag=sanitize_to_markdown(
@ -1248,7 +1261,7 @@ def compact_managetags_deactivate(ctx, change):
"logparams"][
"tag"]),
tag_url=link,
comment=ctx.parsedcomment)
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -1278,7 +1291,7 @@ def compact_renameuser_renameuser(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path("User:" + sanitize_to_url(change["logparams"]["newuser"])))
edits = change["logparams"]["edits"]
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
if edits > 0:
content = ngettext(
"[{author}]({author_url}) renamed user *{old_name}* with {edits} edit to [{new_name}]({link}){comment}",

View file

@ -19,7 +19,7 @@ from src.api import formatter
from src.i18n import formatters_i18n
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
clean_link, compact_summary
_ = formatters_i18n.gettext
ngettext = formatters_i18n.ngettext
@ -51,7 +51,7 @@ def compact_pagetranslation_mark(ctx: Context, change: dict):
else:
link = link + "?oldid={}".format(change["logparams"]["revision"])
link = clean_link(link)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
content = _("[{author}]({author_url}) marked [{article}]({article_url}) for translation{comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
@ -74,7 +74,7 @@ def embed_pagetranslation_unmark(ctx: Context, change: dict):
@formatter.compact(event="pagetranslation/unmark")
def compact_pagetranslation_unmark(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
content = _(
"[{author}]({author_url}) removed [{article}]({article_url}) from the translation system{comment}").format(
@ -100,7 +100,7 @@ def embed_pagetranslation_moveok(ctx: Context, change: dict):
@formatter.compact(event="pagetranslation/moveok")
def compact_pagetranslation_moveok(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["logparams"]["target"])))
content = _(
"[{author}]({author_url}) completed moving translation pages from *{article}* to [{target}]({target_url}){comment}").format(
@ -126,7 +126,7 @@ def embed_pagetranslation_movenok(ctx: Context, change: dict):
@formatter.compact(event="pagetranslation/movenok")
def compact_pagetranslation_movenok(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
target_url = clean_link(create_article_path(sanitize_to_url(change["logparams"]["target"])))
content = _(
@ -154,7 +154,7 @@ def embed_pagetranslation_deletefnok(ctx: Context, change: dict):
@formatter.compact(event="pagetranslation/deletefnok")
def compact_pagetranslation_deletefnok(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
target_url = clean_link(create_article_path(sanitize_to_url(change["logparams"]["target"])))
content = _(
@ -182,7 +182,7 @@ def embed_pagetranslation_deletelok(ctx: Context, change: dict):
@formatter.compact(event="pagetranslation/deletelok")
def compact_pagetranslation_deletelok(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
content = _(
"[{author}]({author_url}) completed deletion of translation page [{article}]({article_url}){comment}").format(
@ -208,7 +208,7 @@ def embed_pagetranslation_deletelnok(ctx: Context, change: dict):
@formatter.compact(event="pagetranslation/deletelnok")
def compact_pagetranslation_deletelnok(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
target_url = clean_link(create_article_path(sanitize_to_url(change["logparams"]["target"])))
content = _(
@ -235,7 +235,7 @@ def embed_pagetranslation_encourage(ctx: Context, change: dict):
@formatter.compact(event="pagetranslation/encourage")
def compact_pagetranslation_encourage(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
content = _("[{author}]({author_url}) encouraged translation of [{article}]({article_url}){comment}").format(
author=author, author_url=author_url,
@ -259,7 +259,7 @@ def embed_pagetranslation_discourage(ctx: Context, change: dict):
@formatter.compact(event="pagetranslation/discourage")
def compact_pagetranslation_discourage(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
content = _("[{author}]({author_url}) discouraged translation of [{article}]({article_url}){comment}").format(
author=author, author_url=author_url,
@ -292,7 +292,7 @@ def embed_pagetranslation_prioritylanguages(ctx: Context, change: dict):
@formatter.compact(event="pagetranslation/prioritylanguages")
def compact_pagetranslation_prioritylanguages(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
if "languages" in change["logparams"]:
languages = "`, `".join(change["logparams"]["languages"].split(","))
@ -336,7 +336,7 @@ def embed_pagetranslation_associate(ctx: Context, change: dict):
@formatter.compact(event="pagetranslation/associate")
def compact_pagetranslation_associate(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
content = _(
"[{author}]({author_url}) added translatable page [{article}]({article_url}) to aggregate group \"{group}\"{comment}").format(
@ -362,7 +362,7 @@ def embed_pagetranslation_dissociate(ctx: Context, change: dict):
@formatter.compact(event="pagetranslation/dissociate")
def compact_pagetranslation_dissociate(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
content = _(
"[{author}]({author_url}) removed translatable page [{article}]({article_url}) from aggregate group \"{group}\"{comment}").format(
@ -391,7 +391,7 @@ def embed_translationreview_message(ctx: Context, change: dict):
@formatter.compact(event="translationreview/message")
def compact_translationreview_message(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = create_article_path(sanitize_to_url(change["title"]))
if "?" in link:
link = link + "&oldid={}".format(change["logparams"]["revision"])
@ -424,7 +424,7 @@ def embed_translationreview_group(ctx: Context, change: dict):
@formatter.compact(event="translationreview/group")
def compact_translationreview_group(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
if "old-state" in change["logparams"]:
content = _(
@ -470,7 +470,7 @@ def embed_pagelang_pagelang(ctx: Context, change: dict):
@formatter.compact(event="pagelang/pagelang")
def compact_pagelang_pagelang(ctx: Context, change: dict):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
parsed_comment = compact_summary(ctx)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
old_lang, new_lang = get_languages(change)
content = _(

View file

@ -78,6 +78,12 @@ def create_article_path(article: str) -> str:
return src.misc.WIKI_ARTICLE_PATH.replace("$1", article)
def compact_summary(ctx: Context) -> str:
"""Creates a comment for compact formatters"""
if ctx.parsedcomment:
return " *({})*".format(ctx.parsedcomment)
return ""
def compact_author(ctx: Context, change: dict) -> (Optional[str], Optional[str]):
"""Returns link to the author and the author itself respecting the settings"""
author, author_url = None, None