This commit is contained in:
MarkusRost 2021-05-19 12:47:26 +00:00
parent b640a090ea
commit 348d28fb45

View file

@ -20,51 +20,214 @@ from src.api import formatter
from src.i18n import rc_formatters from src.i18n import rc_formatters
from src.api.context import Context from src.api.context import Context
from src.api.util import embed_helper, clean_link, compact_author, create_article_path, sanitize_to_markdown, sanitize_to_url from src.api.util import embed_helper, clean_link, compact_author, create_article_path, sanitize_to_markdown, sanitize_to_url
from src.misc import profile_field_name
_ = rc_formatters.gettext _ = rc_formatters.gettext
ngettext = rc_formatters.ngettext ngettext = rc_formatters.ngettext
# CurseProfile - https://help.fandom.com/wiki/Extension:CurseProfile # CurseProfile - https://help.fandom.com/wiki/Extension:CurseProfile
# renameuser/renameuser - Renaming a user # curseprofile/profile-edited - Editing user profile
@formatter.embed(event="renameuser/renameuser") @formatter.embed(event="curseprofile/profile-edited")
def embed_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage: def embed_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage:
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url) embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
embed_helper(ctx, embed, change) embed_helper(ctx, embed, change)
edits = change["logparams"]["edits"] target_user = change["title"].split(':', 1)[1]
if edits > 0: if target_user != change["user"]:
embed["title"] = ngettext("Renamed user \"{old_name}\" with {edits} edit to \"{new_name}\"", embed["title"] = _("Edited {target}'s profile").format(target=sanitize_to_markdown(target_user))
"Renamed user \"{old_name}\" with {edits} edits to \"{new_name}\"", edits).format( else:
old_name=sanitize_to_markdown(change["logparams"]["olduser"]), edits=edits, embed["title"] = _("Edited their own profile")
new_name=sanitize_to_markdown(change["logparams"]["newuser"])) if ctx.parsedcomment is None: # If the field is empty
else: embed["description"] = _("Cleared the {field} field").format(field=profile_field_name(change["logparams"]['4:section'], True))
embed["title"] = _("Renamed user \"{old_name}\" to \"{new_name}\"").format( else:
old_name=sanitize_to_markdown(change["logparams"]["olduser"]), embed["description"] = _("{field} field changed to: {desc}").format(field=profile_field_name(change["logparams"]['4:section'], True), desc=ctx.parsedcomment)
new_name=sanitize_to_markdown(change["logparams"]["newuser"])) embed["url"] = create_article_path("UserProfile:" + sanitize_to_url(target_user))
embed["url"] = create_article_path("User:" + sanitize_to_url(change["logparams"]["newuser"]))
return embed return embed
@formatter.compact(event="renameuser/renameuser") @formatter.compact(event="curseprofile/profile-edited")
def compact_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage: def compact_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage:
author, author_url = compact_author(ctx, change) author, author_url = compact_author(ctx, change)
link = clean_link(create_article_path("User:" + sanitize_to_url(change["logparams"]["newuser"]))) target_user = change["title"].split(':', 1)[1]
edits = change["logparams"]["edits"] link = clean_link(create_article_path("UserProfile:" + sanitize_to_url(target_user)))
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*" if target_user != author:
if edits > 0: if ctx.parsedcomment is None: # If the field is empty
content = ngettext( edit_clear_message = _("[{author}]({author_url}) cleared the {field} on [{target}]({target_url})'s profile.")
"[{author}]({author_url}) renamed user *{old_name}* with {edits} edit to [{new_name}]({link}){comment}", else:
"[{author}]({author_url}) renamed user *{old_name}* with {edits} edits to [{new_name}]({link}){comment}", edit_clear_message = _("[{author}]({author_url}) edited the {field} on [{target}]({target_url})'s profile. *({desc})*")
edits).format( content = edit_clear_message.format(author=author, author_url=author_url, target=sanitize_to_markdown(target_user), target_url=link,
author=author, author_url=author_url, old_name=sanitize_to_markdown(change["logparams"]["olduser"]), field=profile_field_name(change["logparams"]['4:section'], False), desc=ctx.parsedcomment)
edits=edits, else:
new_name=sanitize_to_markdown(change["logparams"]["newuser"]), link=link, comment=parsed_comment if ctx.parsedcomment is None: # If the field is empty
) edit_clear_message = _("[{author}]({author_url}) cleared the {field} on [their own]({target_url}) profile.")
else: else:
content = _("[{author}]({author_url}) renamed user *{old_name}* to [{new_name}]({link}){comment}").format( edit_clear_message = _("[{author}]({author_url}) edited the {field} on [their own]({target_url}) profile. *({desc})*")
author=author, author_url=author_url, old_name=sanitize_to_markdown(change["logparams"]["olduser"]), content = edit_clear_message.format(author=author, author_url=author_url, target_url=link,
new_name=sanitize_to_markdown(change["logparams"]["newuser"]), link=link, comment=parsed_comment field=profile_field_name(change["logparams"]['4:section'], False), desc=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)
# curseprofile/comment-created - Creating comment on user profile
@formatter.embed(event="curseprofile/comment-created")
def embed_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage:
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
embed_helper(ctx, embed, change)
target_user = change["title"].split(':', 1)[1]
if target_user != change["user"]:
embed["title"] = _("Left a comment on {target}'s profile").format(target=sanitize_to_markdown(target_user))
else:
embed["title"] = _("Left a comment on their own profile")
if settings["appearance"]["embed"]["show_edit_changes"]:
embed["description"] = ctx.client.pull_curseprofile_comment(change["logparams"]["4:comment_id"])
embed["url"] = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]))
return embed
@formatter.compact(event="curseprofile/comment-created")
def compact_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage:
author, author_url = compact_author(ctx, change)
target_user = change["title"].split(':', 1)[1]
link = clean_link(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"])))
if target_user != author:
content = _("[{author}]({author_url}) left a [comment]({comment}) on {target}'s profile.").format(
author=author, author_url=author_url, comment=link, target=sanitize_to_markdown(target_user))
else:
content = _("[{author}]({author_url}) left a [comment]({comment}) on their own profile.").format(author=author, author_url=author_url, comment=link)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# curseprofile/comment-edited - Editing comment on user profile
@formatter.embed(event="curseprofile/comment-edited")
def embed_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage:
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
embed_helper(ctx, embed, change)
target_user = change["title"].split(':', 1)[1]
if target_user != change["user"]:
embed["title"] = _("Edited a comment on {target}'s profile").format(target=sanitize_to_markdown(target_user))
else:
embed["title"] = _("Edited a comment on their own profile")
if settings["appearance"]["embed"]["show_edit_changes"]:
embed["description"] = ctx.client.pull_curseprofile_comment(change["logparams"]["4:comment_id"])
embed["url"] = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]))
return embed
@formatter.compact(event="curseprofile/comment-edited")
def compact_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage:
author, author_url = compact_author(ctx, change)
target_user = change["title"].split(':', 1)[1]
link = clean_link(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"])))
if target_user != author:
content = _("[{author}]({author_url}) edited a [comment]({comment}) on {target}'s profile.").format(
author=author, author_url=author_url, comment=link, target=sanitize_to_markdown(target_user))
else:
content = _("[{author}]({author_url}) edited a [comment]({comment}) on their own profile.").format(author=author, author_url=author_url, comment=link)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# curseprofile/comment-replied - Replying to comment on user profile
@formatter.embed(event="curseprofile/comment-replied")
def embed_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage:
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
embed_helper(ctx, embed, change)
target_user = change["title"].split(':', 1)[1]
if target_user != change["user"]:
embed["title"] = _("Replied to a comment on {target}'s profile").format(target=sanitize_to_markdown(target_user))
else:
embed["title"] = _("Replied to a comment on their own profile")
if settings["appearance"]["embed"]["show_edit_changes"]:
embed["description"] = ctx.client.pull_curseprofile_comment(change["logparams"]["4:comment_id"])
embed["url"] = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]))
return embed
@formatter.compact(event="curseprofile/comment-replied")
def compact_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage:
author, author_url = compact_author(ctx, change)
target_user = change["title"].split(':', 1)[1]
link = clean_link(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"])))
if target_user != author:
content = _("[{author}]({author_url}) replied to a [comment]({comment}) on {target}'s profile.").format(
author=author, author_url=author_url, comment=link, target=sanitize_to_markdown(target_user))
else:
content = _("[{author}]({author_url}) replied to a [comment]({comment}) on their own profile.").format(author=author, author_url=author_url, comment=link)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# curseprofile/comment-deleted - Deleting comment on user profile
@formatter.embed(event="curseprofile/comment-deleted")
def embed_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage:
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
embed_helper(ctx, embed, change)
target_user = change["title"].split(':', 1)[1]
if target_user != change["user"]:
embed["title"] = _("Deleted a comment on {target}'s profile").format(target=sanitize_to_markdown(target_user))
else:
embed["title"] = _("Deleted a comment on their own profile")
if ctx.parsedcomment is not None:
embed["description"] = ctx.parsedcomment
if "4:comment_id" in change["logparams"]:
embed["url"] = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]))
else:
embed["url"] = create_article_path("UserProfile:" + sanitize_to_url(target_user))
return embed
@formatter.compact(event="curseprofile/comment-deleted")
def compact_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage:
author, author_url = compact_author(ctx, change)
target_user = change["title"].split(':', 1)[1]
if "4:comment_id" in change["logparams"]:
link = clean_link(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"])))
else:
link = clean_link(create_article_path("UserProfile:" + sanitize_to_url(target_user)))
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
if target_user != author:
content = _("[{author}]({author_url}) deleted a [comment]({comment}) on {target}'s profile.{reason}").format(
author=author, author_url=author_url, comment=link, target=sanitize_to_markdown(target_user), reason=parsed_comment)
else:
content = _("[{author}]({author_url}) deleted a [comment]({comment}) on their own profile.{reason}").format(
author=author, author_url=author_url, comment=link, reason=parsed_comment)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
# curseprofile/comment-purged - Purging comment on user profile
@formatter.embed(event="curseprofile/comment-purged")
def embed_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage:
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
embed_helper(ctx, embed, change)
target_user = change["title"].split(':', 1)[1]
if target_user != change["user"]:
embed["title"] = _("Purged a comment on {target}'s profile").format(target=sanitize_to_markdown(target_user))
else:
embed["title"] = _("Purged a comment on their own profile")
if ctx.parsedcomment is not None:
embed["description"] = ctx.parsedcomment
embed["url"] = create_article_path("UserProfile:" + sanitize_to_url(target_user))
return embed
@formatter.compact(event="curseprofile/comment-purged")
def compact_renameuser_renameuser(ctx: Context, change: dict) -> DiscordMessage:
author, author_url = compact_author(ctx, change)
target_user = change["title"].split(':', 1)[1]
link = clean_link(create_article_path("UserProfile:" + sanitize_to_url(target_user)))
parsed_comment = "" if ctx.parsedcomment is None else " *(" + ctx.parsedcomment + ")*"
if target_user != author:
content = _("[{author}]({author_url}) purged a comment on [{target}]({link})'s profile.{reason}").format(
author=author, author_url=author_url, link=link, target=sanitize_to_markdown(target_user), reason=parsed_comment)
else:
content = _("[{author}]({author_url}) purged a comment on [their own]({link}) profile.{reason}").format(author=author, author_url=author_url, link=link)
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content, reason=parsed_comment)