mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Fixed #133
This commit is contained in:
parent
97ac7ee2e8
commit
459d242c55
|
@ -9,7 +9,7 @@
|
||||||
"limit": 10,
|
"limit": 10,
|
||||||
"webhookURL": "https://discordapp.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
"webhookURL": "https://discordapp.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||||
"limitrefetch": 28,
|
"limitrefetch": 28,
|
||||||
"wikiname": "Minecraft Wiki",
|
"wikiname": "Wreck It Woodhouse",
|
||||||
"avatars": {
|
"avatars": {
|
||||||
"connection_failed": "https://i.imgur.com/2jWQEt1.png",
|
"connection_failed": "https://i.imgur.com/2jWQEt1.png",
|
||||||
"connection_restored": "",
|
"connection_restored": "",
|
||||||
|
|
|
@ -3,6 +3,7 @@ import math
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
import datetime
|
||||||
from urllib.parse import quote_plus
|
from urllib.parse import quote_plus
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
@ -87,20 +88,22 @@ def compact_formatter(action, change, parsed_comment, categories, recent_changes
|
||||||
except ValueError:
|
except ValueError:
|
||||||
link = link_formatter(create_article_path(change["title"]))
|
link = link_formatter(create_article_path(change["title"]))
|
||||||
if change["logparams"]["duration"] == "infinite":
|
if change["logparams"]["duration"] == "infinite":
|
||||||
block_time = _("infinity and beyond")
|
block_time = _("for infinity and beyond")
|
||||||
else:
|
else:
|
||||||
english_length = re.sub(r"(\d+)", "", change["logparams"][
|
english_length = re.sub(r"(\d+)", "", change["logparams"][
|
||||||
"duration"]) # note that translation won't work for millenia and century yet
|
"duration"]) # note that translation won't work for millenia and century yet
|
||||||
english_length_num = re.sub(r"(\D+)", "", change["logparams"]["duration"])
|
english_length_num = re.sub(r"(\D+)", "", change["logparams"]["duration"])
|
||||||
try:
|
try:
|
||||||
|
if "@" in english_length:
|
||||||
|
raise ValueError
|
||||||
english_length = english_length.rstrip("s").strip()
|
english_length = english_length.rstrip("s").strip()
|
||||||
block_time = "{num} {translated_length}".format(num=english_length_num,
|
block_time = _("for {num} {translated_length}").format(num=english_length_num,
|
||||||
translated_length=ngettext(english_length,
|
translated_length=ngettext(english_length,
|
||||||
english_length + "s",
|
english_length + "s",
|
||||||
int(english_length_num)))
|
int(english_length_num)))
|
||||||
except AttributeError:
|
except (AttributeError, ValueError):
|
||||||
logger.error("Could not strip s from the block event, seems like the regex didn't work?")
|
date_time_obj = datetime.datetime.strptime(change["logparams"]["expiry"], '%Y-%m-%dT%H:%M:%SZ')
|
||||||
return
|
block_time = _("until {}").format(date_time_obj.strftime("%Y-%m-%d %H:%M:%S UTC"))
|
||||||
if "sitewide" not in change["logparams"]:
|
if "sitewide" not in change["logparams"]:
|
||||||
restriction_description = ""
|
restriction_description = ""
|
||||||
if "pages" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"]["pages"]:
|
if "pages" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"]["pages"]:
|
||||||
|
@ -125,7 +128,7 @@ def compact_formatter(action, change, parsed_comment, categories, recent_changes
|
||||||
logger.debug(restriction_description)
|
logger.debug(restriction_description)
|
||||||
restriction_description = restriction_description[:1020] + "…"
|
restriction_description = restriction_description[:1020] + "…"
|
||||||
content = _(
|
content = _(
|
||||||
"[{author}]({author_url}) blocked [{user}]({user_url}) for {time}{restriction_desc}{comment}").format(author=author, author_url=author_url, user=user, time=block_time, user_url=link, restriction_desc=restriction_description, comment=parsed_comment)
|
"[{author}]({author_url}) blocked [{user}]({user_url}) {time}{restriction_desc}{comment}").format(author=author, author_url=author_url, user=user, time=block_time, user_url=link, restriction_desc=restriction_description, comment=parsed_comment)
|
||||||
elif action == "block/reblock":
|
elif action == "block/reblock":
|
||||||
link = link_formatter(create_article_path(change["title"]))
|
link = link_formatter(create_article_path(change["title"]))
|
||||||
user = change["title"].split(':')[1]
|
user = change["title"].split(':')[1]
|
||||||
|
@ -506,16 +509,18 @@ def embed_formatter(action, change, parsed_comment, categories, recent_changes):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
link = create_article_path(change["title"].replace(" ", "_").replace(')', '\)'))
|
link = create_article_path(change["title"].replace(" ", "_").replace(')', '\)'))
|
||||||
if change["logparams"]["duration"] == "infinite":
|
if change["logparams"]["duration"] == "infinite":
|
||||||
block_time = _("infinity and beyond")
|
block_time = _("for infinity and beyond")
|
||||||
else:
|
else:
|
||||||
english_length = re.sub(r"(\d+)", "", change["logparams"]["duration"]) #note that translation won't work for millenia and century yet
|
english_length = re.sub(r"(\d+)", "", change["logparams"]["duration"]) # note that translation won't work for millenia and century yet
|
||||||
english_length_num = re.sub(r"(\D+)", "", change["logparams"]["duration"])
|
english_length_num = re.sub(r"(\D+)", "", change["logparams"]["duration"])
|
||||||
try:
|
try:
|
||||||
|
if "@" in english_length:
|
||||||
|
raise ValueError
|
||||||
english_length = english_length.rstrip("s").strip()
|
english_length = english_length.rstrip("s").strip()
|
||||||
block_time = "{num} {translated_length}".format(num=english_length_num, translated_length=ngettext(english_length, english_length + "s", int(english_length_num)))
|
block_time = _("for {num} {translated_length}").format(num=english_length_num, translated_length=ngettext(english_length, english_length + "s", int(english_length_num)))
|
||||||
except AttributeError:
|
except (AttributeError, ValueError):
|
||||||
logger.error("Could not strip s from the block event, seems like the regex didn't work?")
|
date_time_obj = datetime.datetime.strptime(change["logparams"]["expiry"], '%Y-%m-%dT%H:%M:%SZ')
|
||||||
return
|
block_time = _("until {}").format(date_time_obj.strftime("%Y-%m-%d %H:%M:%S UTC"))
|
||||||
if "sitewide" not in change["logparams"]:
|
if "sitewide" not in change["logparams"]:
|
||||||
restriction_description = ""
|
restriction_description = ""
|
||||||
if "pages" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"]["pages"]:
|
if "pages" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"]["pages"]:
|
||||||
|
@ -540,7 +545,7 @@ def embed_formatter(action, change, parsed_comment, categories, recent_changes):
|
||||||
logger.debug(restriction_description)
|
logger.debug(restriction_description)
|
||||||
restriction_description = restriction_description[:1020]+"…"
|
restriction_description = restriction_description[:1020]+"…"
|
||||||
embed.add_field(_("Partial block details"), restriction_description, inline=True)
|
embed.add_field(_("Partial block details"), restriction_description, inline=True)
|
||||||
embed["title"] = _("Blocked {blocked_user} for {time}").format(blocked_user=user, time=block_time)
|
embed["title"] = _("Blocked {blocked_user} {time}").format(blocked_user=user, time=block_time)
|
||||||
elif action == "block/reblock":
|
elif action == "block/reblock":
|
||||||
link = create_article_path(change["title"].replace(" ", "_").replace(')', '\)'))
|
link = create_article_path(change["title"].replace(" ", "_").replace(')', '\)'))
|
||||||
user = change["title"].split(':')[1]
|
user = change["title"].split(':')[1]
|
||||||
|
|
Loading…
Reference in a new issue