From 52b61d75c90a4644ff1826cf1225a50da0bb799c Mon Sep 17 00:00:00 2001 From: Frisk Date: Sun, 30 Dec 2018 19:27:16 +0100 Subject: [PATCH] Fixed #36 forever, please do not even mention this issue to me ever again --- rcgcdw.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rcgcdw.py b/rcgcdw.py index 3e20f51..e0367e3 100644 --- a/rcgcdw.py +++ b/rcgcdw.py @@ -77,7 +77,13 @@ LinkParser = LinkParser() def send(message, name, avatar): - send_to_discord({"content": message, "avatar_url": avatar, "username": name}) + dictionary_creator = {} + dictionary_creator["content"] = message + if name: + dictionary_creator["username"] = name + if avatar: + dictionary_creator["avatar_url"] = avatar + send_to_discord(dictionary_creator) def safe_read(request, *keys): @@ -101,6 +107,8 @@ def send_to_discord_webhook(data): header = settings["header"] if "content" not in data: header['Content-Type'] = 'application/json' + else: + header['Content-Type'] = 'application/x-www-form-urlencoded' try: result = requests.post(settings["webhookURL"], data=data, headers=header, timeout=10) @@ -511,7 +519,7 @@ def webhook_formatter(action, STATIC, **params): def handle_discord_http(code, formatted_embed, result): if 300 > code > 199: # message went through return 0 - elif code == 400: # HTTP BAD REQUEST + elif code == 400: # HTTP BAD REQUEST result.status_code, data, result, header logging.error( "Following message has been rejected by Discord, please submit a bug on our bugtracker adding it:") logging.error(formatted_embed)