Fixed issue where the comment was too big for the message to be sent. Reworked the comment pulling code.

This commit is contained in:
Frisk 2019-06-13 17:34:08 +02:00
parent 0b5df0177e
commit a736f5abbd
No known key found for this signature in database
GPG key ID: 0E9A7D3C0A01586C

View file

@ -115,12 +115,20 @@ def send_to_discord(data):
def pull_comment(comment_id): def pull_comment(comment_id):
comment = None
try: try:
comment = recent_changes.handle_mw_errors(recent_changes.safe_request("https://{}.gamepedia.com/api.php?action=comment&do=getRaw&comment_id={}&format=json".format(settings["wiki"], comment_id)).json()) comment = recent_changes.handle_mw_errors(recent_changes.safe_request("https://{}.gamepedia.com/api.php?action=comment&do=getRaw&comment_id={}&format=json".format(settings["wiki"], comment_id)).json())["text"]
logger.debug("Got the following comment from the API: {}".format(comment))
except MWError: except MWError:
pass pass
return comment except TypeError:
logger.exception("Could not resolve the comment text.")
except KeyError:
logger.exception("CurseProfile extension API did not respond with a valid comment content.")
else:
if len(comment) > 1000:
comment = comment[0:1000] + ""
return comment
return ""
def compact_formatter(action, change, parsed_comment, categories): def compact_formatter(action, change, parsed_comment, categories):
@ -624,9 +632,7 @@ def embed_formatter(action, change, parsed_comment, categories):
embed["title"] = _("Unblocked {blocked_user}").format(blocked_user=user) embed["title"] = _("Unblocked {blocked_user}").format(blocked_user=user)
elif action == "curseprofile/comment-created": elif action == "curseprofile/comment-created":
if settings["appearance"]["embed"]["show_edit_changes"]: if settings["appearance"]["embed"]["show_edit_changes"]:
comment_content = pull_comment(change["logparams"]["4:comment_id"]) parsed_comment = pull_comment(change["logparams"]["4:comment_id"])
if comment_content is not None and comment_content["text"]:
embed["fields"] = [{"name": _("Comment content"), "value": comment_content["text"]}]
link = "https://{wiki}.gamepedia.com/Special:CommentPermalink/{commentid}".format(wiki=settings["wiki"], link = "https://{wiki}.gamepedia.com/Special:CommentPermalink/{commentid}".format(wiki=settings["wiki"],
commentid=change["logparams"]["4:comment_id"]) commentid=change["logparams"]["4:comment_id"])
embed["title"] = _("Left a comment on {target}'s profile").format(target=change["title"].split(':')[1]) if change["title"].split(':')[1] != \ embed["title"] = _("Left a comment on {target}'s profile").format(target=change["title"].split(':')[1]) if change["title"].split(':')[1] != \
@ -634,9 +640,7 @@ def embed_formatter(action, change, parsed_comment, categories):
"Left a comment on their own profile") "Left a comment on their own profile")
elif action == "curseprofile/comment-replied": elif action == "curseprofile/comment-replied":
if settings["appearance"]["embed"]["show_edit_changes"]: if settings["appearance"]["embed"]["show_edit_changes"]:
comment_content = pull_comment(change["logparams"]["4:comment_id"]) parsed_comment = pull_comment(change["logparams"]["4:comment_id"])
if comment_content is not None and comment_content["text"]:
embed["fields"] = [{"name": _("Comment content"), "value": comment_content["text"]}]
link = "https://{wiki}.gamepedia.com/Special:CommentPermalink/{commentid}".format(wiki=settings["wiki"], link = "https://{wiki}.gamepedia.com/Special:CommentPermalink/{commentid}".format(wiki=settings["wiki"],
commentid=change["logparams"]["4:comment_id"]) commentid=change["logparams"]["4:comment_id"])
embed["title"] = _("Replied to a comment on {target}'s profile").format(target=change["title"].split(':')[1]) if change["title"].split(':')[1] != \ embed["title"] = _("Replied to a comment on {target}'s profile").format(target=change["title"].split(':')[1]) if change["title"].split(':')[1] != \
@ -644,9 +648,7 @@ def embed_formatter(action, change, parsed_comment, categories):
"Replied to a comment on their own profile") "Replied to a comment on their own profile")
elif action == "curseprofile/comment-edited": elif action == "curseprofile/comment-edited":
if settings["appearance"]["embed"]["show_edit_changes"]: if settings["appearance"]["embed"]["show_edit_changes"]:
comment_content = pull_comment(change["logparams"]["4:comment_id"]) parsed_comment = pull_comment(change["logparams"]["4:comment_id"])
if comment_content is not None and comment_content["text"]:
embed["fields"] = [{"name": _("Comment content"), "value": comment_content["text"]}]
link = "https://{wiki}.gamepedia.com/Special:CommentPermalink/{commentid}".format(wiki=settings["wiki"], link = "https://{wiki}.gamepedia.com/Special:CommentPermalink/{commentid}".format(wiki=settings["wiki"],
commentid=change["logparams"]["4:comment_id"]) commentid=change["logparams"]["4:comment_id"])
embed["title"] = _("Edited a comment on {target}'s profile").format(target=change["title"].split(':')[1]) if change["title"].split(':')[1] != \ embed["title"] = _("Edited a comment on {target}'s profile").format(target=change["title"].split(':')[1]) if change["title"].split(':')[1] != \