mirror of
https://github.com/EDCD/EDDN.git
synced 2025-04-25 20:52:13 +03:00
core/DuplicateMessages: black / quotes pass
This commit is contained in:
parent
20d784ae09
commit
32fb1b00ab
@ -41,33 +41,33 @@ class DuplicateMessages(Thread):
|
|||||||
"""Detect if the given message is in the duplicates cache."""
|
"""Detect if the given message is in the duplicates cache."""
|
||||||
with self.lock:
|
with self.lock:
|
||||||
# Test messages are never duplicate, would be a pain to wait for another test :D
|
# Test messages are never duplicate, would be a pain to wait for another test :D
|
||||||
if re.search('test', json['$schemaRef'], re.I):
|
if re.search("test", json["$schemaRef"], re.I):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Shallow copy, minus headers
|
# Shallow copy, minus headers
|
||||||
json_test = {
|
json_test = {
|
||||||
'$schemaRef': json['$schemaRef'],
|
"$schemaRef": json["$schemaRef"],
|
||||||
'message': dict(json['message']),
|
"message": dict(json["message"]),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove timestamp (Mainly to avoid multiple scan messages and faction influences)
|
# Remove timestamp (Mainly to avoid multiple scan messages and faction influences)
|
||||||
json_test['message'].pop('timestamp')
|
json_test["message"].pop("timestamp")
|
||||||
|
|
||||||
# Convert journal starPos to avoid software modification in dupe messages
|
# Convert journal starPos to avoid software modification in dupe messages
|
||||||
if 'StarPos' in json_test['message']:
|
if "StarPos" in json_test["message"]:
|
||||||
json_test['message']['StarPos'] = [int(round(x * 32)) for x in json_test['message']['StarPos']]
|
json_test["message"]["StarPos"] = [int(round(x * 32)) for x in json_test["message"]["StarPos"]]
|
||||||
|
|
||||||
# Prevent journal Docked event with small difference in distance from start
|
# Prevent journal Docked event with small difference in distance from start
|
||||||
if 'DistFromStarLS' in json_test['message']:
|
if "DistFromStarLS" in json_test["message"]:
|
||||||
json_test['message']['DistFromStarLS'] = int(json_test['message']['DistFromStarLS'] + 0.5)
|
json_test["message"]["DistFromStarLS"] = int(json_test["message"]["DistFromStarLS"] + 0.5)
|
||||||
|
|
||||||
# Remove journal ScanType and DistanceFromArrivalLS (Avoid duplicate scan messages after SAAScanComplete)
|
# Remove journal ScanType and DistanceFromArrivalLS (Avoid duplicate scan messages after SAAScanComplete)
|
||||||
json_test['message'].pop('ScanType', None)
|
json_test["message"].pop("ScanType", None)
|
||||||
json_test['message'].pop('DistanceFromArrivalLS', None)
|
json_test["message"].pop("DistanceFromArrivalLS", None)
|
||||||
|
|
||||||
message = simplejson.dumps(json_test, sort_keys=True) # Ensure most duplicate messages will get the same
|
message = simplejson.dumps(json_test, sort_keys=True) # Ensure most duplicate messages will get the same
|
||||||
# key
|
# key
|
||||||
key = hashlib.sha256(message.encode('utf8')).hexdigest()
|
key = hashlib.sha256(message.encode("utf8")).hexdigest()
|
||||||
|
|
||||||
if key not in self.caches:
|
if key not in self.caches:
|
||||||
self.caches[key] = datetime.utcnow()
|
self.caches[key] = datetime.utcnow()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user