From c74172f6b3395d30b7be70752aab1c49b3811e77 Mon Sep 17 00:00:00 2001 From: MarkusRost <2701034-MarkusRost@users.noreply.gitlab.com> Date: Sat, 6 May 2023 17:03:08 +0200 Subject: [PATCH 1/5] add RcGcDw buttons --- src/bot.py | 4 ++-- src/discord.py | 7 +++++++ src/formatters/rc.py | 49 +++++++++++++++++++++++++++++++++++++++++++- src/wiki.py | 4 ++-- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/bot.py b/src/bot.py index 5a8ef26..1fd1910 100644 --- a/src/bot.py +++ b/src/bot.py @@ -240,8 +240,8 @@ async def generate_targets(wiki_url: str, additional_requirements: str) -> defau combinations = defaultdict(list) async with db.pool().acquire() as connection: async with connection.transaction(): - async for webhook in connection.cursor('SELECT webhook, lang, display FROM rcgcdw WHERE wiki = $1 {}'.format(additional_requirements), wiki_url): - combination = (webhook["lang"], webhook["display"]) + async for webhook in connection.cursor('SELECT webhook, lang, display, buttons FROM rcgcdw WHERE wiki = $1 {}'.format(additional_requirements), wiki_url): + combination = (webhook["lang"], webhook["display"], webhook["buttons"]) combinations[combination].append(webhook["webhook"]) return combinations diff --git a/src/discord.py b/src/discord.py index 1517020..473449c 100644 --- a/src/discord.py +++ b/src/discord.py @@ -125,6 +125,13 @@ class DiscordMessage: self.length += len(name) + len(value) self.embed["fields"].append(dict(name=name, value=value, inline=inline)) + def add_button(self, custom_id, label, style=2, emoji=None): + if "components" not in self.webhook_object: + self.webhook_object["components"] = [{"type": 1, "components": []}] + if len(self.webhook_object["components"][-1]["components"]) >= 5: + self.webhook_object["components"].append({"type": 1, "components": []}) + self.webhook_object["components"][-1]["components"].append({"type": 2, "custom_id": custom_id, "style": style, "label": label, "emoji": emoji}) + def set_avatar(self, url): self.webhook_object["avatar_url"] = url diff --git a/src/formatters/rc.py b/src/formatters/rc.py index 660ae53..ea54bbf 100644 --- a/src/formatters/rc.py +++ b/src/formatters/rc.py @@ -30,12 +30,17 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c WIKI_SCRIPT_PATH = paths[1] WIKI_ARTICLE_PATH = paths[2] WIKI_JUST_DOMAIN = paths[3] + BUTTON_PREFIX = "rc_/" + WIKI_SCRIPT_PATH.split('/', 3)[3] + action_buttons = message_target[0][2].split('|') if message_target[0][2] is not None else [] + message_buttons = [] if action != "suppressed": if "anon" in change: author_url = link_formatter(create_article_path("Special:Contributions/{user}".format(user=change["user"]), WIKI_ARTICLE_PATH)) else: author_url = link_formatter(create_article_path("User:{user}".format(user=change["user"]), WIKI_ARTICLE_PATH)) author = change["user"] + if "block" in action_buttons: + message_buttons.append((BUTTON_PREFIX + " block " + change["userid"], _("Block user"), 4, {"id": None, "name": "๐Ÿšซ"})) parsed_comment = "" if parsed_comment is None else " *("+parsed_comment+")*" if action in ["edit", "new"]: edit_link = link_formatter("{wiki}index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format( @@ -50,8 +55,14 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c bold = "**" if action == "edit": content = _("[{author}]({author_url}) edited [{article}]({edit_link}){comment} {bold}({sign}{edit_size}){bold}").format(author=author, author_url=author_url, article=change["title"], edit_link=edit_link, comment=parsed_comment, edit_size=edit_size, sign=sign, bold=bold) + if "rollback" in action_buttons: + message_buttons.append((BUTTON_PREFIX + " rollback " + change["pageid"] + " " + change["userid"], _("Rollback"), 1, {"id": None, "name": "๐Ÿ”"})) + if "undo" in action_buttons: + message_buttons.append((BUTTON_PREFIX + " undo " + change["pageid"] + " " + change["revid"], _("Undo"), 2, {"id": None, "name": "๐Ÿ”‚"})) else: content = _("[{author}]({author_url}) created [{article}]({edit_link}){comment} {bold}({sign}{edit_size}){bold}").format(author=author, author_url=author_url, article=change["title"], edit_link=edit_link, comment=parsed_comment, edit_size=edit_size, sign=sign, bold=bold) + if "delete" in action_buttons: + message_buttons.append((BUTTON_PREFIX + " delete " + change["pageid"], _("Delete"), 4, {"id": None, "name": "๐Ÿ—‘๏ธ"})) elif action =="upload/upload": file_link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH)) content = _("[{author}]({author_url}) uploaded [{file}]({file_link}){comment}").format(author=author, @@ -59,6 +70,8 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c file=change["title"], file_link=file_link, comment=parsed_comment) + if "delete" in action_buttons: + message_buttons.append((BUTTON_PREFIX + " delete " + change["pageid"], _("Delete"), 4, {"id": None, "name": "๐Ÿ—‘๏ธ"})) elif action == "upload/revert": file_link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH)) content = _("[{author}]({author_url}) reverted a version of [{file}]({file_link}){comment}").format( @@ -79,12 +92,20 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c redirect_status = _("without making a redirect") if "suppressredirect" in change["logparams"] else _("with a redirect") 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=change["logparams"]['target_title'], target_url=link, comment=parsed_comment, made_a_redirect=redirect_status) + if "move" in action_buttons: + custom_id = BUTTON_PREFIX + " move " + change["pageid"] + " " + change["title"] + if len(custom_id) <= 100: + message_buttons.append((custom_id, _("Move back"), 2, {"id": None, "name": "๐Ÿ”‚"})) elif action == "move/move_redir": link = link_formatter(create_article_path(change["logparams"]["target_title"], WIKI_ARTICLE_PATH)) redirect_status = _("without making a redirect") if "suppressredirect" in change["logparams"] else _( "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=change["title"], target=change["logparams"]['target_title'], target_url=link, comment=parsed_comment, made_a_redirect=redirect_status) + if "move" in action_buttons: + custom_id = BUTTON_PREFIX + " move " + change["pageid"] + " " + change["title"] + if len(custom_id) <= 100: + message_buttons.append((custom_id, _("Move back"), 2, {"id": None, "name": "๐Ÿ”‚"})) elif action == "protect/move_prot": link = link_formatter(create_article_path(change["logparams"]["oldtitle_title"], WIKI_ARTICLE_PATH)) content = _( @@ -591,7 +612,10 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c else: content = _("Unknown event `{event}` by [{author}]({author_url}), report it on the [support server](<{support}>).").format(event=action, author=author, author_url=author_url, support=settings["support"]) action = "unknown" - return DiscordMessage("compact", action, message_target[1], content=content, wiki=WIKI_SCRIPT_PATH) + message = DiscordMessage("compact", action, message_target[1], content=content, wiki=WIKI_SCRIPT_PATH) + for message_button in message_buttons: + message.add_button(*message_button) + return message async def embed_formatter(action, change, parsed_comment, categories, recent_changes, message_target, paths, rate_limiter, additional_data=None) -> DiscordMessage: @@ -604,6 +628,8 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha WIKI_SCRIPT_PATH = paths[1] WIKI_ARTICLE_PATH = paths[2] WIKI_JUST_DOMAIN = paths[3] + BUTTON_PREFIX = "rc_/" + WIKI_SCRIPT_PATH.split('/', 3)[3] + action_buttons = message_target[0][2].split('|') if message_target[0][2] is not None else [] embed = DiscordMessage("embed", action, message_target[1], wiki=WIKI_SCRIPT_PATH) if parsed_comment is None: parsed_comment = _("No description provided") @@ -613,6 +639,8 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha else: author_url = create_article_path("User:{}".format(change["user"]), WIKI_ARTICLE_PATH) embed.set_author(change["user"], author_url) + if "block" in action_buttons: + embed.add_button(BUTTON_PREFIX + " block " + change["userid"], _("Block user"), 4, {"id": None, "name": "๐Ÿšซ"}) if action in ("edit", "new"): # edit or new page editsize = change["newlen"] - change["oldlen"] if editsize > 0: @@ -667,6 +695,13 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha embed.add_field(_("Added"), "{data}".format(data=EditDiff.small_prev_ins), inline=True) else: logger.warning("Unable to download data on the edit content!") + if action == "new" and "delete" in action_buttons: + embed.add_button(BUTTON_PREFIX + " delete " + change["pageid"], _("Delete"), 4, {"id": None, "name": "๐Ÿ—‘๏ธ"}) + if action == "edit": + if "rollback" in action_buttons: + embed.add_button(BUTTON_PREFIX + " rollback " + change["pageid"] + " " + change["userid"], _("Rollback"), 1, {"id": None, "name": "๐Ÿ”"}) + if "undo" in action_buttons: + embed.add_button(BUTTON_PREFIX + " undo " + change["pageid"] + " " + change["revid"], _("Undo"), 2, {"id": None, "name": "๐Ÿ”‚"}) elif action in ("upload/overwrite", "upload/upload", "upload/revert"): # sending files license = None try: @@ -705,6 +740,8 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha wiki=WIKI_SCRIPT_PATH, filename=article_encoded, archiveid=revision["archivename"]) embed.add_field(_("Options"), _("([preview]({link}) | [undo]({undolink}))").format( link=image_direct_url, undolink=undolink)) + if "filerevert" in action_buttons: + embed.add_button(BUTTON_PREFIX + " file " + change["pageid"] + " " + revision["archivename"].split("!")[0], _("Revert"), 2, {"id": None, "name": "๐Ÿ”‚"}) if message_target[0][1] > 1: embed["image"]["url"] = image_direct_url if action == "upload/overwrite": @@ -717,6 +754,8 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha embed.add_field(_("Options"), _("([preview]({link}))").format(link=image_direct_url)) if message_target[0][1] > 1: embed["image"]["url"] = image_direct_url + if "delete" in action_buttons: + embed.add_button(BUTTON_PREFIX + " delete " + change["pageid"], _("Delete"), 4, {"id": None, "name": "๐Ÿ—‘๏ธ"}) elif action == "delete/delete": link = create_article_path(change["title"], WIKI_ARTICLE_PATH) embed["title"] = _("Deleted page {article}").format(article=change["title"]) @@ -729,10 +768,18 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha 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=change["title"], target=change["logparams"]['target_title']) + if "move" in action_buttons: + custom_id = BUTTON_PREFIX + " move " + change["pageid"] + " " + change["title"] + if len(custom_id) <= 100: + embed.add_button(custom_id, _("Move back"), 2, {"id": None, "name": "๐Ÿ”‚"}) elif action == "move/move_redir": link = create_article_path(change["logparams"]["target_title"], WIKI_ARTICLE_PATH) embed["title"] = _("Moved {redirect}{article} to {title} over redirect").format(redirect="โคท " if "redirect" in change else "", article=change["title"], title=change["logparams"]["target_title"]) + if "move" in action_buttons: + custom_id = BUTTON_PREFIX + " move " + change["pageid"] + " " + change["title"] + if len(custom_id) <= 100: + embed.add_button(custom_id, _("Move back"), 2, {"id": None, "name": "๐Ÿ”‚"}) elif action == "protect/move_prot": link = create_article_path(change["logparams"]["oldtitle_title"], WIKI_ARTICLE_PATH) embed["title"] = _("Moved protection settings from {redirect}{article} to {title}").format(redirect="โคท " if "redirect" in change else "", article=change["logparams"]["oldtitle_title"], diff --git a/src/wiki.py b/src/wiki.py index 4d8938c..f2ace40 100644 --- a/src/wiki.py +++ b/src/wiki.py @@ -35,7 +35,7 @@ class Wiki: params = {"action": "query", "format": "json", "uselang": "content", "list": "tags|recentchanges", "meta": "allmessages|siteinfo", "utf8": 1, "tglimit": "max", "tgprop": "displayname", - "rcprop": "title|redirect|timestamp|ids|loginfo|parsedcomment|sizes|flags|tags|user", + "rcprop": "title|redirect|timestamp|ids|loginfo|parsedcomment|sizes|flags|tags|user|userid", "rclimit": amount, "rcshow": "!bot", "rctype": "edit|new|log|categorize", "ammessages": "recentchanges-page-added-to-category|recentchanges-page-removed-from-category|recentchanges-page-added-to-category-bundled|recentchanges-page-removed-from-category-bundled", "amenableparser": 1, "amincludelocal": 1, "siprop": "namespaces|general"} @@ -43,7 +43,7 @@ class Wiki: params = {"action": "query", "format": "json", "uselang": "content", "list": "tags|recentchanges", "meta": "siteinfo", "utf8": 1, "tglimit": "max", "rcshow": "!bot", "tgprop": "displayname", - "rcprop": "title|redirect|timestamp|ids|loginfo|parsedcomment|sizes|flags|tags|user", + "rcprop": "title|redirect|timestamp|ids|loginfo|parsedcomment|sizes|flags|tags|user|userid", "rclimit": amount, "rctype": "edit|new|log|categorize", "siprop": "namespaces|general"} try: response = await session.get(url_path, params=params) From 116e159d191048509d413019afaadd388f41739f Mon Sep 17 00:00:00 2001 From: MarkusRost <2701034-MarkusRost@users.noreply.gitlab.com> Date: Sat, 6 May 2023 17:30:54 +0200 Subject: [PATCH 2/5] get script path more nicely --- src/formatters/rc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/formatters/rc.py b/src/formatters/rc.py index ea54bbf..946b232 100644 --- a/src/formatters/rc.py +++ b/src/formatters/rc.py @@ -30,7 +30,7 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c WIKI_SCRIPT_PATH = paths[1] WIKI_ARTICLE_PATH = paths[2] WIKI_JUST_DOMAIN = paths[3] - BUTTON_PREFIX = "rc_/" + WIKI_SCRIPT_PATH.split('/', 3)[3] + BUTTON_PREFIX = "rc_/" + WIKI_SCRIPT_PATH[len(WIKI_JUST_DOMAIN):] action_buttons = message_target[0][2].split('|') if message_target[0][2] is not None else [] message_buttons = [] if action != "suppressed": @@ -628,7 +628,7 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha WIKI_SCRIPT_PATH = paths[1] WIKI_ARTICLE_PATH = paths[2] WIKI_JUST_DOMAIN = paths[3] - BUTTON_PREFIX = "rc_/" + WIKI_SCRIPT_PATH.split('/', 3)[3] + BUTTON_PREFIX = "rc_/" + WIKI_SCRIPT_PATH[len(WIKI_JUST_DOMAIN):] action_buttons = message_target[0][2].split('|') if message_target[0][2] is not None else [] embed = DiscordMessage("embed", action, message_target[1], wiki=WIKI_SCRIPT_PATH) if parsed_comment is None: From 04f38b5e6b34e88d709b40a31cc3610080b27ed4 Mon Sep 17 00:00:00 2001 From: MarkusRost <2701034-MarkusRost@users.noreply.gitlab.com> Date: Sat, 6 May 2023 17:50:59 +0200 Subject: [PATCH 3/5] forgot anon users --- src/discord.py | 2 ++ src/formatters/rc.py | 38 +++++++++++++++----------------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/discord.py b/src/discord.py index 473449c..6f8a4d0 100644 --- a/src/discord.py +++ b/src/discord.py @@ -126,6 +126,8 @@ class DiscordMessage: self.embed["fields"].append(dict(name=name, value=value, inline=inline)) def add_button(self, custom_id, label, style=2, emoji=None): + if len(custom_id) > 100: + return if "components" not in self.webhook_object: self.webhook_object["components"] = [{"type": 1, "components": []}] if len(self.webhook_object["components"][-1]["components"]) >= 5: diff --git a/src/formatters/rc.py b/src/formatters/rc.py index 946b232..0b88779 100644 --- a/src/formatters/rc.py +++ b/src/formatters/rc.py @@ -40,7 +40,7 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c author_url = link_formatter(create_article_path("User:{user}".format(user=change["user"]), WIKI_ARTICLE_PATH)) author = change["user"] if "block" in action_buttons: - message_buttons.append((BUTTON_PREFIX + " block " + change["userid"], _("Block user"), 4, {"id": None, "name": "๐Ÿšซ"})) + message_buttons.append((BUTTON_PREFIX + " block " + ( "#" + str(change["userid"]) if change["userid"] else change["user"] ), _("Block user"), 4, {"id": None, "name": "๐Ÿšซ"})) parsed_comment = "" if parsed_comment is None else " *("+parsed_comment+")*" if action in ["edit", "new"]: edit_link = link_formatter("{wiki}index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format( @@ -56,13 +56,13 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c if action == "edit": content = _("[{author}]({author_url}) edited [{article}]({edit_link}){comment} {bold}({sign}{edit_size}){bold}").format(author=author, author_url=author_url, article=change["title"], edit_link=edit_link, comment=parsed_comment, edit_size=edit_size, sign=sign, bold=bold) if "rollback" in action_buttons: - message_buttons.append((BUTTON_PREFIX + " rollback " + change["pageid"] + " " + change["userid"], _("Rollback"), 1, {"id": None, "name": "๐Ÿ”"})) + message_buttons.append((BUTTON_PREFIX + " rollback " + str(change["pageid"]) + " " + ( "#" + str(change["userid"]) if change["userid"] else change["user"] ), _("Rollback"), 1, {"id": None, "name": "๐Ÿ”"})) if "undo" in action_buttons: - message_buttons.append((BUTTON_PREFIX + " undo " + change["pageid"] + " " + change["revid"], _("Undo"), 2, {"id": None, "name": "๐Ÿ”‚"})) + message_buttons.append((BUTTON_PREFIX + " undo " + str(change["pageid"]) + " " + str(change["revid"]), _("Undo"), 2, {"id": None, "name": "๐Ÿ”‚"})) else: content = _("[{author}]({author_url}) created [{article}]({edit_link}){comment} {bold}({sign}{edit_size}){bold}").format(author=author, author_url=author_url, article=change["title"], edit_link=edit_link, comment=parsed_comment, edit_size=edit_size, sign=sign, bold=bold) if "delete" in action_buttons: - message_buttons.append((BUTTON_PREFIX + " delete " + change["pageid"], _("Delete"), 4, {"id": None, "name": "๐Ÿ—‘๏ธ"})) + message_buttons.append((BUTTON_PREFIX + " delete " + str(change["pageid"]), _("Delete"), 4, {"id": None, "name": "๐Ÿ—‘๏ธ"})) elif action =="upload/upload": file_link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH)) content = _("[{author}]({author_url}) uploaded [{file}]({file_link}){comment}").format(author=author, @@ -71,7 +71,7 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c file_link=file_link, comment=parsed_comment) if "delete" in action_buttons: - message_buttons.append((BUTTON_PREFIX + " delete " + change["pageid"], _("Delete"), 4, {"id": None, "name": "๐Ÿ—‘๏ธ"})) + message_buttons.append((BUTTON_PREFIX + " delete " + str(change["pageid"]), _("Delete"), 4, {"id": None, "name": "๐Ÿ—‘๏ธ"})) elif action == "upload/revert": file_link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH)) content = _("[{author}]({author_url}) reverted a version of [{file}]({file_link}){comment}").format( @@ -93,9 +93,7 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c 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=change["logparams"]['target_title'], target_url=link, comment=parsed_comment, made_a_redirect=redirect_status) if "move" in action_buttons: - custom_id = BUTTON_PREFIX + " move " + change["pageid"] + " " + change["title"] - if len(custom_id) <= 100: - message_buttons.append((custom_id, _("Move back"), 2, {"id": None, "name": "๐Ÿ”‚"})) + message_buttons.append((BUTTON_PREFIX + " move " + str(change["pageid"]) + " " + change["title"], _("Move back"), 2, {"id": None, "name": "๐Ÿ”‚"})) elif action == "move/move_redir": link = link_formatter(create_article_path(change["logparams"]["target_title"], WIKI_ARTICLE_PATH)) redirect_status = _("without making a redirect") if "suppressredirect" in change["logparams"] else _( @@ -103,9 +101,7 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c 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=change["title"], target=change["logparams"]['target_title'], target_url=link, comment=parsed_comment, made_a_redirect=redirect_status) if "move" in action_buttons: - custom_id = BUTTON_PREFIX + " move " + change["pageid"] + " " + change["title"] - if len(custom_id) <= 100: - message_buttons.append((custom_id, _("Move back"), 2, {"id": None, "name": "๐Ÿ”‚"})) + message_buttons.append((BUTTON_PREFIX + " move " + str(change["pageid"]) + " " + change["title"], _("Move back"), 2, {"id": None, "name": "๐Ÿ”‚"})) elif action == "protect/move_prot": link = link_formatter(create_article_path(change["logparams"]["oldtitle_title"], WIKI_ARTICLE_PATH)) content = _( @@ -640,7 +636,7 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha author_url = create_article_path("User:{}".format(change["user"]), WIKI_ARTICLE_PATH) embed.set_author(change["user"], author_url) if "block" in action_buttons: - embed.add_button(BUTTON_PREFIX + " block " + change["userid"], _("Block user"), 4, {"id": None, "name": "๐Ÿšซ"}) + embed.add_button(BUTTON_PREFIX + " block " + ( "#" + str(change["userid"]) if change["userid"] else change["user"] ), _("Block user"), 4, {"id": None, "name": "๐Ÿšซ"}) if action in ("edit", "new"): # edit or new page editsize = change["newlen"] - change["oldlen"] if editsize > 0: @@ -696,12 +692,12 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha else: logger.warning("Unable to download data on the edit content!") if action == "new" and "delete" in action_buttons: - embed.add_button(BUTTON_PREFIX + " delete " + change["pageid"], _("Delete"), 4, {"id": None, "name": "๐Ÿ—‘๏ธ"}) + embed.add_button(BUTTON_PREFIX + " delete " + str(change["pageid"]), _("Delete"), 4, {"id": None, "name": "๐Ÿ—‘๏ธ"}) if action == "edit": if "rollback" in action_buttons: - embed.add_button(BUTTON_PREFIX + " rollback " + change["pageid"] + " " + change["userid"], _("Rollback"), 1, {"id": None, "name": "๐Ÿ”"}) + embed.add_button(BUTTON_PREFIX + " rollback " + str(change["pageid"]) + " " + ( "#" + str(change["userid"]) if change["userid"] else change["user"] ), _("Rollback"), 1, {"id": None, "name": "๐Ÿ”"}) if "undo" in action_buttons: - embed.add_button(BUTTON_PREFIX + " undo " + change["pageid"] + " " + change["revid"], _("Undo"), 2, {"id": None, "name": "๐Ÿ”‚"}) + embed.add_button(BUTTON_PREFIX + " undo " + str(change["pageid"]) + " " + str(change["revid"]), _("Undo"), 2, {"id": None, "name": "๐Ÿ”‚"}) elif action in ("upload/overwrite", "upload/upload", "upload/revert"): # sending files license = None try: @@ -741,7 +737,7 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha embed.add_field(_("Options"), _("([preview]({link}) | [undo]({undolink}))").format( link=image_direct_url, undolink=undolink)) if "filerevert" in action_buttons: - embed.add_button(BUTTON_PREFIX + " file " + change["pageid"] + " " + revision["archivename"].split("!")[0], _("Revert"), 2, {"id": None, "name": "๐Ÿ”‚"}) + embed.add_button(BUTTON_PREFIX + " file " + str(change["pageid"]) + " " + revision["archivename"].split("!")[0], _("Revert"), 2, {"id": None, "name": "๐Ÿ”‚"}) if message_target[0][1] > 1: embed["image"]["url"] = image_direct_url if action == "upload/overwrite": @@ -755,7 +751,7 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha if message_target[0][1] > 1: embed["image"]["url"] = image_direct_url if "delete" in action_buttons: - embed.add_button(BUTTON_PREFIX + " delete " + change["pageid"], _("Delete"), 4, {"id": None, "name": "๐Ÿ—‘๏ธ"}) + embed.add_button(BUTTON_PREFIX + " delete " + str(change["pageid"]), _("Delete"), 4, {"id": None, "name": "๐Ÿ—‘๏ธ"}) elif action == "delete/delete": link = create_article_path(change["title"], WIKI_ARTICLE_PATH) embed["title"] = _("Deleted page {article}").format(article=change["title"]) @@ -769,17 +765,13 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha "A redirect has been made")) embed["title"] = _("Moved {redirect}{article} to {target}").format(redirect="โคท " if "redirect" in change else "", article=change["title"], target=change["logparams"]['target_title']) if "move" in action_buttons: - custom_id = BUTTON_PREFIX + " move " + change["pageid"] + " " + change["title"] - if len(custom_id) <= 100: - embed.add_button(custom_id, _("Move back"), 2, {"id": None, "name": "๐Ÿ”‚"}) + embed.add_button(BUTTON_PREFIX + " move " + str(change["pageid"]) + " " + change["title"], _("Move back"), 2, {"id": None, "name": "๐Ÿ”‚"}) elif action == "move/move_redir": link = create_article_path(change["logparams"]["target_title"], WIKI_ARTICLE_PATH) embed["title"] = _("Moved {redirect}{article} to {title} over redirect").format(redirect="โคท " if "redirect" in change else "", article=change["title"], title=change["logparams"]["target_title"]) if "move" in action_buttons: - custom_id = BUTTON_PREFIX + " move " + change["pageid"] + " " + change["title"] - if len(custom_id) <= 100: - embed.add_button(custom_id, _("Move back"), 2, {"id": None, "name": "๐Ÿ”‚"}) + embed.add_button(BUTTON_PREFIX + " move " + str(change["pageid"]) + " " + change["title"], _("Move back"), 2, {"id": None, "name": "๐Ÿ”‚"}) elif action == "protect/move_prot": link = create_article_path(change["logparams"]["oldtitle_title"], WIKI_ARTICLE_PATH) embed["title"] = _("Moved protection settings from {redirect}{article} to {title}").format(redirect="โคท " if "redirect" in change else "", article=change["logparams"]["oldtitle_title"], From 7dd97fc6d7fe7201c67736b81237b402462a3930 Mon Sep 17 00:00:00 2001 From: MarkusRost <2701034-MarkusRost@users.noreply.gitlab.com> Date: Sat, 6 May 2023 18:47:56 +0200 Subject: [PATCH 4/5] fix BUTTON_PREFIX --- src/formatters/rc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/formatters/rc.py b/src/formatters/rc.py index 0b88779..fbe4df4 100644 --- a/src/formatters/rc.py +++ b/src/formatters/rc.py @@ -30,7 +30,7 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c WIKI_SCRIPT_PATH = paths[1] WIKI_ARTICLE_PATH = paths[2] WIKI_JUST_DOMAIN = paths[3] - BUTTON_PREFIX = "rc_/" + WIKI_SCRIPT_PATH[len(WIKI_JUST_DOMAIN):] + BUTTON_PREFIX = "rc_" + WIKI_SCRIPT_PATH[len(WIKI_JUST_DOMAIN):] action_buttons = message_target[0][2].split('|') if message_target[0][2] is not None else [] message_buttons = [] if action != "suppressed": @@ -624,7 +624,7 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha WIKI_SCRIPT_PATH = paths[1] WIKI_ARTICLE_PATH = paths[2] WIKI_JUST_DOMAIN = paths[3] - BUTTON_PREFIX = "rc_/" + WIKI_SCRIPT_PATH[len(WIKI_JUST_DOMAIN):] + BUTTON_PREFIX = "rc_" + WIKI_SCRIPT_PATH[len(WIKI_JUST_DOMAIN):] action_buttons = message_target[0][2].split('|') if message_target[0][2] is not None else [] embed = DiscordMessage("embed", action, message_target[1], wiki=WIKI_SCRIPT_PATH) if parsed_comment is None: From 15f2f2aa6ae4656803a12bc7e81fab619904e1ea Mon Sep 17 00:00:00 2001 From: MarkusRost <2701034-MarkusRost@users.noreply.gitlab.com> Date: Sun, 7 May 2023 12:17:45 +0000 Subject: [PATCH 5/5] change block emoji to something visible --- src/formatters/rc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/formatters/rc.py b/src/formatters/rc.py index fbe4df4..d53433b 100644 --- a/src/formatters/rc.py +++ b/src/formatters/rc.py @@ -40,7 +40,7 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c author_url = link_formatter(create_article_path("User:{user}".format(user=change["user"]), WIKI_ARTICLE_PATH)) author = change["user"] if "block" in action_buttons: - message_buttons.append((BUTTON_PREFIX + " block " + ( "#" + str(change["userid"]) if change["userid"] else change["user"] ), _("Block user"), 4, {"id": None, "name": "๐Ÿšซ"})) + message_buttons.append((BUTTON_PREFIX + " block " + ( "#" + str(change["userid"]) if change["userid"] else change["user"] ), _("Block user"), 4, {"id": None, "name": "๐Ÿšง"})) parsed_comment = "" if parsed_comment is None else " *("+parsed_comment+")*" if action in ["edit", "new"]: edit_link = link_formatter("{wiki}index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format( @@ -636,7 +636,7 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha author_url = create_article_path("User:{}".format(change["user"]), WIKI_ARTICLE_PATH) embed.set_author(change["user"], author_url) if "block" in action_buttons: - embed.add_button(BUTTON_PREFIX + " block " + ( "#" + str(change["userid"]) if change["userid"] else change["user"] ), _("Block user"), 4, {"id": None, "name": "๐Ÿšซ"}) + embed.add_button(BUTTON_PREFIX + " block " + ( "#" + str(change["userid"]) if change["userid"] else change["user"] ), _("Block user"), 4, {"id": None, "name": "๐Ÿšง"}) if action in ("edit", "new"): # edit or new page editsize = change["newlen"] - change["oldlen"] if editsize > 0: