Skip to content

Commit

Permalink
Merge pull request #16 from uzair-ashraf/uzair/15-external-config-file
Browse files Browse the repository at this point in the history
15 - User can change port number for OSC data
  • Loading branch information
shadorki authored Jan 17, 2023
2 parents dbd0b7f + a4f8791 commit d047541
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__pycache__
build
build
vrc-discord-osc.config.json
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ A python application for VRChat players to receive discord notifications on thei

- [Installation](#installation)
- [Contributing](#contributing)
- [Setting a different port number](#setting-a-different-port-number)
- [Setting up your avatar](#setting-up-your-avatar)

## Installation
Expand Down Expand Up @@ -57,7 +58,23 @@ Head over to the [Releases](https://github.com/uzair-ashraf/vrc-osc-discord-band

This repository is setup with a Github action to compile the standalone executable. If you would like to compile it on your local machine you can read the action for the command via `pyinstaller` [here](./.github/workflows/release.yml).

### Setting up your avatar
## Setting a different port number

---

In the same directory your executable is located in, create a file named `vrc-discord-osc.config.json`

In the file add the following contents, and change `9000` to the port you'd like to send your OSC data to.

```json
{
"port": 9000
}
```

If you did it properly the next time you run your application, the terminal window should state the port number you set.

## Setting up your avatar

---

Expand Down
19 changes: 19 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json


def get_port_number() -> int:
port = 9000
try:
f = open('./vrc-discord-osc.config.json')
data = json.load(f)
f.close()
if ("port" in data):
if type(data['port']) is int:
print(f"Using port {data['port']}.")
port = data['port']
except:
print("Config file not found...")
finally:
if port == 9000:
print("Defaulting to port 9000.")
return port
4 changes: 2 additions & 2 deletions discord_band.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


class DiscordBand:
def __init__(self):
self.osc_client = SimpleUDPClient("127.0.0.1", 9000)
def __init__(self, port: int):
self.osc_client = SimpleUDPClient("127.0.0.1", port or 9000)
self.is_enabled = False
self.is_disposing = False
self.disable_timer = 0
Expand Down
9 changes: 6 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import config
from discord_band import DiscordBand
from windows import Windows
from winsdk.windows.ui.notifications import UserNotification
Expand All @@ -20,10 +21,11 @@ async def init(discord_band: DiscordBand, windows: Windows):
windows.add_notification_listener(handler(discord_band))
await windows.run()


discord_band = DiscordBand()
discord_band = None
try:
print("Starting VRC Discord Notifications...")
port = config.get_port_number()
discord_band = DiscordBand(port)
windows = Windows()
asyncio.run(init(discord_band, windows))
except KeyboardInterrupt:
Expand All @@ -32,4 +34,5 @@ async def init(discord_band: DiscordBand, windows: Windows):
print(e)
input("Caught issue with Windows\n")
finally:
discord_band.dispose()
if discord_band != None:
discord_band.dispose()

0 comments on commit d047541

Please sign in to comment.