mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-24 00:34:10 +00:00
A few important bugfixed to prevent crashes from hidden actions
This commit is contained in:
parent
3b37bd5b48
commit
9f2c72fad9
63
rcgcdw.py
63
rcgcdw.py
|
@ -158,8 +158,9 @@ def link_formatter(link):
|
||||||
return "<"+re.sub(r"([ \)])", "\\\\\\1", link)+">"
|
return "<"+re.sub(r"([ \)])", "\\\\\\1", link)+">"
|
||||||
|
|
||||||
def compact_formatter(action, change, parsed_comment, categories):
|
def compact_formatter(action, change, parsed_comment, categories):
|
||||||
author_url = link_formatter("https://{wiki}.gamepedia.com/User:{user}".format(wiki=settings["wiki"], user=change["user"]))
|
if action != "suppressed":
|
||||||
author = change["user"]
|
author_url = link_formatter("https://{wiki}.gamepedia.com/User:{user}".format(wiki=settings["wiki"], user=change["user"]))
|
||||||
|
author = change["user"]
|
||||||
parsed_comment = "" if parsed_comment is None else " *("+parsed_comment+")*"
|
parsed_comment = "" if parsed_comment is None else " *("+parsed_comment+")*"
|
||||||
if action in ["edit", "new"]:
|
if action in ["edit", "new"]:
|
||||||
edit_link = link_formatter("https://{wiki}.gamepedia.com/index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format(
|
edit_link = link_formatter("https://{wiki}.gamepedia.com/index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format(
|
||||||
|
@ -428,7 +429,6 @@ def compact_formatter(action, change, parsed_comment, categories):
|
||||||
elif action == "suppressed":
|
elif action == "suppressed":
|
||||||
link = "<https://{wiki}.gamepedia.com/>".format(wiki=settings["wiki"])
|
link = "<https://{wiki}.gamepedia.com/>".format(wiki=settings["wiki"])
|
||||||
content = _("An action has been hidden by administration.")
|
content = _("An action has been hidden by administration.")
|
||||||
print(content)
|
|
||||||
send_to_discord({'content': content})
|
send_to_discord({'content': content})
|
||||||
|
|
||||||
def embed_formatter(action, change, parsed_comment, categories):
|
def embed_formatter(action, change, parsed_comment, categories):
|
||||||
|
@ -437,32 +437,35 @@ def embed_formatter(action, change, parsed_comment, categories):
|
||||||
colornumber = None
|
colornumber = None
|
||||||
if parsed_comment is None:
|
if parsed_comment is None:
|
||||||
parsed_comment = _("No description provided")
|
parsed_comment = _("No description provided")
|
||||||
if "anon" in change:
|
if action != "suppressed":
|
||||||
author_url = "https://{wiki}.gamepedia.com/Special:Contributions/{user}".format(wiki=settings["wiki"],
|
if "anon" in change:
|
||||||
user=change["user"])
|
author_url = "https://{wiki}.gamepedia.com/Special:Contributions/{user}".format(wiki=settings["wiki"],
|
||||||
logging.debug("current user: {} with cache of IPs: {}".format(change["user"], recent_changes.map_ips.keys()))
|
user=change["user"])
|
||||||
if change["user"] not in list(recent_changes.map_ips.keys()):
|
logging.debug("current user: {} with cache of IPs: {}".format(change["user"], recent_changes.map_ips.keys()))
|
||||||
contibs = safe_read(recent_changes.safe_request(
|
if change["user"] not in list(recent_changes.map_ips.keys()):
|
||||||
"https://{wiki}.gamepedia.com/api.php?action=query&format=json&list=usercontribs&uclimit=max&ucuser={user}&ucstart={timestamp}&ucprop=".format(
|
contibs = safe_read(recent_changes.safe_request(
|
||||||
wiki=settings["wiki"], user=change["user"], timestamp=change["timestamp"])), "query", "usercontribs")
|
"https://{wiki}.gamepedia.com/api.php?action=query&format=json&list=usercontribs&uclimit=max&ucuser={user}&ucstart={timestamp}&ucprop=".format(
|
||||||
if contibs is None:
|
wiki=settings["wiki"], user=change["user"], timestamp=change["timestamp"])), "query", "usercontribs")
|
||||||
logging.warning(
|
if contibs is None:
|
||||||
"WARNING: Something went wrong when checking amount of contributions for given IP address")
|
logging.warning(
|
||||||
change["user"] = change["user"] + "(?)"
|
"WARNING: Something went wrong when checking amount of contributions for given IP address")
|
||||||
|
change["user"] = change["user"] + "(?)"
|
||||||
|
else:
|
||||||
|
recent_changes.map_ips[change["user"]] = len(contibs)
|
||||||
|
logging.debug("1Current params user {} and state of map_ips {}".format(change["user"], recent_changes.map_ips))
|
||||||
|
change["user"] = "{author} ({contribs})".format(author=change["user"], contribs=len(contibs))
|
||||||
else:
|
else:
|
||||||
recent_changes.map_ips[change["user"]] = len(contibs)
|
logging.debug(
|
||||||
logging.debug("1Current params user {} and state of map_ips {}".format(change["user"], recent_changes.map_ips))
|
"2Current params user {} and state of map_ips {}".format(change["user"], recent_changes.map_ips))
|
||||||
change["user"] = "{author} ({contribs})".format(author=change["user"], contribs=len(contibs))
|
if action in ("edit", "new"):
|
||||||
|
recent_changes.map_ips[change["user"]] += 1
|
||||||
|
change["user"] = "{author} ({amount})".format(author=change["user"],
|
||||||
|
amount=recent_changes.map_ips[change["user"]])
|
||||||
else:
|
else:
|
||||||
logging.debug(
|
author_url = "https://{wiki}.gamepedia.com/User:{user}".format(wiki=settings["wiki"],
|
||||||
"2Current params user {} and state of map_ips {}".format(change["user"], recent_changes.map_ips))
|
user=change["user"].replace(" ", "_"))
|
||||||
if action in ("edit", "new"):
|
embed["author"]["name"] = change["user"]
|
||||||
recent_changes.map_ips[change["user"]] += 1
|
embed["author"]["url"] = author_url
|
||||||
change["user"] = "{author} ({amount})".format(author=change["user"],
|
|
||||||
amount=recent_changes.map_ips[change["user"]])
|
|
||||||
else:
|
|
||||||
author_url = "https://{wiki}.gamepedia.com/User:{user}".format(wiki=settings["wiki"],
|
|
||||||
user=change["user"].replace(" ", "_"))
|
|
||||||
if action in ("edit", "new"): # edit or new page
|
if action in ("edit", "new"): # edit or new page
|
||||||
editsize = change["newlen"] - change["oldlen"]
|
editsize = change["newlen"] - change["oldlen"]
|
||||||
if editsize > 0:
|
if editsize > 0:
|
||||||
|
@ -783,10 +786,9 @@ def embed_formatter(action, change, parsed_comment, categories):
|
||||||
elif action == "suppressed":
|
elif action == "suppressed":
|
||||||
link = "https://{wiki}.gamepedia.com/".format(wiki=settings["wiki"])
|
link = "https://{wiki}.gamepedia.com/".format(wiki=settings["wiki"])
|
||||||
embed["title"] = _("Action has been hidden by administration.")
|
embed["title"] = _("Action has been hidden by administration.")
|
||||||
|
embed["author"]["name"] = _("Unknown")
|
||||||
else:
|
else:
|
||||||
logging.warning("No entry for {event} with params: {params}".format(event=action, params=change))
|
logging.warning("No entry for {event} with params: {params}".format(event=action, params=change))
|
||||||
embed["author"]["name"] = change["user"]
|
|
||||||
embed["author"]["url"] = author_url
|
|
||||||
embed["author"]["icon_url"] = settings["appearance"]["embed"][action]["icon"]
|
embed["author"]["icon_url"] = settings["appearance"]["embed"][action]["icon"]
|
||||||
embed["url"] = link
|
embed["url"] = link
|
||||||
embed["description"] = parsed_comment
|
embed["description"] = parsed_comment
|
||||||
|
@ -851,7 +853,8 @@ def essential_info(change, changed_categories):
|
||||||
"""Prepares essential information for both embed and compact message format."""
|
"""Prepares essential information for both embed and compact message format."""
|
||||||
logging.debug(change)
|
logging.debug(change)
|
||||||
if ("actionhidden" in change or "suppressed" in change) and "suppressed" not in settings["ignored"]: # if event is hidden using suppression
|
if ("actionhidden" in change or "suppressed" in change) and "suppressed" not in settings["ignored"]: # if event is hidden using suppression
|
||||||
appearance_mode("supressed", change, "", [])
|
appearance_mode("suppressed", change, "", changed_categories)
|
||||||
|
return
|
||||||
if "commenthidden" not in change:
|
if "commenthidden" not in change:
|
||||||
LinkParser.feed(change["parsedcomment"])
|
LinkParser.feed(change["parsedcomment"])
|
||||||
parsed_comment = LinkParser.new_string
|
parsed_comment = LinkParser.new_string
|
||||||
|
|
Loading…
Reference in a new issue