Skip to content

Commit

Permalink
2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCommCraft committed Apr 19, 2024
1 parent 4a16495 commit 5d31b4c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ To connect to Turbowarps Cloud Variables you can use the `scratchcommunication.c

```python
tw_cloud = scratchcommunication.TwCloudConnection(
contact_info = "Your contact info", # Specify some contact info. Turbowarp will block your connection otherwise.
project_id = "Your project id here",
username = "player1000", # (Optional)
quickaccess = False,
Expand All @@ -97,15 +98,15 @@ tw_cloud = scratchcommunication.TwCloudConnection(
warning_type = ErrorInEventHandler,
cloud_host = "wss://clouddata.turbowarp.org/", # (Optional) Changes the host used for cloud variables.
accept_strs = False, # (Optional) Allows you to set cloud variables to strings. Only works if cloud host allows it.
keep_all_events = False, # (Optional) Allows you to disable automatic garbage disposal of events. Events can still be manually disposed of. Unrecommended because it will slowly but surely fill up a lot of memory if events aren't disposed of.
contact_info = None # (Optional) Allows you to give turbowarp your contact info. If you don't add any it defaults to your session username or nothing.
keep_all_events = False # (Optional) Allows you to disable automatic garbage disposal of events. Events can still be manually disposed of. Unrecommended because it will slowly but surely fill up a lot of memory if events aren't disposed of.
)
```

Or you could connect from your session

```python
tw_cloud = session.create_turbowarp_cloudconnection(
contact_info = "Your contact info",
project_id = "Your project id here",
username = None, # (Optional) Will default to your username
quickaccess = False,
Expand All @@ -114,11 +115,12 @@ tw_cloud = session.create_turbowarp_cloudconnection(
warning_type = ErrorInEventHandler,
cloud_host = "wss://clouddata.turbowarp.org/",
accept_strs = False,
keep_all_events = False,
contact_info = None
keep_all_events = False
)
```

**Warning: You need to add sufficient contact_info for your turbowarp connection or it might not work!**

To shorten it a bit you can also use `scratchcommunication.session.Session.create_tw_cloudconnection` instead of `scratchcommunication.session.Session.create_turbowarp_cloudconnection`.

## Working with cloud variables
Expand Down Expand Up @@ -290,6 +292,7 @@ You can also use Turbowarp for cloud sockets.

```python
cloud_socket = session.create_turbowarp_cloud_socket( # session.create_tw_cloud_socket also works here
contact_info = "Your contact info",
project_id = "Your project id here",
packet_size = 220, # (Optional) I recommend leaving this value be if you only use Scratch and Turbowarp.
cloudconnection_kwargs = None, # (Optional) Allows for adding keyword arguments for the Cloud Connection used in the cloud socket. Look at the documentation for Cloud Connection if you do not know which keyword arguments there are
Expand Down
7 changes: 4 additions & 3 deletions scratchcommunication/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def __init__(
cloud_host : str = "wss://clouddata.turbowarp.org/",
accept_strs : bool = False,
keep_all_events : bool = False,
contact_info : str = None
contact_info : str
):
super().__init__(
project_id=project_id,
Expand All @@ -475,7 +475,8 @@ def __init__(
keep_all_events=keep_all_events
)
self.supports_cloud_logs = False
self.contact_info = contact_info or ("@"+session.username if session else "Anonymous")
self.contact_info = contact_info or ((f"@{session.username} on scratch" if session else "Anonymous") if username == "player1000" else f"@{username} on scratch")
assert self.contact_info != "Anonymous", "You need to specify your contact_info for the turbowarp cloud."
self.user_agent = f"scratchcommunication - {self.contact_info}"
self.cloud_host = cloud_host
self.accept_strs = accept_strs
Expand All @@ -495,7 +496,7 @@ def _connect(self, *, cloud_host = None, retry : int = 10):
if cloud_host is not None:
self.cloud_host = cloud_host
self.websocket = WebSocket()
self.websocket.connect(self.cloud_host, enable_multithread=True, timeout=5, header={"user-agent": self.user_agent})
self.websocket.connect(self.cloud_host, enable_multithread=True, timeout=5, header={"User-Agent": self.user_agent})
self.handshake()
self.emit_event("connect")
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions scratchcommunication/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ def create_cloud_socket(self, project_id : int, *, packet_size : int = 220, clou
'''
return cloud_socket.CloudSocket(cloud=self.create_cloudconnection(project_id, warning_type=ErrorInCloudSocket, **(cloudconnection_kwargs if cloudconnection_kwargs else {})), packet_size=packet_size, security=security, **kwargs)

def create_turbowarp_cloud_socket(self, project_id : int, *, packet_size : int = 90000, cloudconnection_kwargs : dict = None, security : tuple = None, **kwargs):
def create_turbowarp_cloud_socket(self, contact_info : str, project_id : int, *, packet_size : int = 90000, cloudconnection_kwargs : dict = None, security : tuple = None, **kwargs):
'''
Create a cloud socket to a turbowarp project.
'''
return cloud_socket.CloudSocket(cloud=self.create_tw_cloudconnection(project_id, warning_type=ErrorInCloudSocket, **(cloudconnection_kwargs if cloudconnection_kwargs else {})), packet_size=packet_size, security=security, **kwargs)
return cloud_socket.CloudSocket(cloud=self.create_tw_cloudconnection(project_id, contact_info=contact_info, warning_type=ErrorInCloudSocket, **(cloudconnection_kwargs if cloudconnection_kwargs else {})), packet_size=packet_size, security=security, **kwargs)

def create_tw_cloud_socket(self, *args, **kwargs):
'''
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='scratchcommunication',
version='2.4.1',
version='2.4.2',
author='Simon Gilde',
author_email='simon.c.gilde@gmail.com',
description='A python module for communicating with scratch projects',
Expand Down

0 comments on commit 5d31b4c

Please sign in to comment.