Merge branch 'testing' into 'master'

A few more issues fixed for 1.1

Closes #14

See merge request piotrex43/RcGcDw!4
This commit is contained in:
Frisk 2018-06-24 20:50:33 +00:00
commit 144f715fdc
5 changed files with 47 additions and 17 deletions

View file

@ -34,6 +34,8 @@ Explanation for settings:
`appearience` section with different types of actions and logs, and corresponding to them colors/icons. In here you can set custom icon or color!
`overview` bool value, sends a day overview to the channel if true.
`overview_time` **local machine time** at which the day overview will be sent.
`license_regex` if you have an unusual or translated template for applying licenses to images, you can modify this value with proper regex expression. The capturing group for license name should be named "license". **remember about double escaping the backslashes**
`license_regex_detect` a regex detecting a license, it differs from `license_regex` by the fact that it has to match only the beginning of license template. **remember about double escaping the backslashes**
### How to use ###
Make sure you have installed all of dependencies and **filled settings.json properly**. You can also use `pip install -r requirements.txt` to install dependencies automatically. If you are using Raspberry Pi you won't have newest Python version installed, you can use [this guide](https://gist.github.com/dschep/24aa61672a2092246eaca2824400d37f).

Binary file not shown.

View file

@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2018-06-23 17:33+0200\n"
"PO-Revision-Date: 2018-06-23 20:24+0200\n"
"Last-Translator: JSBM\n"
"PO-Revision-Date: 2018-06-24 11:03+0200\n"
"Last-Translator: Frisk <piotrex43@protonmail.ch>\n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
@ -61,11 +61,11 @@ msgstr ""
#: rcgcdw.py:137
msgid "Deleted page {article}"
msgstr "Suppresion de la page {article}"
msgstr "Suppression de la page {article}"
#: rcgcdw.py:140
msgid "Deleted redirect {article} by overwriting"
msgstr "Suppresion par écrasement de la redirection {article}"
msgstr "Suppression par écrasement de la redirection {article}"
#: rcgcdw.py:143
msgid "A redirect has been made"
@ -305,7 +305,7 @@ msgstr "Aucune activité"
#: rcgcdw.py:512
msgid " ({} actions)"
msgstr "({} actions)"
msgstr " ({} actions)"
#: rcgcdw.py:512
msgid "Admin actions"
@ -313,7 +313,7 @@ msgstr "Actions d'administrateur"
#: rcgcdw.py:512
msgid "Bytes changed"
msgstr "Octet modifié"
msgstr "Octets modifiés"
#: rcgcdw.py:512
msgid "Day score"

View file

@ -121,29 +121,36 @@ def webhook_formatter(action, STATIC, **params):
if article_content is None:
logging.warning("Something went wrong when getting license for the image")
return 0
content = list(article_content.values())[0]['revisions'][0]['*'].lower()
if "{{license" not in content and "{{lizenz" not in content: #de-mcw
license = _("**No license!**")
else:
matches = re.search(r"\{\{(license|lizenz)(\ |\|)(.*?)\}\}", content)
content = list(article_content.values())[0]['revisions'][0]['*']
try:
matches = re.search(re.compile(settings["license_regex"], re.IGNORECASE), content)
if matches is not None:
license = matches.group(3)
license = matches.group("license")
else:
license = "?"
if re.search(re.compile(settings["license_regex_detect"], re.IGNORECASE), content) is None:
license = _("**No license!**")
else:
license = "?"
except IndexError:
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!")
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 = "?"
embed["fields"] = [{"name": _("Options"), "value": _("([preview]({link}))").format(link=embed["image"]["url"])}]
params["desc"] = _("{desc}\nLicense: {license}").format(desc=params["desc"], license=license)
elif action == 6:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=params["title"].replace(" ", "_"))
embed["title"] = _("Deleted page {article}").format(article=params["title"])
elif action == 7:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=params["title"].replace(" ", "_"))
embed["title"] = _("Deleted redirect {article} by overwriting").format(article=params["title"])
elif action == 14:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=params["target"].replace(" ", "_"))
params["desc"] = "{supress}. {desc}".format(desc=params["desc"], supress=_("No redirect has been made") if params["supress"] == True else _("A redirect has been made"))
embed["title"] = _("Moved {article} to {target}").format(article = params["title"], target=params["target"])
elif action == 15:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=params["target"].replace(" ", "_"))
embed["title"] = _("Moved {article} to {title} over redirect").format(article=params["title"], title=params["target"])
elif action == 16:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
@ -302,6 +309,25 @@ def webhook_formatter(action, STATIC, **params):
headers = {'Content-Type': 'application/json'}
#logging.debug(data)
result = requests.post(settings["webhookURL"], data=formatted_embed, headers=headers)
if result.status_code != requests.codes.ok:
handle_discord_http(result.status_code, formatted_embed, headers)
def handle_discord_http(code, formatted_embed, headers):
if code == 204: #message went through
return
elif code == 400: #HTTP BAD REQUEST
logging.error("Following message has been rejected by Discord, please submit a bug on our bugtracker adding it:")
logging.error(formatted_embed)
elif code == 401: #HTTP UNAUTHORIZED
logging.error("Webhook URL is invalid or no longer in use, please replace it with proper one.")
elif code == 429:
logging.error("We are sending too many requests to the Discord, slowing down...")
time.sleep(20.0)
result = requests.post(settings["webhookURL"], data=formatted_embed, headers=headers) #TODO Replace this solution with less obscure one
elif code > 500 and code < 600:
logging.error("Discord have trouble processing the event, and because the HTTP code returned is 500> it means we blame them.")
time.sleep(20.0)
result = requests.post(settings["webhookURL"], data=formatted_embed, headers=headers)
def first_pass(change): #I've decided to split the embed formatter and change handler, maybe it's more messy this way, I don't know
parsedcomment = (BeautifulSoup(change["parsedcomment"], "lxml")).get_text()
@ -480,7 +506,7 @@ def day_overview(): #time.strftime('%Y-%m-%dT%H:%M:%S.000Z', time.gmtime(time.ti
if item["type"] == "log":
files = files+1 if item["logtype"] == item["logaction"] == "upload" else files
admin = admin+1 if item["logtype"] in ["delete", "merge", "block", "protect", "import", "rights", "abusefilter", "interwiki", "managetags"] else admin
overall = round(new_articles+edits*0.1+files*0.3+admin*0.1+changed_bytes*0.01, 2)
overall = round(new_articles+edits*0.1+files*0.3+admin*0.1+math.fabs(changed_bytes*0.001), 2)
embed = defaultdict(dict)
embed["title"] = _("Daily overview")
embed["url"] = "https://{wiki}.gamepedia.com/Special:Statistics".format(wiki=settings["wiki"])

View file

@ -18,6 +18,8 @@
"show_updown_messages": true,
"overview": false,
"overview_time": "00:00",
"license_regex_detect": "\\{\\{(license|lizenz|licence)",
"license_regex": "\\{\\{(license|lizenz|licence)(\\ |\\|)(?P<license>.*?)\\}\\}",
"appearance":{
"daily_overview": {
"color": 16312092,