This commit is contained in:
Frisk 2019-05-02 17:02:50 +02:00
parent e32ab0778c
commit 74ca419e35
No known key found for this signature in database
GPG key ID: 0E9A7D3C0A01586C
2 changed files with 29 additions and 26 deletions

View file

@ -516,36 +516,38 @@ def embed_formatter(action, change, parsed_comment, categories):
embed["title"] = _("Uploaded a new version of {name}").format(name=change["title"]) embed["title"] = _("Uploaded a new version of {name}").format(name=change["title"])
else: else:
embed["title"] = _("Uploaded {name}").format(name=change["title"]) embed["title"] = _("Uploaded {name}").format(name=change["title"])
article_content = safe_read(recent_changes.safe_request( if settings["license_detection"]:
"https://{wiki}.gamepedia.com/api.php?action=query&format=json&prop=revisions&titles={article}&rvprop=content".format( article_content = safe_read(recent_changes.safe_request(
wiki=settings["wiki"], article=quote_plus(change["title"], safe=''))), "query", "pages") "https://{wiki}.gamepedia.com/api.php?action=query&format=json&prop=revisions&titles={article}&rvprop=content".format(
if article_content is None: wiki=settings["wiki"], article=quote_plus(change["title"], safe=''))), "query", "pages")
logging.warning("Something went wrong when getting license for the image") if article_content is None:
return 0 logging.warning("Something went wrong when getting license for the image")
if "-1" not in article_content: return 0
content = list(article_content.values())[0]['revisions'][0]['*'] if "-1" not in article_content:
try: content = list(article_content.values())[0]['revisions'][0]['*']
matches = re.search(re.compile(settings["license_regex"], re.IGNORECASE), content) try:
if matches is not None: matches = re.search(re.compile(settings["license_regex"], re.IGNORECASE), content)
license = matches.group("license") if matches is not None:
else: license = matches.group("license")
if re.search(re.compile(settings["license_regex_detect"], re.IGNORECASE), content) is None:
license = _("**No license!**")
else: else:
license = "?" if re.search(re.compile(settings["license_regex_detect"], re.IGNORECASE), content) is None:
except IndexError: license = _("**No license!**")
logging.error( else:
"Given regex for the license detection is incorrect. It does not have a capturing group called \"license\" specified. Please fix license_regex value in the config!") license = "?"
license = "?" except IndexError:
except re.error: logging.error(
logging.error( "Given regex for the license detection is incorrect. It does not have a capturing group called \"license\" specified. Please fix license_regex value in the config!")
"Given regex for the license detection is incorrect. Please fix license_regex or license_regex_detect values in the config!") license = "?"
license = "?" except re.error:
logging.error(
"Given regex for the license detection is incorrect. Please fix license_regex or license_regex_detect values in the config!")
license = "?"
if license is not None:
parsed_comment += "\n{}".format(license)
if additional_info_retrieved: if additional_info_retrieved:
embed["fields"] = [ embed["fields"] = [
{"name": _("Options"), "value": _("([preview]({link}))").format(link=embed["image"]["url"])}] {"name": _("Options"), "value": _("([preview]({link}))").format(link=embed["image"]["url"])}]
parsed_comment = _("{desc}\nLicense: {license}").format(desc=parsed_comment,
license=license if license is not None else "?")
elif action == "delete/delete": elif action == "delete/delete":
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"],
article=change["title"].replace(" ", "_")) article=change["title"].replace(" ", "_"))

View file

@ -21,6 +21,7 @@
"overview": false, "overview": false,
"overview_time": "00:00", "overview_time": "00:00",
"send_empty_overview": false, "send_empty_overview": false,
"license_detection": true,
"license_regex_detect": "\\{\\{(license|lizenz|licence|copyright)", "license_regex_detect": "\\{\\{(license|lizenz|licence|copyright)",
"license_regex": "\\{\\{(license|lizenz|licence|copyright)(\\ |\\|)(?P<license>.*?)\\}\\}", "license_regex": "\\{\\{(license|lizenz|licence|copyright)(\\ |\\|)(?P<license>.*?)\\}\\}",
"wiki_bot_login": "", "wiki_bot_login": "",