Fixed minecraft uuid lookup method wrongly placing the short UUID into

the cache instead of the long uuid.
Closes #25
feature/embed-uploads
Tristan Gosselin-Hane 7 years ago
parent cdeb7f777d
commit 34b5ea94e6
No known key found for this signature in database
GPG Key ID: 86886FC44C72EAA1
  1. 11
      webhook-bridge.py

@ -12,6 +12,7 @@ import time
import logging import logging
import random import random
import string import string
import uuid
from threading import Thread from threading import Thread
from config import Configuration from config import Configuration
from database import DiscordChannel, AccountLinkToken, DiscordAccount from database import DiscordChannel, AccountLinkToken, DiscordAccount
@ -58,7 +59,8 @@ def mc_uuid_to_username(uuid):
player_username = mojang_response[0]["name"] player_username = mojang_response[0]["name"]
UUID_CACHE[uuid] = player_username UUID_CACHE[uuid] = player_username
return 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)) log.error("Failed to lookup {}'s username using the Mojang API.".format(uuid))
else: else:
return UUID_CACHE[uuid] return UUID_CACHE[uuid]
@ -69,7 +71,8 @@ def mc_username_to_uuid(username):
try: try:
player_uuid = requests.get( player_uuid = requests.get(
"https://api.mojang.com/users/profiles/minecraft/{}".format(username)).json()["id"] "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 return player_uuid
except: except:
log.error("Failed to lookup {}'s UUID using the Mojang API.".format(username)) 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) el.log_connection(uuid=action.uuid, reason=el.ConnectionReason.SEEN)
if isinstance(action, clientbound.play.PlayerListItemPacket.RemovePlayerAction): if isinstance(action, clientbound.play.PlayerListItemPacket.RemovePlayerAction):
log.debug("Processing RemovePlayerAction tab list packet, uuid: {}".format(action.uuid)) 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 player_uuid = action.uuid
webhook_payload = { webhook_payload = {
'username': username, 'username': username,
@ -352,7 +355,7 @@ def main():
BOT_USERNAME.lower()), chat_string, re.M | re.I) BOT_USERNAME.lower()), chat_string, re.M | re.I)
if bot_message_match: if bot_message_match:
el.log_chat_message( 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), display_name=bot_message_match.group(1),
message=bot_message_match.group(2), message=bot_message_match.group(2),
message_unformatted=chat_string) message_unformatted=chat_string)

Loading…
Cancel
Save