mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Merge remote-tracking branch 'origin/buttons'
This commit is contained in:
commit
278b3dea6f
|
@ -240,8 +240,8 @@ async def generate_targets(wiki_url: str, additional_requirements: str) -> defau
|
||||||
combinations = defaultdict(list)
|
combinations = defaultdict(list)
|
||||||
async with db.pool().acquire() as connection:
|
async with db.pool().acquire() as connection:
|
||||||
async with connection.transaction():
|
async with connection.transaction():
|
||||||
async for webhook in connection.cursor('SELECT webhook, lang, display FROM rcgcdw WHERE wiki = $1 {}'.format(additional_requirements), wiki_url):
|
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"])
|
combination = (webhook["lang"], webhook["display"], webhook["buttons"])
|
||||||
combinations[combination].append(webhook["webhook"])
|
combinations[combination].append(webhook["webhook"])
|
||||||
return combinations
|
return combinations
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,15 @@ class DiscordMessage:
|
||||||
self.length += len(name) + len(value)
|
self.length += len(name) + len(value)
|
||||||
self.embed["fields"].append(dict(name=name, value=value, inline=inline))
|
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:
|
||||||
|
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):
|
def set_avatar(self, url):
|
||||||
self.webhook_object["avatar_url"] = url
|
self.webhook_object["avatar_url"] = url
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,17 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c
|
||||||
WIKI_SCRIPT_PATH = paths[1]
|
WIKI_SCRIPT_PATH = paths[1]
|
||||||
WIKI_ARTICLE_PATH = paths[2]
|
WIKI_ARTICLE_PATH = paths[2]
|
||||||
WIKI_JUST_DOMAIN = paths[3]
|
WIKI_JUST_DOMAIN = paths[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":
|
if action != "suppressed":
|
||||||
if "anon" in change:
|
if "anon" in change:
|
||||||
author_url = link_formatter(create_article_path("Special:Contributions/{user}".format(user=change["user"]), WIKI_ARTICLE_PATH))
|
author_url = link_formatter(create_article_path("Special:Contributions/{user}".format(user=change["user"]), WIKI_ARTICLE_PATH))
|
||||||
else:
|
else:
|
||||||
author_url = link_formatter(create_article_path("User:{user}".format(user=change["user"]), WIKI_ARTICLE_PATH))
|
author_url = link_formatter(create_article_path("User:{user}".format(user=change["user"]), WIKI_ARTICLE_PATH))
|
||||||
author = change["user"]
|
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": "🚧"}))
|
||||||
parsed_comment = "" if parsed_comment is None else " *("+parsed_comment+")*"
|
parsed_comment = "" if parsed_comment is None else " *("+parsed_comment+")*"
|
||||||
if action in ["edit", "new"]:
|
if action in ["edit", "new"]:
|
||||||
edit_link = link_formatter("{wiki}index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format(
|
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 = "**"
|
bold = "**"
|
||||||
if action == "edit":
|
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)
|
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 " + 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 " + str(change["pageid"]) + " " + str(change["revid"]), _("Undo"), 2, {"id": None, "name": "🔂"}))
|
||||||
else:
|
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)
|
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 " + str(change["pageid"]), _("Delete"), 4, {"id": None, "name": "🗑️"}))
|
||||||
elif action =="upload/upload":
|
elif action =="upload/upload":
|
||||||
file_link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
|
file_link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
|
||||||
content = _("[{author}]({author_url}) uploaded [{file}]({file_link}){comment}").format(author=author,
|
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=change["title"],
|
||||||
file_link=file_link,
|
file_link=file_link,
|
||||||
comment=parsed_comment)
|
comment=parsed_comment)
|
||||||
|
if "delete" in action_buttons:
|
||||||
|
message_buttons.append((BUTTON_PREFIX + " delete " + str(change["pageid"]), _("Delete"), 4, {"id": None, "name": "🗑️"}))
|
||||||
elif action == "upload/revert":
|
elif action == "upload/revert":
|
||||||
file_link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
|
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(
|
content = _("[{author}]({author_url}) reverted a version of [{file}]({file_link}){comment}").format(
|
||||||
|
@ -79,12 +92,16 @@ 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")
|
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"],
|
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)
|
target=change["logparams"]['target_title'], target_url=link, comment=parsed_comment, made_a_redirect=redirect_status)
|
||||||
|
if "move" in action_buttons:
|
||||||
|
message_buttons.append((BUTTON_PREFIX + " move " + str(change["pageid"]) + " " + change["title"], _("Move back"), 2, {"id": None, "name": "🔂"}))
|
||||||
elif action == "move/move_redir":
|
elif action == "move/move_redir":
|
||||||
link = link_formatter(create_article_path(change["logparams"]["target_title"], WIKI_ARTICLE_PATH))
|
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 _(
|
redirect_status = _("without making a redirect") if "suppressredirect" in change["logparams"] else _(
|
||||||
"with a redirect")
|
"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"],
|
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)
|
target=change["logparams"]['target_title'], target_url=link, comment=parsed_comment, made_a_redirect=redirect_status)
|
||||||
|
if "move" in action_buttons:
|
||||||
|
message_buttons.append((BUTTON_PREFIX + " move " + str(change["pageid"]) + " " + change["title"], _("Move back"), 2, {"id": None, "name": "🔂"}))
|
||||||
elif action == "protect/move_prot":
|
elif action == "protect/move_prot":
|
||||||
link = link_formatter(create_article_path(change["logparams"]["oldtitle_title"], WIKI_ARTICLE_PATH))
|
link = link_formatter(create_article_path(change["logparams"]["oldtitle_title"], WIKI_ARTICLE_PATH))
|
||||||
content = _(
|
content = _(
|
||||||
|
@ -591,7 +608,10 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c
|
||||||
else:
|
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"])
|
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"
|
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:
|
async def embed_formatter(action, change, parsed_comment, categories, recent_changes, message_target, paths, rate_limiter, additional_data=None) -> DiscordMessage:
|
||||||
|
@ -604,6 +624,8 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha
|
||||||
WIKI_SCRIPT_PATH = paths[1]
|
WIKI_SCRIPT_PATH = paths[1]
|
||||||
WIKI_ARTICLE_PATH = paths[2]
|
WIKI_ARTICLE_PATH = paths[2]
|
||||||
WIKI_JUST_DOMAIN = paths[3]
|
WIKI_JUST_DOMAIN = paths[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)
|
embed = DiscordMessage("embed", action, message_target[1], wiki=WIKI_SCRIPT_PATH)
|
||||||
if parsed_comment is None:
|
if parsed_comment is None:
|
||||||
parsed_comment = _("No description provided")
|
parsed_comment = _("No description provided")
|
||||||
|
@ -613,6 +635,8 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha
|
||||||
else:
|
else:
|
||||||
author_url = create_article_path("User:{}".format(change["user"]), WIKI_ARTICLE_PATH)
|
author_url = create_article_path("User:{}".format(change["user"]), WIKI_ARTICLE_PATH)
|
||||||
embed.set_author(change["user"], author_url)
|
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": "🚧"})
|
||||||
if action in ("edit", "new"): # edit or new page
|
if action in ("edit", "new"): # edit or new page
|
||||||
editsize = change["newlen"] - change["oldlen"]
|
editsize = change["newlen"] - change["oldlen"]
|
||||||
if editsize > 0:
|
if editsize > 0:
|
||||||
|
@ -667,6 +691,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)
|
embed.add_field(_("Added"), "{data}".format(data=EditDiff.small_prev_ins), inline=True)
|
||||||
else:
|
else:
|
||||||
logger.warning("Unable to download data on the edit content!")
|
logger.warning("Unable to download data on the edit content!")
|
||||||
|
if action == "new" and "delete" in action_buttons:
|
||||||
|
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 " + 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 " + str(change["pageid"]) + " " + str(change["revid"]), _("Undo"), 2, {"id": None, "name": "🔂"})
|
||||||
elif action in ("upload/overwrite", "upload/upload", "upload/revert"): # sending files
|
elif action in ("upload/overwrite", "upload/upload", "upload/revert"): # sending files
|
||||||
license = None
|
license = None
|
||||||
try:
|
try:
|
||||||
|
@ -705,6 +736,8 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha
|
||||||
wiki=WIKI_SCRIPT_PATH, filename=article_encoded, archiveid=revision["archivename"])
|
wiki=WIKI_SCRIPT_PATH, filename=article_encoded, archiveid=revision["archivename"])
|
||||||
embed.add_field(_("Options"), _("([preview]({link}) | [undo]({undolink}))").format(
|
embed.add_field(_("Options"), _("([preview]({link}) | [undo]({undolink}))").format(
|
||||||
link=image_direct_url, undolink=undolink))
|
link=image_direct_url, undolink=undolink))
|
||||||
|
if "filerevert" in action_buttons:
|
||||||
|
embed.add_button(BUTTON_PREFIX + " file " + str(change["pageid"]) + " " + revision["archivename"].split("!")[0], _("Revert"), 2, {"id": None, "name": "🔂"})
|
||||||
if message_target[0][1] > 1:
|
if message_target[0][1] > 1:
|
||||||
embed["image"]["url"] = image_direct_url
|
embed["image"]["url"] = image_direct_url
|
||||||
if action == "upload/overwrite":
|
if action == "upload/overwrite":
|
||||||
|
@ -717,6 +750,8 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha
|
||||||
embed.add_field(_("Options"), _("([preview]({link}))").format(link=image_direct_url))
|
embed.add_field(_("Options"), _("([preview]({link}))").format(link=image_direct_url))
|
||||||
if message_target[0][1] > 1:
|
if message_target[0][1] > 1:
|
||||||
embed["image"]["url"] = image_direct_url
|
embed["image"]["url"] = image_direct_url
|
||||||
|
if "delete" in action_buttons:
|
||||||
|
embed.add_button(BUTTON_PREFIX + " delete " + str(change["pageid"]), _("Delete"), 4, {"id": None, "name": "🗑️"})
|
||||||
elif action == "delete/delete":
|
elif action == "delete/delete":
|
||||||
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
|
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
|
||||||
embed["title"] = _("Deleted page {article}").format(article=change["title"])
|
embed["title"] = _("Deleted page {article}").format(article=change["title"])
|
||||||
|
@ -729,10 +764,14 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha
|
||||||
supress=_("No redirect has been made") if "suppressredirect" in change["logparams"] else _(
|
supress=_("No redirect has been made") if "suppressredirect" in change["logparams"] else _(
|
||||||
"A redirect has been made"))
|
"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'])
|
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:
|
||||||
|
embed.add_button(BUTTON_PREFIX + " move " + str(change["pageid"]) + " " + change["title"], _("Move back"), 2, {"id": None, "name": "🔂"})
|
||||||
elif action == "move/move_redir":
|
elif action == "move/move_redir":
|
||||||
link = create_article_path(change["logparams"]["target_title"], WIKI_ARTICLE_PATH)
|
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"],
|
embed["title"] = _("Moved {redirect}{article} to {title} over redirect").format(redirect="⤷ " if "redirect" in change else "", article=change["title"],
|
||||||
title=change["logparams"]["target_title"])
|
title=change["logparams"]["target_title"])
|
||||||
|
if "move" in action_buttons:
|
||||||
|
embed.add_button(BUTTON_PREFIX + " move " + str(change["pageid"]) + " " + change["title"], _("Move back"), 2, {"id": None, "name": "🔂"})
|
||||||
elif action == "protect/move_prot":
|
elif action == "protect/move_prot":
|
||||||
link = create_article_path(change["logparams"]["oldtitle_title"], WIKI_ARTICLE_PATH)
|
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"],
|
embed["title"] = _("Moved protection settings from {redirect}{article} to {title}").format(redirect="⤷ " if "redirect" in change else "", article=change["logparams"]["oldtitle_title"],
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Wiki:
|
||||||
params = {"action": "query", "format": "json", "uselang": "content", "list": "tags|recentchanges",
|
params = {"action": "query", "format": "json", "uselang": "content", "list": "tags|recentchanges",
|
||||||
"meta": "allmessages|siteinfo",
|
"meta": "allmessages|siteinfo",
|
||||||
"utf8": 1, "tglimit": "max", "tgprop": "displayname",
|
"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",
|
"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",
|
"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"}
|
"amenableparser": 1, "amincludelocal": 1, "siprop": "namespaces|general"}
|
||||||
|
@ -43,7 +43,7 @@ class Wiki:
|
||||||
params = {"action": "query", "format": "json", "uselang": "content", "list": "tags|recentchanges",
|
params = {"action": "query", "format": "json", "uselang": "content", "list": "tags|recentchanges",
|
||||||
"meta": "siteinfo", "utf8": 1,
|
"meta": "siteinfo", "utf8": 1,
|
||||||
"tglimit": "max", "rcshow": "!bot", "tgprop": "displayname",
|
"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"}
|
"rclimit": amount, "rctype": "edit|new|log|categorize", "siprop": "namespaces|general"}
|
||||||
try:
|
try:
|
||||||
response = await session.get(url_path, params=params)
|
response = await session.get(url_path, params=params)
|
||||||
|
|
Loading…
Reference in a new issue