From fd9c38bb76e76c16641c5342b92ac9f5b3c1a6c2 Mon Sep 17 00:00:00 2001 From: Frisk Date: Sun, 24 Jun 2018 02:16:49 +0200 Subject: [PATCH 1/8] Fixed fr translation --- locale/fr/LC_MESSAGES/rcgcdw.mo | Bin 6867 -> 6870 bytes locale/fr/LC_MESSAGES/rcgcdw.po | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/locale/fr/LC_MESSAGES/rcgcdw.mo b/locale/fr/LC_MESSAGES/rcgcdw.mo index c81bd40d35ad98e3ff242f615024923aa106f26c..d9fdba65346e37cd11a3871a3ab365952675bb50 100644 GIT binary patch delta 710 zcmXZaJ4ixd6u|M5VYi3bOHC_Fi;5nQUbBbM(2ItKB7&%Jv>_sbf`*2>I7GBbQ!UaG z6%j~8W6%^7^c)(Zp&^2%cIkgmxZL0QK8}9pocldT-=Y_{Hmh7j{whW6SWqR>g$CAO zB=00Pv0g$_WgGpthaGr=UVOn${6)?4R*N{X1BY+`+i(-Zcu*~t3=-V45krGhCvX(C zfE`{9c!(jq##;PAE!^f331TIhXksHKP#Z~N057l~A2EU@?p*$`+sgg%Ivd(y8k_M3 zefWiXP!`M3;mLL4MJ;3wdvO)Dz%**!6ZYT-Y9UUNH9wYj7DrgGSOo0^XV`}?$n>O) zd8&S7IMRc4IEn_wu^1Crk89YCyU3Yxg<8l1w&FW#q1u%;7Ufln)--`8E}{dMQNP^= zwqO!<#K*`Gz4N2Ch7aTJHJ6E`t}haNFygyMmTINDfs0u!hK z(!3h+2*a4gTKvLFw0K2Y(S-&^uo;(8H?oTw`~nB@5u<4H75d{ov+&33OladVw&69_ z;|J4}5$ zR0GK2NC*QshIUM$0~fIY*D!=>WKFq34RVhi_<|ZVkGe5~S2>!~6xukCdKZ>ZzugA5 z;|}T(pCX4Kcc=m0QFr`_JmM#v&WBNh4WkVc#qkuDFixW0wK?Q>0ZCElW!gerU?24o jon;oR Date: Sun, 24 Jun 2018 11:05:20 +0200 Subject: [PATCH 2/8] Updated fr translation --- locale/fr/LC_MESSAGES/rcgcdw.mo | Bin 6870 -> 6872 bytes locale/fr/LC_MESSAGES/rcgcdw.po | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/fr/LC_MESSAGES/rcgcdw.mo b/locale/fr/LC_MESSAGES/rcgcdw.mo index d9fdba65346e37cd11a3871a3ab365952675bb50..0145d2caf5066589098194c775b8f8311327bdcb 100644 GIT binary patch delta 610 zcmXZZze_?<6u|L=WtnD~nUz-BZ~6iGQWLF+K-(IE5QM-bGNE521x;^rsP?96a4IMw zr)YEy3JPgxh=zvfkLY_axZKZuhkNcl=e}z6J$g4(XSzgW%q=pD2^_&gH1Hhb_>2i` zY8Odi5*c#L)Polo!bj}HUvy%NzFUeQ!90pI)<8iHqHuF!%2&F7myFqj-xm zSj9GUcGV0Zk0S>9Fo}(rMH}YOk9#7Vw4I@eeY@PjwoPq82uf4H#eg4=kgFKpL%>K~2nJFCL*@ naE9Y}Q_fgZcB^3|Lg8|$^~B;R1h;qB^BeifRiPYnU)ufvFiJh( delta 608 zcmXZYyGw#$6vy#{Vdf<>GtJ~}j3=ZQSM(_mV_=pL# zw27oKg?w_r(2b`U##`*bUu;H`N2Cv3XrO^Tn8R@_d88;oCKU?P_>57sw%0byq8_}1 zy;#P6yhA^Jqh9ofc64}ajrdT5WN;EUP|qo&u6w}{etL_wBu-ZAhD6;Zoa28TNAMb_ z@D*Fp?yDI<9!Emhi7B*T7Mn1KUATo4c!=CBH>g3LicE%>e4r-PwzRVtgAEr^7p|fM z^XS4|9KaIl6JH>YAP=YkzEC^\n" "Language-Team: \n" "Language: fr\n" "MIME-Version: 1.0\n" @@ -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" From 834197a9b59cfdae6f96312c7d010961051153db Mon Sep 17 00:00:00 2001 From: Frisk Date: Sun, 24 Jun 2018 11:45:30 +0200 Subject: [PATCH 3/8] Temporary fixes to regex, fixed #14 --- rcgcdw.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rcgcdw.py b/rcgcdw.py index 59e86eb..421ee4c 100644 --- a/rcgcdw.py +++ b/rcgcdw.py @@ -122,10 +122,10 @@ def webhook_formatter(action, STATIC, **params): 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 + if "{{license" not in content and "{{lizenz" not in content and "{{licence" not in content: license = _("**No license!**") else: - matches = re.search(r"\{\{(license|lizenz)(\ |\|)(.*?)\}\}", content) + matches = re.search(r"\{\{(license|lizenz|licence)(\ |\|)(.*?)\}\}", content) if matches is not None: license = matches.group(3) else: @@ -480,7 +480,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.abs(changed_bytes*0.001), 2) embed = defaultdict(dict) embed["title"] = _("Daily overview") embed["url"] = "https://{wiki}.gamepedia.com/Special:Statistics".format(wiki=settings["wiki"]) From 585cc36dfa28dc354034b74477f7167536e88eae Mon Sep 17 00:00:00 2001 From: Frisk Date: Sun, 24 Jun 2018 12:31:07 +0200 Subject: [PATCH 4/8] Temporary(?) solution, added #13 and #12 --- README.md | 2 ++ rcgcdw.py | 21 ++++++++++++++------- settings.json.example | 2 ++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9cf742f..0b112fc 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/rcgcdw.py b/rcgcdw.py index 421ee4c..fcd6368 100644 --- a/rcgcdw.py +++ b/rcgcdw.py @@ -121,15 +121,22 @@ 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 and "{{licence" not in content: - license = _("**No license!**") - else: - matches = re.search(r"\{\{(license|lizenz|licence)(\ |\|)(.*?)\}\}", content) + content = list(article_content.values())[0]['revisions'][0]['*'] + try: + matches = re.search(re.compile(settings["license_regex"]), content, re.IGNORECASE) if matches is not None: - license = matches.group(3) + license = matches.group("license") else: - license = "?" + if re.search(re.compile(settings["license_regex_detect"]), content, re.IGNORECASE) is None: + license = _("**No license!**") + else: + license = "?" + except sre_constants.error: + logging.error("Given regex for the license detection is incorrect. Please fix license_regex or license_regex_detect values in the config!") + 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 = "?" 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: diff --git a/settings.json.example b/settings.json.example index 69f2386..a8da206 100644 --- a/settings.json.example +++ b/settings.json.example @@ -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.*?)\\}\\}", "appearance":{ "daily_overview": { "color": 16312092, From 5774c0821e3ad1f24628f007dfc87431eaa0ed0b Mon Sep 17 00:00:00 2001 From: Frisk Date: Sun, 24 Jun 2018 12:51:57 +0200 Subject: [PATCH 5/8] Added #11 --- rcgcdw.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rcgcdw.py b/rcgcdw.py index fcd6368..f67617b 100644 --- a/rcgcdw.py +++ b/rcgcdw.py @@ -309,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() From d21567e2fa6deb469d8acb9d558752968b023761 Mon Sep 17 00:00:00 2001 From: Frisk Date: Sun, 24 Jun 2018 20:28:42 +0200 Subject: [PATCH 6/8] Fixes to 585cc36dfa28dc354034b74477f7167536e88eae --- rcgcdw.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rcgcdw.py b/rcgcdw.py index f67617b..a59cae9 100644 --- a/rcgcdw.py +++ b/rcgcdw.py @@ -123,20 +123,20 @@ def webhook_formatter(action, STATIC, **params): return 0 content = list(article_content.values())[0]['revisions'][0]['*'] try: - matches = re.search(re.compile(settings["license_regex"]), content, re.IGNORECASE) + matches = re.search(re.compile(settings["license_regex"], re.IGNORECASE), content) if matches is not None: license = matches.group("license") else: - if re.search(re.compile(settings["license_regex_detect"]), content, re.IGNORECASE) is None: + if re.search(re.compile(settings["license_regex_detect"], re.IGNORECASE), content) is None: license = _("**No license!**") else: license = "?" - except sre_constants.error: - logging.error("Given regex for the license detection is incorrect. Please fix license_regex or license_regex_detect values in the config!") - 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: From fac7acfe5754371fbda0d6ddfc6caf21d9dcd54a Mon Sep 17 00:00:00 2001 From: Frisk Date: Sun, 24 Jun 2018 22:12:09 +0200 Subject: [PATCH 7/8] Fixed function --- rcgcdw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rcgcdw.py b/rcgcdw.py index a59cae9..ee9e861 100644 --- a/rcgcdw.py +++ b/rcgcdw.py @@ -506,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+math.abs(changed_bytes*0.001), 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"]) From 1947985260904bec3f7535fced300f718ed0c989 Mon Sep 17 00:00:00 2001 From: Frisk Date: Sun, 24 Jun 2018 22:44:29 +0200 Subject: [PATCH 8/8] Fixed link formatting in few events --- rcgcdw.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rcgcdw.py b/rcgcdw.py index ee9e861..67d751c 100644 --- a/rcgcdw.py +++ b/rcgcdw.py @@ -140,17 +140,17 @@ def webhook_formatter(action, STATIC, **params): 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)