mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Added ManageWiki extension formatters
This commit is contained in:
parent
d42eed4e20
commit
8316ff1657
207
extensions/base/managewiki.py
Normal file
207
extensions/base/managewiki.py
Normal file
|
@ -0,0 +1,207 @@
|
|||
# This file is part of Recent changes Goat compatible Discord webhook (RcGcDw).
|
||||
#
|
||||
# RcGcDw is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# RcGcDw is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import logging
|
||||
import re
|
||||
from src.discord.message import DiscordMessage
|
||||
from src.api import formatter
|
||||
from src.i18n import rc_formatters
|
||||
from src.api.context import Context
|
||||
from src.api.util import embed_helper, compact_author, create_article_path, sanitize_to_markdown, sanitize_to_url
|
||||
|
||||
_ = rc_formatters.gettext
|
||||
ngettext = rc_formatters.ngettext
|
||||
|
||||
|
||||
# ManageWiki - https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:ManageWiki
|
||||
# managewiki/settings - Changing wiki settings
|
||||
|
||||
@formatter.embed(event="managewiki/settings")
|
||||
def embed_managewiki_settings(ctx: Context, change: dict):
|
||||
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"] = _("Changed wiki settings")
|
||||
if change["logparams"].get("changes", ""):
|
||||
embed.add_field("Setting", sanitize_to_markdown(change["logparams"].get("changes")))
|
||||
return embed
|
||||
|
||||
|
||||
@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 + ")*"
|
||||
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)
|
||||
|
||||
# managewiki/delete - Deleting a wiki
|
||||
|
||||
|
||||
@formatter.embed(event="managewiki/delete")
|
||||
def embed_managewiki_delete(ctx: Context, change: dict):
|
||||
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 a \"{wiki}\" wiki").format(wiki=change["logparams"].get("wiki", _("Unknown")))
|
||||
return embed
|
||||
|
||||
|
||||
@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 + ")*"
|
||||
content = _("[{author}]({author_url}) deleted a wiki *{wiki_name}*{comment}").format(author=author,
|
||||
author_url=author_url,
|
||||
wiki_name=change[
|
||||
"logparams"].get("wiki",
|
||||
_("Unknown")),
|
||||
comment=parsed_comment)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||
|
||||
# managewiki/lock - Locking a wiki
|
||||
|
||||
|
||||
@formatter.embed(event="managewiki/lock")
|
||||
def embed_managewiki_lock(ctx: Context, change: dict):
|
||||
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"] = _("Locked a \"{wiki}\" wiki").format(wiki=change["logparams"].get("wiki", _("Unknown")))
|
||||
return embed
|
||||
|
||||
|
||||
@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 + ")*"
|
||||
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)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||
|
||||
# managewiki/namespaces - Modirying a wiki namespace
|
||||
|
||||
|
||||
@formatter.embed(event="managewiki/namespaces")
|
||||
def embed_managewiki_namespaces(ctx: Context, change: dict):
|
||||
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"] = _("Modified \"{namespace_name}\" namespace").format(
|
||||
namespace_name=change["logparams"].get("namespace", _("Unknown")))
|
||||
embed.add_field(_('Wiki'), change["logparams"].get("wiki", _("Unknown")))
|
||||
return embed
|
||||
|
||||
|
||||
@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 + ")*"
|
||||
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)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||
|
||||
# managewiki/namespaces-delete - Deleteing a namespace
|
||||
|
||||
|
||||
@formatter.embed(event="managewiki/namespaces-delete")
|
||||
def embed_managewiki_namespaces_delete(ctx: Context, change: dict):
|
||||
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 a \"{namespace_name}\" namespace").format(
|
||||
namespace_name=change["logparams"].get("namespace", _("Unknown")))
|
||||
embed.add_field(_('Wiki'), change["logparams"].get("wiki", _("Unknown")))
|
||||
return embed
|
||||
|
||||
|
||||
@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 + ")*"
|
||||
content = _(
|
||||
"[{author}]({author_url}) deleted a 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)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||
|
||||
# managewiki/rights - Modifying user groups
|
||||
|
||||
|
||||
@formatter.embed(event="managewiki/rights")
|
||||
def embed_managewiki_rights(ctx: Context, change: dict):
|
||||
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"]))
|
||||
group_name = change["title"].split("/permissions/", 1)[1]
|
||||
embed["title"] = _("Modified \"{usergroup_name}\" usergroup").format(usergroup_name=group_name)
|
||||
return embed
|
||||
|
||||
|
||||
@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 + ")*"
|
||||
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
|
||||
)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||
|
||||
# managewiki/undelete - Restoring a wiki
|
||||
|
||||
|
||||
@formatter.embed(event="managewiki/undelete")
|
||||
def embed_managewiki_undelete(ctx: Context, change: dict):
|
||||
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"] = _("Undeleted a \"{wiki}\" wiki").format(wiki=change["logparams"].get("wiki", _("Unknown")))
|
||||
return embed
|
||||
|
||||
|
||||
@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 + ")*"
|
||||
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
|
||||
)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||
|
||||
# managewiki/unlock - Unlocking a wiki
|
||||
|
||||
|
||||
@formatter.embed(event="managewiki/unlock")
|
||||
def embed_managewiki_unlock(ctx: Context, change: dict):
|
||||
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"] = _("Unlocked a \"{wiki}\" wiki").format(wiki=change["logparams"].get("wiki", _("Unknown")))
|
||||
return embed
|
||||
|
||||
|
||||
@formatter.compact(event="managewiki/undelete")
|
||||
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 + ")*"
|
||||
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
|
||||
)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
|
@ -245,37 +245,21 @@ def compact_formatter(action, change, parsed_comment, categories, recent_changes
|
|||
elif action == "managetags/deactivate":
|
||||
link = link_formatter(create_article_path(change["title"]))
|
||||
elif action == "managewiki/settings": # Miraheze's ManageWiki extension https://github.com/miraheze/ManageWiki
|
||||
content = _("[{author}]({author_url}) changed wiki settings{reason}".format(author=author, author_url=author_url, reason=parsed_comment))
|
||||
|
||||
elif action == "managewiki/delete":
|
||||
content = _("[{author}]({author_url}) deleted a wiki *{wiki_name}*{comment}").format(author=author, author_url=author_url,
|
||||
wiki_name=change["logparams"].get("wiki", _("Unknown")), comment=parsed_comment)
|
||||
|
||||
elif action == "managewiki/lock":
|
||||
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)
|
||||
|
||||
elif action == "managewiki/namespaces":
|
||||
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)
|
||||
|
||||
elif action == "managewiki/namespaces-delete":
|
||||
content = _(
|
||||
"[{author}]({author_url}) deleted a 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)
|
||||
|
||||
elif action == "managewiki/rights":
|
||||
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
|
||||
)
|
||||
|
||||
elif action == "managewiki/undelete":
|
||||
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
|
||||
)
|
||||
|
||||
elif action == "managewiki/unlock":
|
||||
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
|
||||
)
|
||||
|
||||
elif action == "datadump/generate":
|
||||
content = _("[{author}]({author_url}) generated *{file}* dump{comment}").format(
|
||||
author=author, author_url=author_url, file=change["logparams"]["filename"],
|
||||
|
@ -621,35 +605,21 @@ def embed_formatter(action, change, parsed_comment, categories, recent_changes):
|
|||
elif action == "managetags/deactivate":
|
||||
|
||||
elif action == "managewiki/settings": # Miraheze's ManageWiki extension https://github.com/miraheze/ManageWiki
|
||||
link = create_article_path(change["title"])
|
||||
embed["title"] = _("Changed wiki settings")
|
||||
if change["logparams"].get("changes", ""):
|
||||
embed.add_field("Setting", change["logparams"].get("changes"))
|
||||
|
||||
elif action == "managewiki/delete":
|
||||
embed["title"] = _("Deleted a \"{wiki}\" wiki").format(wiki=change["logparams"].get("wiki", _("Unknown")))
|
||||
link = create_article_path(change["title"])
|
||||
|
||||
elif action == "managewiki/lock":
|
||||
embed["title"] = _("Locked a \"{wiki}\" wiki").format(wiki=change["logparams"].get("wiki", _("Unknown")))
|
||||
link = create_article_path(change["title"])
|
||||
|
||||
elif action == "managewiki/namespaces":
|
||||
embed["title"] = _("Modified \"{namespace_name}\" namespace").format(namespace_name=change["logparams"].get("namespace", _("Unknown")))
|
||||
link = create_article_path(change["title"])
|
||||
embed.add_field(_('Wiki'), change["logparams"].get("wiki", _("Unknown")))
|
||||
|
||||
elif action == "managewiki/namespaces-delete":
|
||||
embed["title"] = _("Deleted a \"{namespace_name}\" namespace").format(
|
||||
namespace_name=change["logparams"].get("namespace", _("Unknown")))
|
||||
link = create_article_path(change["title"])
|
||||
embed.add_field(_('Wiki'), change["logparams"].get("wiki", _("Unknown")))
|
||||
|
||||
elif action == "managewiki/rights":
|
||||
group_name = change["title"].split("/permissions/", 1)[1]
|
||||
embed["title"] = _("Modified \"{usergroup_name}\" usergroup").format(usergroup_name=group_name)
|
||||
link = create_article_path(change["title"])
|
||||
|
||||
elif action == "managewiki/undelete":
|
||||
embed["title"] = _("Undeleted a \"{wiki}\" wiki").format(wiki=change["logparams"].get("wiki", _("Unknown")))
|
||||
link = create_article_path(change["title"])
|
||||
|
||||
elif action == "managewiki/unlock":
|
||||
embed["title"] = _("Unlocked a \"{wiki}\" wiki").format(wiki=change["logparams"].get("wiki", _("Unknown")))
|
||||
link = create_article_path(change["title"])
|
||||
|
||||
elif action == "datadump/generate":
|
||||
embed["title"] = _("Generated {file} dump").format(file=change["logparams"]["filename"])
|
||||
link = create_article_path(change["title"])
|
||||
|
|
Loading…
Reference in a new issue