From 5b81b32687caa49d63e47838b545e3d655916dd1 Mon Sep 17 00:00:00 2001 From: Tristan Gosselin-Hane Date: Mon, 12 Nov 2018 02:17:52 -0500 Subject: [PATCH] Fixed a few bugs relating to elasticsearch player count * Log the bot's connection * Ignore duplicate bot connection packets * Simulate decrementing player count for missed disconnect events --- webhook-bridge.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/webhook-bridge.py b/webhook-bridge.py index 1e6c3b4..d87fcc3 100755 --- a/webhook-bridge.py +++ b/webhook-bridge.py @@ -274,6 +274,9 @@ def main(): player_uuid = action.uuid if action.name not in PLAYER_LIST.inv: PLAYER_LIST.inv[action.name] = action.uuid + else: + # Sometimes we get a duplicate add packet on join idk why + return if action.name not in UUID_CACHE.inv: UUID_CACHE.inv[action.name] = action.uuid # Initial tablist backfill @@ -295,8 +298,12 @@ def main(): ACCEPT_JOIN_EVENTS = True if config.es_enabled: diff = set(PREVIOUS_PLAYER_LIST.keys()) - set(PLAYER_LIST.keys()) - for uuid in diff: - es_connection(uuid=uuid, reason=ConnectionReason.DISCONNECTED, count=len(PLAYER_LIST)) + for idx, uuid in enumerate(diff): + es_connection(uuid=uuid, reason=ConnectionReason.DISCONNECTED, + count=len(PREVIOUS_PLAYER_LIST) - (idx + 1)) + # Don't bother announcing the bot's own join message (who cares) but log it for analytics still + if config.es_enabled: + es_connection(uuid=action.uuid, reason=ConnectionReason.CONNECTED, count=len(PLAYER_LIST)) if config.es_enabled: es_connection(uuid=action.uuid, reason=ConnectionReason.SEEN) @@ -312,10 +319,10 @@ def main(): } for webhook in WEBHOOKS: post = requests.post(webhook,json=webhook_payload) - if config.es_enabled: - es_connection(uuid=action.uuid, reason=ConnectionReason.DISCONNECTED, count=len(PLAYER_LIST)) del UUID_CACHE[action.uuid] del PLAYER_LIST[action.uuid] + if config.es_enabled: + es_connection(uuid=action.uuid, reason=ConnectionReason.DISCONNECTED, count=len(PLAYER_LIST)) def handle_join_game(join_game_packet): global PLAYER_LIST