Skip to content

Commit

Permalink
Merge pull request #13 from offish/v2.0.7
Browse files Browse the repository at this point in the history
fix pricestf socket crashing
  • Loading branch information
offish authored Nov 4, 2023
2 parents c0528f6 + f17245b commit e8ab76f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/tf2_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = "tf2-utils"
__author__ = "offish"
__version__ = "2.0.6"
__version__ = "2.0.7"
__license__ = "MIT"

from .sku import get_sku, get_sku_properties, sku_to_defindex
Expand Down
21 changes: 18 additions & 3 deletions src/tf2_utils/sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json

from websockets.sync.client import connect
from websockets.sync.client import ClientConnection, connect


class BackpackTFSocket:
Expand Down Expand Up @@ -70,8 +70,23 @@ def __init__(
self.prices_tf = PricesTF()
self.settings = settings

def process_message(self, message: str) -> None:
def process_message(self, ws: ClientConnection, message: str) -> None:
data = json.loads(message)

# our auths are only valid for 10 minutes at a time
# pricestf requests us to authenticate again
if data.get("type") == "AUTH_REQUIRED":
self.prices_tf.request_access_token()
ws.send(
json.dumps(
{
"type": "AUTH",
"data": {"accessToken": self.prices_tf.access_token},
}
)
)
return

self.callback(data)

def listen(self) -> None:
Expand All @@ -86,4 +101,4 @@ def listen(self) -> None:
) as websocket:
while True:
message = websocket.recv()
self.process_message(message)
self.process_message(websocket, message)

0 comments on commit e8ab76f

Please sign in to comment.