mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Replaced print statements with logging function calls, fixed redirect bug, removed one unnecessary variable, some translation fix
This commit is contained in:
parent
3e619016f3
commit
aff677e9d6
27
rcgcdw.py
27
rcgcdw.py
|
@ -70,7 +70,7 @@ class LinkParser(HTMLParser):
|
||||||
self.new_string = self.new_string + data
|
self.new_string = self.new_string + data
|
||||||
|
|
||||||
def handle_endtag(self, tag):
|
def handle_endtag(self, tag):
|
||||||
print(self.new_string)
|
logging.debug(self.new_string)
|
||||||
|
|
||||||
LinkParser = LinkParser()
|
LinkParser = LinkParser()
|
||||||
|
|
||||||
|
@ -130,10 +130,6 @@ def webhook_formatter(action, STATIC, **params):
|
||||||
colornumber = None if isinstance(STATIC["color"], str) else STATIC["color"]
|
colornumber = None if isinstance(STATIC["color"], str) else STATIC["color"]
|
||||||
data = {"embeds": []}
|
data = {"embeds": []}
|
||||||
embed = defaultdict(dict)
|
embed = defaultdict(dict)
|
||||||
if "title" in params:
|
|
||||||
article_encoded = params["title"].replace(" ", "_").replace(')', '\)')
|
|
||||||
if STATIC["redirect"]:
|
|
||||||
params["title"] = "⤷ " + params["title"]
|
|
||||||
if STATIC["ipaction"]:
|
if STATIC["ipaction"]:
|
||||||
author_url = "https://{wiki}.gamepedia.com/Special:Contributions/{user}".format(wiki=settings["wiki"],
|
author_url = "https://{wiki}.gamepedia.com/Special:Contributions/{user}".format(wiki=settings["wiki"],
|
||||||
user=params["user"])
|
user=params["user"])
|
||||||
|
@ -148,8 +144,11 @@ def webhook_formatter(action, STATIC, **params):
|
||||||
params["user"] = params["user"] + "(?)"
|
params["user"] = params["user"] + "(?)"
|
||||||
else:
|
else:
|
||||||
recent_changes.map_ips[params["user"]] = len(contibs)
|
recent_changes.map_ips[params["user"]] = len(contibs)
|
||||||
|
logging.debug("1Current params user {} and state of map_ips {}".format(params["user"], recent_changes.map_ips))
|
||||||
params["user"] = "{author} ({contribs})".format(author=params["user"], contribs=len(contibs))
|
params["user"] = "{author} ({contribs})".format(author=params["user"], contribs=len(contibs))
|
||||||
else:
|
else:
|
||||||
|
logging.debug(
|
||||||
|
"2Current params user {} and state of map_ips {}".format(params["user"], recent_changes.map_ips))
|
||||||
recent_changes.map_ips[params["user"]] += 1
|
recent_changes.map_ips[params["user"]] += 1
|
||||||
params["user"] = "{author} ({amount})".format(author=params["user"],
|
params["user"] = "{author} ({amount})".format(author=params["user"],
|
||||||
amount=recent_changes.map_ips[params["user"]])
|
amount=recent_changes.map_ips[params["user"]])
|
||||||
|
@ -158,7 +157,6 @@ def webhook_formatter(action, STATIC, **params):
|
||||||
user=params["user"].replace(" ", "_"))
|
user=params["user"].replace(" ", "_"))
|
||||||
if action in ("edit", "new"): # edit or new page
|
if action in ("edit", "new"): # edit or new page
|
||||||
editsize = params["size"]
|
editsize = params["size"]
|
||||||
print(editsize)
|
|
||||||
if editsize > 0:
|
if editsize > 0:
|
||||||
if editsize > 6032:
|
if editsize > 6032:
|
||||||
colornumber = 65280
|
colornumber = 65280
|
||||||
|
@ -174,7 +172,7 @@ def webhook_formatter(action, STATIC, **params):
|
||||||
link = "https://{wiki}.gamepedia.com/index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format(
|
link = "https://{wiki}.gamepedia.com/index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format(
|
||||||
wiki=settings["wiki"], pageid=params["pageid"], diff=params["diff"], oldrev=params["oldrev"],
|
wiki=settings["wiki"], pageid=params["pageid"], diff=params["diff"], oldrev=params["oldrev"],
|
||||||
article=params["title"].replace(" ", "_"))
|
article=params["title"].replace(" ", "_"))
|
||||||
embed["title"] = "{article} ({new}{minor}{editsize})".format(article=params["title"], editsize="+" + str(
|
embed["title"] = "{redirect}{article} ({new}{minor}{editsize})".format(redirect="⤷ " if STATIC["redirect"] else "",article=params["title"], editsize="+" + str(
|
||||||
editsize) if editsize > 0 else editsize, new=_("(N!) ") if action == "new" else "",
|
editsize) if editsize > 0 else editsize, new=_("(N!) ") if action == "new" else "",
|
||||||
minor=_("m ") if action == "edit" and params[
|
minor=_("m ") if action == "edit" and params[
|
||||||
"minor"] else "")
|
"minor"] else "")
|
||||||
|
@ -196,6 +194,7 @@ def webhook_formatter(action, STATIC, **params):
|
||||||
pass
|
pass
|
||||||
if params["overwrite"]:
|
if params["overwrite"]:
|
||||||
if additional_info_retrieved:
|
if additional_info_retrieved:
|
||||||
|
article_encoded = params["title"].replace(" ", "_").replace(')', '\)')
|
||||||
img_timestamp = [x for x in img_info[1]["timestamp"] if x.isdigit()]
|
img_timestamp = [x for x in img_info[1]["timestamp"] if x.isdigit()]
|
||||||
undolink = "https://{wiki}.gamepedia.com/index.php?title={filename}&action=revert&oldimage={timestamp}%21{filenamewon}".format(
|
undolink = "https://{wiki}.gamepedia.com/index.php?title={filename}&action=revert&oldimage={timestamp}%21{filenamewon}".format(
|
||||||
wiki=settings["wiki"], filename=article_encoded, timestamp="".join(img_timestamp),
|
wiki=settings["wiki"], filename=article_encoded, timestamp="".join(img_timestamp),
|
||||||
|
@ -250,16 +249,16 @@ def webhook_formatter(action, STATIC, **params):
|
||||||
supress=_("No redirect has been made") if params[
|
supress=_("No redirect has been made") if params[
|
||||||
"supress"] == True else _(
|
"supress"] == True else _(
|
||||||
"A redirect has been made"))
|
"A redirect has been made"))
|
||||||
embed["title"] = _("Moved {article} to {target}").format(article=params["title"], target=params["target"])
|
embed["title"] = _("Moved {redirect}{article} to {target}").format(redirect="⤷ " if STATIC["redirect"] else "", article=params["title"], target=params["target"])
|
||||||
elif action == "move/move_redir":
|
elif action == "move/move_redir":
|
||||||
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"],
|
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"],
|
||||||
article=params["target"].replace(" ", "_"))
|
article=params["target"].replace(" ", "_"))
|
||||||
embed["title"] = _("Moved {article} to {title} over redirect").format(article=params["title"],
|
embed["title"] = _("Moved {redirect}{article} to {title} over redirect").format(redirect="⤷ " if STATIC["redirect"] else "", article=params["title"],
|
||||||
title=params["target"])
|
title=params["target"])
|
||||||
elif action == "protect/move_prot":
|
elif action == "protect/move_prot":
|
||||||
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"],
|
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"],
|
||||||
article=params["title"].replace(" ", "_"))
|
article=params["title"].replace(" ", "_"))
|
||||||
embed["title"] = _("Moved protection settings from {article} to {title}").format(article=params["title"],
|
embed["title"] = _("Moved protection settings from {redirect}{article} to {title}").format(redirect="⤷ " if STATIC["redirect"] else "", article=params["title"],
|
||||||
title=params["target"])
|
title=params["target"])
|
||||||
elif action == "block/block":
|
elif action == "block/block":
|
||||||
link = "https://{wiki}.gamepedia.com/{user}".format(wiki=settings["wiki"],
|
link = "https://{wiki}.gamepedia.com/{user}".format(wiki=settings["wiki"],
|
||||||
|
@ -491,8 +490,8 @@ def webhook_formatter(action, STATIC, **params):
|
||||||
if "fields" not in embed:
|
if "fields" not in embed:
|
||||||
embed["fields"] = []
|
embed["fields"] = []
|
||||||
# embed["fields"].append({"name": _("Changed categories"), "value": ", ".join(params["new_categories"][0:15]) + ("" if (len(params["new_categories"]) < 15) else _(" and {} more").format(len(params["new_categories"])-14))})
|
# embed["fields"].append({"name": _("Changed categories"), "value": ", ".join(params["new_categories"][0:15]) + ("" if (len(params["new_categories"]) < 15) else _(" and {} more").format(len(params["new_categories"])-14))})
|
||||||
new_cat = (_("**Added**:") + ", ".join(STATIC["changed_categories"]["new"][0:16]) + ("\n" if len(STATIC["changed_categories"]["new"])<=15 else _(" and {} more\n").format(len(STATIC["changed_categories"]["new"])-15) ) ) if STATIC["changed_categories"]["new"] else ""
|
new_cat = (_("**Added**: ") + ", ".join(STATIC["changed_categories"]["new"][0:16]) + ("\n" if len(STATIC["changed_categories"]["new"])<=15 else _(" and {} more\n").format(len(STATIC["changed_categories"]["new"])-15) ) ) if STATIC["changed_categories"]["new"] else ""
|
||||||
del_cat = (_("**Removed**:") + ", ".join(STATIC["changed_categories"]["removed"][0:16]) + ("" if len(STATIC["changed_categories"]["removed"])<=15 else _(" and {} more").format(len(STATIC["changed_categories"]["removed"])-15) ) ) if STATIC["changed_categories"]["removed"] else ""
|
del_cat = (_("**Removed**: ") + ", ".join(STATIC["changed_categories"]["removed"][0:16]) + ("" if len(STATIC["changed_categories"]["removed"])<=15 else _(" and {} more").format(len(STATIC["changed_categories"]["removed"])-15) ) ) if STATIC["changed_categories"]["removed"] else ""
|
||||||
embed["fields"].append({"name": _("Changed categories"), "value": new_cat + del_cat})
|
embed["fields"].append({"name": _("Changed categories"), "value": new_cat + del_cat})
|
||||||
data["embeds"].append(dict(embed))
|
data["embeds"].append(dict(embed))
|
||||||
data['avatar_url'] = settings["avatars"]["embed"]
|
data['avatar_url'] = settings["avatars"]["embed"]
|
||||||
|
@ -664,7 +663,7 @@ def first_pass(
|
||||||
webhook_formatter(combination, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment)
|
webhook_formatter(combination, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment)
|
||||||
else:
|
else:
|
||||||
logging.warning("No entry matches given change!")
|
logging.warning("No entry matches given change!")
|
||||||
print(change)
|
logging.warning("Entry: {}".format(change))
|
||||||
send(_("Unable to process the event"), _("error"), settings["avatars"]["no_event"])
|
send(_("Unable to process the event"), _("error"), settings["avatars"]["no_event"])
|
||||||
return
|
return
|
||||||
# elif change["type"] == "external": # not sure what happens then, but it's listed as possible type
|
# elif change["type"] == "external": # not sure what happens then, but it's listed as possible type
|
||||||
|
@ -833,7 +832,7 @@ class recent_changes_class(object):
|
||||||
|
|
||||||
def handle_mw_errors(self, request):
|
def handle_mw_errors(self, request):
|
||||||
if "errors" in request:
|
if "errors" in request:
|
||||||
print(request["errors"])
|
logging.error(request["errors"])
|
||||||
raise MWError
|
raise MWError
|
||||||
return request
|
return request
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue