From e1c7d30b6fbf05bc2c46a3f2c2f5a062f971ee94 Mon Sep 17 00:00:00 2001 From: Frisk Date: Wed, 4 Dec 2024 11:58:36 +0100 Subject: [PATCH] Add support for globalblocking from RcGcDw --- extensions/base/__init__.py | 1 + extensions/base/globalblocking.py | 156 ++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 extensions/base/globalblocking.py diff --git a/extensions/base/__init__.py b/extensions/base/__init__.py index 98b6d74..6059f40 100644 --- a/extensions/base/__init__.py +++ b/extensions/base/__init__.py @@ -28,3 +28,4 @@ import extensions.base.approvedrevs import extensions.base.templateclassification import extensions.base.comments import extensions.base.rcgcdb +import extensions.base.globalblocking diff --git a/extensions/base/globalblocking.py b/extensions/base/globalblocking.py new file mode 100644 index 0000000..7c1ac8c --- /dev/null +++ b/extensions/base/globalblocking.py @@ -0,0 +1,156 @@ +# 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 . + +from src.discord.message import DiscordMessage +from src.api import formatter +from src.api.context import Context +from src.api.util import embed_helper, clean_link, compact_author, compact_summary, sanitize_to_markdown + + +# GlobalBlocking - https://www.mediawiki.org/wiki/Extension:GlobalBlocking +# gblblock/gblock2 - Globally block an IP address + +@formatter.embed(event="gblblock/gblock2", mode="embed") +def embed_gblblock_gblock2(ctx: Context, change: dict): + embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url) + user = change["title"].split(':', 1)[1] + embed["url"] = ctx.client.create_article_path("Special:Contributions/{user}".format(user=user)) + embed["title"] = ctx._("Globally blocked {blocked_user}").format(blocked_user=user) + embed["description"] = change["logparams"].get("0", ctx._("no further information about the block")) + embed_helper(ctx, embed, change) + return embed + + +@formatter.compact(event="gblblock/gblock2", mode="compact") +def compact_gblblock_gblock2(ctx: Context, change: dict): + user = change["title"].split(':', 1)[1] + author, author_url = compact_author(ctx, change) + parsed_comment = compact_summary(ctx) + link = clean_link(ctx.client.create_article_path("Special:Contributions/{user}".format(user=user))) + content = ctx._( + "[{author}]({author_url}) globally blocked [{user}]({user_url}) {options} {comment}").format(author=author, + author_url=author_url, + user=sanitize_to_markdown(user), + options=change["logparams"].get("0", ctx._("no further information about the block")), + user_url=link, + comment=parsed_comment) + return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content) + + +# gblblock/whitelist - Disable locally a global ban on an IP address +@formatter.embed(event="gblblock/whitelist", mode="embed") +def embed_gblblock_whitelist(ctx: Context, change: dict): + embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url) + user = change["title"].split(':', 1)[1] + embed["url"] = ctx.client.create_article_path("Special:Contributions/{user}".format(user=user)) + embed["title"] = ctx._("Disabled the global block locally on {blocked_user}").format(blocked_user=user) + embed_helper(ctx, embed, change) + return embed + + +@formatter.compact(event="gblblock/whitelist", mode="compact") +def compact_gblblock_whitelist(ctx: Context, change: dict): + user = change["title"].split(':', 1)[1] + author, author_url = compact_author(ctx, change) + parsed_comment = compact_summary(ctx) + link = clean_link(ctx.client.create_article_path("Special:Contributions/{user}".format(user=user))) + content = ctx._( + "[{author}]({author_url}) disabled the global block locally on [{user}]({user_url}) {comment}").format(author=author, + author_url=author_url, + user=sanitize_to_markdown(user), + user_url=link, + comment=parsed_comment) + return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content) + +# gblblock/gunblock - Remove a global block on an IP address + + +@formatter.embed(event="gblblock/gunblock", mode="embed") +def embed_gblblock_gunblock(ctx: Context, change: dict): + embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url) + user = change["title"].split(':', 1)[1] + embed["url"] = ctx.client.create_article_path("Special:Contributions/{user}".format(user=user)) + embed["title"] = ctx._("Removed the global block on {blocked_user}").format(blocked_user=user) + embed_helper(ctx, embed, change) + return embed + + +@formatter.compact(event="gblblock/gunblock", mode="compact") +def compact_gblblock_gunblock(ctx: Context, change: dict): + user = change["title"].split(':', 1)[1] + author, author_url = compact_author(ctx, change) + parsed_comment = compact_summary(ctx) + link = clean_link(ctx.client.create_article_path("Special:Contributions/{user}".format(user=user))) + content = ctx._( + "[{author}]({author_url}) removed the global block on [{user}]({user_url}) {comment}").format(author=author, + author_url=author_url, + user=sanitize_to_markdown(user), + user_url=link, + comment=parsed_comment) + return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content) + + +# gblblock/modify - Remove a global block on an IP address +@formatter.embed(event="gblblock/modify", mode="embed") +def embed_gblblock_modify(ctx: Context, change: dict): + embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url) + user = change["title"].split(':', 1)[1] + embed["url"] = ctx.client.create_article_path("Special:Contributions/{user}".format(user=user)) + embed["title"] = ctx._("Modified the global block on {blocked_user}").format(blocked_user=user) + embed["description"] = change["logparams"].get("0", ctx._("no further information about the block")) + embed_helper(ctx, embed, change) + return embed + + +@formatter.compact(event="gblblock/modify", mode="compact") +def compact_gblblock_modify(ctx: Context, change: dict): + user = change["title"].split(':', 1)[1] + author, author_url = compact_author(ctx, change) + parsed_comment = compact_summary(ctx) + link = clean_link(ctx.client.create_article_path("Special:Contributions/{user}".format(user=user))) + content = ctx._( + "[{author}]({author_url}) modified the global block on [{user}]({user_url}) {options} {comment}").format(author=author, + author_url=author_url, + user=sanitize_to_markdown(user), + options=change["logparams"].get("0",ctx._("no further information about the block")), + user_url=link, + comment=parsed_comment) + return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content) + + +# gblblock/whitelist - Disable locally a global ban +@formatter.embed(event="gblblock/dwhitelist", mode="embed") +def embed_gblblock_dwhitelist(ctx: Context, change: dict): + embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url) + user = change["title"].split(':', 1)[1] + embed["url"] = ctx.client.create_article_path("Special:Contributions/{user}".format(user=user)) + embed["title"] = ctx._("Re-enabled the global block locally on {blocked_user}").format(blocked_user=user) + embed_helper(ctx, embed, change) + return embed + + +@formatter.compact(event="gblblock/dwhitelist", mode="compact") +def compact_gblblock_dwhitelist(ctx: Context, change: dict): + user = change["title"].split(':', 1)[1] + author, author_url = compact_author(ctx, change) + parsed_comment = compact_summary(ctx) + link = clean_link(ctx.client.create_article_path("Special:Contributions/{user}".format(user=user))) + content = ctx._( + "[{author}]({author_url}) re-enabled the global block locally on [{user}]({user_url}) {comment}").format(author=author, + author_url=author_url, + user=sanitize_to_markdown(user), + user_url=link, + comment=parsed_comment) + return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)