From 34b5ea94e659fe46f52961a16b7dcbce0ae99585 Mon Sep 17 00:00:00 2001 From: Tristan Gosselin-Hane Date: Fri, 23 Nov 2018 10:56:01 -0500 Subject: [PATCH] Fixed minecraft uuid lookup method wrongly placing the short UUID into the cache instead of the long uuid. Closes #25 --- webhook-bridge.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/webhook-bridge.py b/webhook-bridge.py index 8481c5d..796761c 100755 --- a/webhook-bridge.py +++ b/webhook-bridge.py @@ -12,6 +12,7 @@ import time import logging import random import string +import uuid from threading import Thread from config import Configuration from database import DiscordChannel, AccountLinkToken, DiscordAccount @@ -58,7 +59,8 @@ def mc_uuid_to_username(uuid): player_username = mojang_response[0]["name"] UUID_CACHE[uuid] = player_username return player_username - except: + except Exception as e: + log.error(e, exc_info=True) log.error("Failed to lookup {}'s username using the Mojang API.".format(uuid)) else: return UUID_CACHE[uuid] @@ -69,7 +71,8 @@ def mc_username_to_uuid(username): try: player_uuid = requests.get( "https://api.mojang.com/users/profiles/minecraft/{}".format(username)).json()["id"] - UUID_CACHE.inv[username] = player_uuid + long_uuid = uuid.UUID(player_uuid) + UUID_CACHE.inv[username] = str(long_uuid) return player_uuid except: log.error("Failed to lookup {}'s UUID using the Mojang API.".format(username)) @@ -311,7 +314,7 @@ def main(): el.log_connection(uuid=action.uuid, reason=el.ConnectionReason.SEEN) if isinstance(action, clientbound.play.PlayerListItemPacket.RemovePlayerAction): log.debug("Processing RemovePlayerAction tab list packet, uuid: {}".format(action.uuid)) - username = UUID_CACHE[action.uuid] + username = mc_uuid_to_username(action.uuid) player_uuid = action.uuid webhook_payload = { 'username': username, @@ -352,7 +355,7 @@ def main(): BOT_USERNAME.lower()), chat_string, re.M | re.I) if bot_message_match: el.log_chat_message( - uuid=UUID_CACHE.inv[bot_message_match.group(1)], + uuid=mc_username_to_uuid(bot_message_match.group(1)), display_name=bot_message_match.group(1), message=bot_message_match.group(2), message_unformatted=chat_string)