Skip to content

Instantly share code, notes, and snippets.

@catboy1357
Last active August 30, 2022 20:42
Show Gist options
  • Save catboy1357/d9ccf75f7fd92795aa374617ec2bec8e to your computer and use it in GitHub Desktop.
Save catboy1357/d9ccf75f7fd92795aa374617ec2bec8e to your computer and use it in GitHub Desktop.
Scripts to test the new chat box
# This requires the following packages:
## python-osc, a txt file, Bee movie script = https://gist.github.com/MattIPv4/045239bc27b16b2bcf7a3a9a4648c08a
from posixpath import split
import sys, time, math
from pythonosc import udp_client
# Global variables
text = None
client = udp_client.SimpleUDPClient("127.0.0.1", 9000)
file_path = "C:/Your/Derectory/Path"
# split and append if the text is longer than 144 characters
def load_text():
global text
text_len = 144
with open(file_path) as f:
text = f.read().splitlines()
# split the text if it is longer than 144
split_text = []
for txt in text:
if len(txt) > text_len:
temp = txt[:text_len]
else:
split_text.append(txt)
text = split_text
# Main loop, no way to exit other then ctrl+c
def main():
while True:
for idx, val in enumerate(text):
# check if the value is unicode
if not val.isascii():
print("Message is not ascii " + val)
continue
client.send_message("/chatbox/input", [val, True])
print(f"{idx}: {val}")
time.sleep(1.5)
# exits the code nicely
if __name__ == '__main__':
try:
load_text()
main()
except KeyboardInterrupt as e:
client.send_message("/chatbox/input", ["Exit", True])
print('Exit')
sys.exit(e)
except:
raise
from pythonosc import udp_client
# get the input from the user and send it to the OSC server
client = udp_client.SimpleUDPClient("127.0.0.1", 9000)
while True:
message = input("Enter message: ")
# if it does, check if the message is '/quit'
if message == '/quit' or message == '/q':
break
# check if message is ascii
if not message.isascii():
print("Message is not ascii")
continue
# print("Sending message: " + message)
client.send_message("/chatbox/input", [message, True])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment