mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
More work towards compatibility
This commit is contained in:
parent
1287b635c1
commit
f5b08c05e5
|
@ -64,7 +64,7 @@ def embed_edit(ctx: Context, change: dict) -> DiscordMessage:
|
||||||
article=sanitize_to_url(change["title"])
|
article=sanitize_to_url(change["title"])
|
||||||
)
|
)
|
||||||
embed["title"] = "{redirect}{article} ({new}{minor}{bot}{space}{editsize})".format(
|
embed["title"] = "{redirect}{article} ({new}{minor}{bot}{space}{editsize})".format(
|
||||||
redirect="⤷ " if "redirect" in change else "",
|
redirect="⤷ " if change.get("redirect", False) else "",
|
||||||
article=sanitize_to_markdown(change["title"]),
|
article=sanitize_to_markdown(change["title"]),
|
||||||
editsize="+" + str(editsize) if editsize > 0 else editsize,
|
editsize="+" + str(editsize) if editsize > 0 else editsize,
|
||||||
new=ctx._("(N!) ") if action == "new" else "",
|
new=ctx._("(N!) ") if action == "new" else "",
|
||||||
|
@ -75,12 +75,12 @@ def embed_edit(ctx: Context, change: dict) -> DiscordMessage:
|
||||||
try:
|
try:
|
||||||
if action == "new":
|
if action == "new":
|
||||||
changed_content = ctx.client.make_api_request(
|
changed_content = ctx.client.make_api_request(
|
||||||
"?action=compare&format=json&fromslots=main&torev={diff}&fromtext-main=&topst=1&prop=diff".format(
|
"?action=compare&format=json&formatversion=2&fromslots=main&torev={diff}&fromtext-main=&topst=1&prop=diff".format(
|
||||||
diff=change["revid"]), "compare", "*")
|
diff=change["revid"]), "compare", "body")
|
||||||
else:
|
else:
|
||||||
changed_content = ctx.client.make_api_request(
|
changed_content = ctx.client.make_api_request(
|
||||||
"?action=compare&format=json&fromrev={oldrev}&torev={diff}&topst=1&prop=diff".format(
|
"?action=compare&format=json&formatversion=2&fromrev={oldrev}&torev={diff}&topst=1&prop=diff".format(
|
||||||
diff=change["revid"], oldrev=change["old_revid"]), "compare", "*")
|
diff=change["revid"], oldrev=change["old_revid"]), "compare", "body")
|
||||||
except (ServerError, MediaWikiError):
|
except (ServerError, MediaWikiError):
|
||||||
changed_content = None
|
changed_content = None
|
||||||
if changed_content:
|
if changed_content:
|
||||||
|
@ -630,7 +630,7 @@ def embed_block_block(ctx: Context, change: dict):
|
||||||
if str(namespace) == "0":
|
if str(namespace) == "0":
|
||||||
namespaces.append("*{ns}*".format(ns=ctx._("(Main)")))
|
namespaces.append("*{ns}*".format(ns=ctx._("(Main)")))
|
||||||
elif str(namespace) in ctx.client.namespaces: # if we have cached namespace name for given namespace number, add its name to the list
|
elif str(namespace) in ctx.client.namespaces: # if we have cached namespace name for given namespace number, add its name to the list
|
||||||
namespaces.append("*{ns}*".format(ns=ctx.client.namespaces[str(namespace)]["*"]))
|
namespaces.append("*{ns}*".format(ns=ctx.client.namespaces[str(namespace)]["name"]))
|
||||||
else:
|
else:
|
||||||
namespaces.append("*{ns}*".format(ns=namespace))
|
namespaces.append("*{ns}*".format(ns=namespace))
|
||||||
restriction_description = restriction_description + ", ".join(namespaces)
|
restriction_description = restriction_description + ", ".join(namespaces)
|
||||||
|
@ -678,7 +678,7 @@ def compact_block_block(ctx: Context, change: dict):
|
||||||
if str(namespace) == "0":
|
if str(namespace) == "0":
|
||||||
namespaces.append("*{ns}*".format(ns=ctx._("(Main)")))
|
namespaces.append("*{ns}*".format(ns=ctx._("(Main)")))
|
||||||
elif str(namespace) in ctx.client.namespaces: # if we have cached namespace name for given namespace number, add its name to the list
|
elif str(namespace) in ctx.client.namespaces: # if we have cached namespace name for given namespace number, add its name to the list
|
||||||
namespaces.append("*{ns}*".format(ns=ctx.client.namespaces[str(namespace)]["*"]))
|
namespaces.append("*{ns}*".format(ns=ctx.client.namespaces[str(namespace)]["name"]))
|
||||||
else:
|
else:
|
||||||
namespaces.append("*{ns}*".format(ns=namespace))
|
namespaces.append("*{ns}*".format(ns=namespace))
|
||||||
restriction_description = restriction_description + ", ".join(namespaces)
|
restriction_description = restriction_description + ", ".join(namespaces)
|
||||||
|
|
|
@ -49,7 +49,7 @@ talk_notify = settings.get("hooks", {}).get("talk_notify", {})
|
||||||
def talk_notify_hook(context: Context, change: dict):
|
def talk_notify_hook(context: Context, change: dict):
|
||||||
if not talk_notify.get("default", []) or context.event not in ("edit", "new"):
|
if not talk_notify.get("default", []) or context.event not in ("edit", "new"):
|
||||||
return
|
return
|
||||||
if "minor" in change or change["ns"] == 3:
|
if change.get("minor", False) or change["ns"] == 3:
|
||||||
return
|
return
|
||||||
ignore = change["ns"] % 2 == 0
|
ignore = change["ns"] % 2 == 0
|
||||||
if ignore and talk_notify.get("extra_pages", {}):
|
if ignore and talk_notify.get("extra_pages", {}):
|
||||||
|
|
10
src/misc.py
10
src/misc.py
|
@ -245,14 +245,14 @@ def safe_read(request, *keys):
|
||||||
def parse_mw_request_info(request_data: dict, url: str):
|
def parse_mw_request_info(request_data: dict, url: str):
|
||||||
"""A function parsing request JSON message from MediaWiki logging all warnings and raising on MediaWiki errors"""
|
"""A function parsing request JSON message from MediaWiki logging all warnings and raising on MediaWiki errors"""
|
||||||
# any([True for k in request_data.keys() if k in ("error", "errors")])
|
# any([True for k in request_data.keys() if k in ("error", "errors")])
|
||||||
errors: list = request_data.get("errors", {}) # Is it ugly? I don't know tbh
|
errors: dict = request_data.get("errors", {}) # Is it ugly? I don't know tbh
|
||||||
if errors:
|
if errors:
|
||||||
raise MediaWikiError(str(errors))
|
raise MediaWikiError(str(errors))
|
||||||
warnings: list = request_data.get("warnings", {})
|
warnings: dict = request_data.get("warnings", {})
|
||||||
if warnings:
|
if warnings:
|
||||||
for warning in warnings:
|
for module, warning_data in warnings.items():
|
||||||
misc_logger.warning("MediaWiki returned the following warning: {code} - {text} on {url}.".format(
|
misc_logger.warning("MediaWiki returned the following warning on module {module}: {text} on {url}.".format(
|
||||||
code=warning["code"], text=warning.get("text", warning.get("*", "")), url=url
|
module=module, text=warning_data.get("warnings", ""), url=url
|
||||||
))
|
))
|
||||||
return request_data
|
return request_data
|
||||||
|
|
||||||
|
|
14
src/wiki.py
14
src/wiki.py
|
@ -259,10 +259,10 @@ class Wiki(object):
|
||||||
abuselog = request_json["query"]["abuselog"] # While LYBL approach would be more performant when abuselog is not in request body, I prefer this approach for its clarity
|
abuselog = request_json["query"]["abuselog"] # While LYBL approach would be more performant when abuselog is not in request body, I prefer this approach for its clarity
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if "warnings" in request_json:
|
if "warnings" in request_json:
|
||||||
warnings = request_json.get("warnings", {"query": {"*": ""}})
|
warnings = request_json.get("warnings", {"query": {"warnings": ""}})
|
||||||
if "Unrecognized value for parameter \"list\": abuselog." in warnings["query"]["*"]:
|
if "Unrecognized value for parameter \"list\": abuselog." in warnings["query"]["warnings"]:
|
||||||
settings["show_abuselog"] = False
|
settings["show_abuselog"] = False
|
||||||
logger.warning("AbuseLog extension is not enabled on the wiki. Disabling the function...")
|
logger.warning("AbuseLog extension is not enabled on the wiki. Disabling the function for this session...")
|
||||||
else:
|
else:
|
||||||
abuselog_last_id = self.prepare_abuse_log(abuselog)
|
abuselog_last_id = self.prepare_abuse_log(abuselog)
|
||||||
return rc_last_id, abuselog_last_id
|
return rc_last_id, abuselog_last_id
|
||||||
|
@ -432,13 +432,13 @@ class Wiki(object):
|
||||||
if startup_info:
|
if startup_info:
|
||||||
if "tags" in startup_info and "allmessages" in startup_info:
|
if "tags" in startup_info and "allmessages" in startup_info:
|
||||||
for tag in startup_info["tags"]:
|
for tag in startup_info["tags"]:
|
||||||
try:
|
if tag["displayname"]:
|
||||||
self.tags[tag["name"]] = (BeautifulSoup(tag["displayname"], "lxml")).get_text()
|
self.tags[tag["name"]] = (BeautifulSoup(tag["displayname"], "lxml")).get_text()
|
||||||
except KeyError:
|
else:
|
||||||
self.tags[tag["name"]] = None # Tags with no display name are hidden and should not appear on RC as well
|
self.tags[tag["name"]] = None # Tags with no display name are hidden and should not appear on RC as well
|
||||||
for message in startup_info["allmessages"]:
|
for message in startup_info["allmessages"]:
|
||||||
if "missing" not in message: # ignore missing strings
|
if message.get("missing", False) is False: # ignore missing strings
|
||||||
self.mw_messages[message["name"]] = message["*"]
|
self.mw_messages[message["name"]] = message["content"]
|
||||||
else:
|
else:
|
||||||
logging.warning("Could not fetch the MW message translation for: {}".format(message["name"]))
|
logging.warning("Could not fetch the MW message translation for: {}".format(message["name"]))
|
||||||
for key, message in self.mw_messages.items():
|
for key, message in self.mw_messages.items():
|
||||||
|
|
Loading…
Reference in a new issue