Small fixes and whitespace changes

This commit is contained in:
Frisk 2021-05-08 13:32:31 +02:00
parent 0083fbf4f6
commit 8deb702fc8
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC

View file

@ -37,6 +37,7 @@ if 1 == 2: # additional translation strings in unreachable code
print(_("director"), _("bot"), _("editor"), _("directors"), _("sysop"), _("bureaucrat"), _("reviewer"),
_("autoreview"), _("autopatrol"), _("wiki_guardian"))
# Page edit - event edit, New - page creation
@ -143,7 +144,9 @@ def embed_upload_upload(ctx, change) -> DiscordMessage:
params["iilimit"] = "5"
request_for_image_data = ctx.client.make_api_request(params, "query", "pages")
except (ServerError, MediaWikiError):
logger.exception("Couldn't retrieve more information about the image {} because of server/MediaWiki error".format(change["title"]))
logger.exception(
"Couldn't retrieve more information about the image {} because of server/MediaWiki error".format(
change["title"]))
except (ClientError, BadRequest):
raise
except KeyError:
@ -156,15 +159,17 @@ def embed_upload_upload(ctx, change) -> DiscordMessage:
else:
logger.warning("Request for additional image information have failed. The preview will not be shown.")
request_for_image_data = None
link = create_article_path(sanitize_to_url(change["title"]))
embed["url"] = create_article_path(sanitize_to_url(change["title"]))
image_direct_url = None
# Make a request for file revisions so we can get direct URL to the image for embed
if request_for_image_data is not None:
try:
urls = image_data["imageinfo"]
for num, revision in enumerate(urls):
if revision["timestamp"] == change["logparams"]["img_timestamp"]: # find the correct revision corresponding for this log entry
image_direct_url = "{rev}?{cache}".format(rev=revision["url"], cache=int(time.time() * 5)) # cachebusting
if revision["timestamp"] == change["logparams"][
"img_timestamp"]: # find the correct revision corresponding for this log entry
image_direct_url = "{rev}?{cache}".format(rev=revision["url"],
cache=int(time.time() * 5)) # cachebusting
break
except KeyError:
logger.exception(
@ -181,7 +186,8 @@ def embed_upload_upload(ctx, change) -> DiscordMessage:
image_data["imageinfo"]))
else:
undolink = "{wiki}index.php?title={filename}&action=revert&oldimage={archiveid}".format(
wiki=ctx.client.WIKI_SCRIPT_PATH, filename=sanitize_to_url(change["title"]), archiveid=revision["archivename"])
wiki=ctx.client.WIKI_SCRIPT_PATH, filename=sanitize_to_url(change["title"]),
archiveid=revision["archivename"])
embed.add_field(_("Options"), _("([preview]({link}) | [undo]({undolink}))").format(
link=image_direct_url, undolink=undolink))
if settings["appearance"]["embed"]["embed_images"]:
@ -212,7 +218,8 @@ def embed_upload_upload(ctx, change) -> DiscordMessage:
"Given regex for the license detection is incorrect. Please fix license_regex or license_regex_detect values in the config!")
license = "?"
except KeyError:
logger.exception("Unknown error when retriefing the image data for a license, full content: {}".format(image_data))
logger.exception(
"Unknown error when retriefing the image data for a license, full content: {}".format(image_data))
if license is not None:
embed["description"] += _("\nLicense: {}").format(license)
if image_direct_url:
@ -228,7 +235,8 @@ def compact_upload_revert(ctx, change) -> DiscordMessage:
file_link = clean_link(create_article_path(sanitize_to_url(change["title"])))
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
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)
author=author, author_url=author_url, file=sanitize_to_markdown(change["title"]), file_link=file_link,
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -237,7 +245,9 @@ 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 + ")*"
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)
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)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -248,7 +258,8 @@ def compact_upload_upload(ctx, change) -> DiscordMessage:
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
content = _("[{author}]({author_url}) uploaded [{file}]({file_link}){comment}").format(author=author,
author_url=author_url,
file=sanitize_to_markdown(change["title"]),
file=sanitize_to_markdown(
change["title"]),
file_link=file_link,
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -271,7 +282,8 @@ def compact_delete_delete(ctx, change) -> DiscordMessage:
page_link = clean_link(create_article_path(sanitize_to_url(change["title"])))
content = _("[{author}]({author_url}) deleted [{page}]({page_link}){comment}").format(author=author,
author_url=author_url,
page=sanitize_to_markdown(change["title"]),
page=sanitize_to_markdown(
change["title"]),
page_link=page_link,
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
@ -283,7 +295,8 @@ def embed_delete_delete_redir(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"] = _("Deleted redirect {article} by overwriting").format(article=sanitize_to_markdown(change["title"]))
embed["title"] = _("Deleted redirect {article} by overwriting").format(
article=sanitize_to_markdown(change["title"]))
return embed
@ -297,6 +310,7 @@ def compact_delete_delete_redir(ctx, change) -> DiscordMessage:
comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# delete/restore - Restoring a page
@ -316,11 +330,13 @@ def compact_delete_restore(ctx, change) -> DiscordMessage:
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=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
@ -335,13 +351,14 @@ def embed_delete_event(ctx, change) -> DiscordMessage:
@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)
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")
@ -369,6 +386,7 @@ def compact_delete_revision(ctx, change) -> DiscordMessage:
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
@ -378,12 +396,14 @@ def embed_move_move(ctx, change) -> DiscordMessage:
embed_helper(ctx, embed, change, set_desc=False)
embed["url"] = create_article_path(sanitize_to_url(change["logparams"]['target_title']))
embed["description"] = "{supress}. {desc}".format(desc=ctx.parsedcomment,
supress=_("No redirect has been made") if "suppressredirect" in change[
supress=_("No redirect has been made") if "suppressredirect" in
change[
"logparams"] else _(
"A redirect has been made"))
embed["title"] = _("Moved {redirect}{article} to {target}").format(redirect="" if "redirect" in change else "",
article=sanitize_to_markdown(change["title"]),
target=sanitize_to_markdown(change["logparams"]['target_title']))
target=sanitize_to_markdown(
change["logparams"]['target_title']))
return embed
@ -400,6 +420,7 @@ def compact_move_move(ctx, change) -> DiscordMessage:
made_a_redirect=redirect_status)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# move/move_redir - Move over redirect
@ -409,7 +430,8 @@ def embed_move_move_redir(ctx, change) -> DiscordMessage:
embed_helper(ctx, embed, change, set_desc=False)
embed["url"] = create_article_path(sanitize_to_url(change["logparams"]['target_title']))
embed["description"] = "{supress}. {desc}".format(desc=ctx.parsedcomment,
supress=_("No redirect has been made") if "suppressredirect" in change[
supress=_("No redirect has been made") if "suppressredirect" in
change[
"logparams"] else _(
"A redirect has been made"))
embed["title"] = _("Moved {redirect}{article} to {title} over redirect").format(
@ -426,11 +448,13 @@ def compact_move_move_redir(ctx, change) -> DiscordMessage:
"with a redirect")
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"]),
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,
made_a_redirect=redirect_status)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# protect/move_prot - Moving protection
@ -440,7 +464,8 @@ def embed_protect_move_prot(ctx, change):
embed_helper(ctx, embed, change)
embed["url"] = create_article_path(sanitize_to_url(change["logparams"]["oldtitle_title"]))
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"]))
return embed
@ -466,7 +491,8 @@ def embed_protect_protect(ctx, change):
embed_helper(ctx, embed, change, set_desc=False)
embed["url"] = create_article_path(sanitize_to_url(change["title"]))
embed["title"] = _("Protected {target}").format(target=sanitize_to_markdown(change["title"]))
embed["description"] = "{settings}{cascade} | {reason}".format(settings=sanitize_to_markdown(change["logparams"].get("description", "")),
embed["description"] = "{settings}{cascade} | {reason}".format(
settings=sanitize_to_markdown(change["logparams"].get("description", "")),
cascade=_(" [cascading]") if "cascade" in change["logparams"] else "",
reason=ctx.parsedcomment)
return embed
@ -485,6 +511,7 @@ def compact_protect_protect(ctx, change):
comment=ctx.parsedcomment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# protect/modify - Changing protection settings
@ -494,7 +521,8 @@ def embed_protect_modify(ctx, change):
embed_helper(ctx, embed, change, set_desc=False)
embed["url"] = create_article_path(sanitize_to_url(change["title"]))
embed["title"] = _("Changed protection level for {article}").format(article=sanitize_to_markdown(change["title"]))
embed["description"] = "{settings}{cascade} | {reason}".format(settings=sanitize_to_markdown(change["logparams"].get("description", "")),
embed["description"] = "{settings}{cascade} | {reason}".format(
settings=sanitize_to_markdown(change["logparams"].get("description", "")),
cascade=_(" [cascading]") if "cascade" in change[
"logparams"] else "",
reason=ctx.parsedcomment)
@ -514,6 +542,7 @@ def compact_protect_modify(ctx, change):
comment=ctx.parsedcomment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# protect/unprotect - Unprotecting a page
@ -531,9 +560,11 @@ def compact_protect_unprotect(ctx, change):
author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
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)
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)
# block/block - Blocking an user
def block_expiry(change: dict) -> str:
if change["logparams"]["duration"] in ["infinite", "indefinite", "infinity", "never"]:
@ -548,11 +579,14 @@ def block_expiry(change: dict) -> str:
timedelta_for_expiry.seconds % 86400 // 3600, timedelta_for_expiry.seconds % 3600 // 60
if not any([years, days, hours, minutes]):
return _("less than a minute")
time_names = (ngettext("year", "years", years), ngettext("day", "days", days), ngettext("hour", "hours", hours), ngettext("minute", "minutes", minutes))
time_names = (
ngettext("year", "years", years), ngettext("day", "days", days), ngettext("hour", "hours", hours),
ngettext("minute", "minutes", minutes))
final_time = []
for num, timev in enumerate([years, days, hours, minutes]):
if timev:
final_time.append(_("{time_unit} {time_number}").format(time_unit=time_names[num], time_number=timev))
final_time.append(
_("{time_unit} {time_number}").format(time_unit=time_names[num], time_number=timev))
return ", ".join(final_time)
else:
return change["logparams"]["duration"] # Temporary? Should be rare? We will see in testing
@ -573,10 +607,10 @@ def embed_block_block(ctx, change):
if "restrictions" in change["logparams"]:
if "pages" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"]["pages"]:
restriction_description = _("Blocked from editing the following pages: ")
for page in change["logparams"]["restrictions"]["pages"]:
restricted_pages = ["*"+i["page_title"]+"*" for i in change["logparams"]["restrictions"]["pages"]]
restricted_pages = ["*" + i["page_title"] + "*" for i in change["logparams"]["restrictions"]["pages"]]
restriction_description = restriction_description + ", ".join(restricted_pages)
if "namespaces" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"]["namespaces"]:
if "namespaces" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"][
"namespaces"]:
namespaces = []
if restriction_description:
restriction_description = restriction_description + _(" and namespaces: ")
@ -591,11 +625,12 @@ def embed_block_block(ctx, change):
restriction_description = restriction_description + "."
if len(restriction_description) > 1020:
logger.debug(restriction_description)
restriction_description = restriction_description[:1020]+""
restriction_description = restriction_description[:1020] + ""
embed.add_field(_("Partial block details"), restriction_description, inline=True)
block_flags = change["logparams"].get("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))
return embed
@ -615,7 +650,6 @@ def compact_block_block(ctx, change):
if "restrictions" in change["logparams"]:
if "pages" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"]["pages"]:
restriction_description = _(" on pages: ")
for page in change["logparams"]["restrictions"]["pages"]:
restricted_pages = ["*{page}*".format(page=i["page_title"]) for i in
change["logparams"]["restrictions"]["pages"]]
restriction_description = restriction_description + ", ".join(restricted_pages)
@ -640,7 +674,8 @@ def compact_block_block(ctx, change):
"[{author}]({author_url}) blocked [{user}]({user_url}) {time}{restriction_desc}{comment}").format(author=author,
author_url=author_url,
user=user,
time=block_expiry(change),
time=block_expiry(
change),
user_url=link,
restriction_desc=restriction_description,
comment=ctx.parsedcomment)
@ -693,6 +728,7 @@ def compact_block_unblock(ctx, change):
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
@ -736,6 +772,7 @@ def compact_import_upload(ctx, change):
count=change["logparams"]["count"], comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# import/interwiki - Importing interwiki entries
@ -747,7 +784,8 @@ def embed_import_interwiki(ctx, change):
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"]))
article=sanitize_to_markdown(change["title"]), count=change["logparams"]["count"],
source=sanitize_to_markdown(change["logparams"]["interwiki_title"]))
return embed
@ -762,17 +800,20 @@ def compact_import_interwiki(ctx, change):
"[{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,
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])
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
@ -792,7 +833,8 @@ def embed_rights_rights(ctx, change):
# 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,
embed["description"] = _("{reason}\n{added}{linebreak}{removed}").format(added=added, removed=removed,
reason=reason,
linebreak="\n" if added else "")
return embed
@ -814,6 +856,7 @@ def compact_rights_rights(ctx, change):
added=added, removed=removed, comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# merge/merge - Merging histories of two pages
@formatter.embed(event="merge/merge", mode="embed")
@ -821,7 +864,8 @@ def embed_merge_merge(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"] = _("Merged revision histories of {article} into {dest}").format(article=sanitize_to_markdown(change["title"]),
embed["title"] = _("Merged revision histories of {article} into {dest}").format(
article=sanitize_to_markdown(change["title"]),
dest=sanitize_to_markdown(change["logparams"][
"dest_title"]))
return embed
@ -839,6 +883,7 @@ def compact_merge_merge(ctx, change):
dest=change["logparams"]["dest_title"], comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# newusers/autocreate - Auto creation of user account
@ -854,9 +899,11 @@ def embed_newusers_autocreate(ctx, change):
@formatter.compact(event="newusers/autocreate")
def compact_newusers_autocreate(ctx, change):
author, author_url = compact_author(ctx, change)
content = _("Account [{author}]({author_url}) was created automatically").format(author=author, author_url=author_url)
content = _("Account [{author}]({author_url}) was created automatically").format(author=author,
author_url=author_url)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# newusers/create - Auto creation of user account
@ -875,8 +922,10 @@ def compact_newusers_create(ctx, change):
content = _("Account [{author}]({author_url}) was created").format(author=author, author_url=author_url)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# newusers/autocreate - Auto creation of user account
@formatter.embed(event="newusers/create2", mode="embed")
def embed_newusers_create2(ctx, change):
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
@ -885,14 +934,17 @@ def embed_newusers_create2(ctx, change):
embed["title"] = _("Created account {article}").format(article=change["title"])
return embed
@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 + ")*"
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)
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)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# newusers/byemail - Creation of account by email
@ -901,7 +953,8 @@ def embed_newusers_byemail(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"] = _("Created account {article} and password was sent by email").format(article=sanitize_to_markdown(change["title"]))
embed["title"] = _("Created account {article} and password was sent by email").format(
article=sanitize_to_markdown(change["title"]))
return embed
@ -910,9 +963,12 @@ def compact_newusers_byemail(ctx, change):
author, author_url = compact_author(ctx, change)
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
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(article=change["title"], article_url=link, author=author, author_url=author_url, comment=parsed_comment)
content = _(
"Account [{article}]({article_url}) was created by [{author}]({author_url}) and password was sent by email{comment}").format(
article=change["title"], article_url=link, author=author, author_url=author_url, comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# newusers/newusers - New users
@ -931,6 +987,7 @@ def compact_newusers_newusers(ctx, change):
content = _("Account [{author}]({author_url}) was created").format(author=author, author_url=author_url)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# interwiki/iw_add - Added entry to interwiki table
@ -951,11 +1008,13 @@ 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 + ")*"
content = _("[{author}]({author_url}) added an entry to the [interwiki table]({table_url}) pointing to {website} with {prefix} prefix").format(
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'],
website=change["logparams"]['1'], table_url=link)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# interwiki/iw_edit - Editing interwiki entry
@ -992,7 +1051,8 @@ def embed_interwiki_iw_delete(ctx, change):
embed_helper(ctx, embed, change, set_desc=False)
embed["url"] = create_article_path("Special:Interwiki")
embed["title"] = _("Deleted an entry in interwiki table")
embed["description"] = _("Prefix: {prefix} | {desc}").format(desc=ctx.parsedcomment, prefix=change["logparams"]['0'])
embed["description"] = _("Prefix: {prefix} | {desc}").format(desc=ctx.parsedcomment,
prefix=change["logparams"]['0'])
return embed
@ -1001,13 +1061,15 @@ 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 + ")*"
content = _("[{author}]({author_url}) deleted an entry in [interwiki table]({table_url}){desc}").format(author=author,
content = _("[{author}]({author_url}) deleted an entry in [interwiki table]({table_url}){desc}").format(
author=author,
author_url=author_url,
table_url=link,
desc=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# contentmodel/change - Changing the content model of a page
@ -1016,7 +1078,8 @@ def embed_contentmodel_change(ctx, change):
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
embed_helper(ctx, embed, change, set_desc=False)
embed["url"] = create_article_path(sanitize_to_url(change["title"]))
embed["title"] = _("Changed the content model of the page {article}").format(article=sanitize_to_markdown(change["title"]))
embed["title"] = _("Changed the content model of the page {article}").format(
article=sanitize_to_markdown(change["title"]))
embed["description"] = _("Model changed from {old} to {new}: {reason}").format(old=change["logparams"]["oldmodel"],
new=change["logparams"]["newmodel"],
reason=ctx.parsedcomment)
@ -1035,6 +1098,7 @@ def compact_contentmodel_change(ctx, change):
new=change["logparams"]["newmodel"], comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# contentmodel/new - Creating a page with non-default content model
@ -1043,8 +1107,10 @@ def embed_contentmodel_new(ctx, change):
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
embed_helper(ctx, embed, change, set_desc=False)
embed["url"] = create_article_path(sanitize_to_url(change["title"]))
embed["title"] = _("Created the page {article} using a non-default content model").format(article=sanitize_to_markdown(change["title"]))
embed["description"] = _("Created with model {new}: {reason}").format(new=change["logparams"]["newmodel"], reason=ctx.parsedcomment)
embed["title"] = _("Created the page {article} using a non-default content model").format(
article=sanitize_to_markdown(change["title"]))
embed["description"] = _("Created with model {new}: {reason}").format(new=change["logparams"]["newmodel"],
reason=ctx.parsedcomment)
return embed
@ -1059,6 +1125,7 @@ def compact_contentmodel_new(ctx, change):
new=change["logparams"]["newmodel"], comment=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# managetags/create - Creating log tags
@ -1080,13 +1147,16 @@ def compact_managetags_create(ctx, change):
content = _("[{author}]({author_url}) created the [tag]({tag_url}) \"{tag}\"{comment}").format(author=author,
author_url=author_url,
tag=
sanitize_to_markdown(change["logparams"][
sanitize_to_markdown(
change[
"logparams"][
"tag"]),
tag_url=link,
comment=ctx.parsedcomment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# managetags/delete - Deleting a tag
@ -1111,7 +1181,8 @@ def compact_managetags_delete(ctx, change):
if change["logparams"]["count"] == 0:
content = _("[{author}]({author_url}) deleted the [tag]({tag_url}) \"{tag}\"{comment}").format(author=author,
author_url=author_url,
tag=sanitize_to_markdown(change[
tag=sanitize_to_markdown(
change[
"logparams"][
"tag"]),
tag_url=link,
@ -1120,11 +1191,13 @@ def compact_managetags_delete(ctx, change):
content = ngettext(
"[{author}]({author_url}) deleted the [tag]({tag_url}) \"{tag}\" and removed it from {count} revision or log entry{comment}",
"[{author}]({author_url}) deleted the [tag]({tag_url}) \"{tag}\" and removed it from {count} revisions and/or log entries{comment}",
change["logparams"]["count"]).format(author=author, author_url=author_url, tag=sanitize_to_markdown(change["logparams"]["tag"]),
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)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# managetags/activate - Activating a tag
@ -1143,13 +1216,15 @@ def compact_managetags_activate(ctx, change):
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
content = _("[{author}]({author_url}) activated the [tag]({tag_url}) \"{tag}\"{comment}").format(author=author,
author_url=author_url,
tag=sanitize_to_markdown(change[
tag=sanitize_to_markdown(
change[
"logparams"][
"tag"]),
tag_url=link,
comment=ctx.parsedcomment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# managetags/deactivate - Deactivating a tag
@ -1168,13 +1243,15 @@ def compact_managetags_deactivate(ctx, change):
link = clean_link(create_article_path(sanitize_to_url(change["title"])))
content = _("[{author}]({author_url}) deactivated the [tag]({tag_url}) \"{tag}\"{comment}").format(author=author,
author_url=author_url,
tag=sanitize_to_markdown(change[
tag=sanitize_to_markdown(
change[
"logparams"][
"tag"]),
tag_url=link,
comment=ctx.parsedcomment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# renameuser/renameuser - Renaming a user
@ -1186,10 +1263,12 @@ def embed_renameuser_renameuser(ctx, change):
if edits > 0:
embed["title"] = ngettext("Renamed user \"{old_name}\" with {edits} edit to \"{new_name}\"",
"Renamed user \"{old_name}\" with {edits} edits to \"{new_name}\"", edits).format(
old_name=sanitize_to_markdown(change["logparams"]["olduser"]), edits=edits, new_name=sanitize_to_markdown(change["logparams"]["newuser"]))
old_name=sanitize_to_markdown(change["logparams"]["olduser"]), edits=edits,
new_name=sanitize_to_markdown(change["logparams"]["newuser"]))
else:
embed["title"] = _("Renamed user \"{old_name}\" to \"{new_name}\"").format(
old_name=sanitize_to_markdown(change["logparams"]["olduser"]), new_name=sanitize_to_markdown(change["logparams"]["newuser"]))
old_name=sanitize_to_markdown(change["logparams"]["olduser"]),
new_name=sanitize_to_markdown(change["logparams"]["newuser"]))
embed["url"] = create_article_path("User:" + sanitize_to_url(change["logparams"]["newuser"]))
return embed
@ -1205,7 +1284,8 @@ def compact_renameuser_renameuser(ctx, change):
"[{author}]({author_url}) renamed user *{old_name}* with {edits} edit to [{new_name}]({link}){comment}",
"[{author}]({author_url}) renamed user *{old_name}* with {edits} edits to [{new_name}]({link}){comment}",
edits).format(
author=author, author_url=author_url, old_name=sanitize_to_markdown(change["logparams"]["olduser"]), edits=edits,
author=author, author_url=author_url, old_name=sanitize_to_markdown(change["logparams"]["olduser"]),
edits=edits,
new_name=sanitize_to_markdown(change["logparams"]["newuser"]), link=link, comment=parsed_comment
)
else: