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"],