Remove need for touch, move variables to a config

Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
Skylar "The Cobra" Widulski 2023-11-25 18:23:05 -05:00
parent 98ec16ae54
commit ead0ad8b0a
Signed by: cobra
GPG Key ID: 4FD8F812083FF6F9
3 changed files with 16 additions and 17 deletions

View File

@ -12,15 +12,13 @@ python3 -m venv venv
pip3 install -r requirements.txt
```
Next, initialize the files needed:
Then, edit the config to fit your use-case.
```
touch next_batch
mkfifo logpipe
cp config.py.example config.py
$EDITOR config.py
```
Then, edit the script variables to fit your use-case.
Finally, run the script:
```

9
config.py.example Normal file
View File

@ -0,0 +1,9 @@
mx_room_id = "!roomid:matrix.org"
mx_user_id = "@my-xonotic-bridge:matrix.org"
mx_homeserver = "https://matrix-client.matrix.org"
mx_pass = "XXXXXXXX"
xon_host = "127.0.0.1"
xon_port = 26000
xon_name = "Xonotic 0.8.6"
xon_pass = "XXXXXXXX"

View File

@ -24,19 +24,11 @@ import os
import sys
from xrcon.client import XRcon
import subprocess
from config import (mx_room_id, mx_user_id, mx_homeserver, mx_pass,
xon_host, xon_port, xon_name, xon_pass)
source_url = 'http://git.vern.cc/cobra/xonotic-bridge'
mx_room_id = "!roomid:matrix.org"
mx_user_id = "@my-xonotic-bridge:matrix.org"
mx_homeserver = "https://matrix-client.matrix.org"
mx_pass = "XXXXXXXX"
xon_host = "127.0.0.1"
xon_port = 26000
xon_name = "Xonotic 0.8.6"
xon_pass = "correct horse battery staple"
def esc(string):
return string.replace('\n', ' ')
@ -64,12 +56,12 @@ class XonoticBridge:
async def watch_xon(self):
lastdata = ''
os.mkfifo('logpipe', 0o600)
async with aiofiles.open('logpipe') as fifo:
while (True):
if (self.client.logged_in):
try:
async for data in fifo:
#data = await fifo.read()
print(data)
if data != '' and data != lastdata:
if not data.startswith(f"<{xon_name}> @"):
@ -89,7 +81,7 @@ class XonoticBridge:
while (True):
sync_response = await self.client.sync(30000)
with open("next_batch","w") as next_batch_token:
with open("next_batch","w+") as next_batch_token:
next_batch_token.write(sync_response.next_batch)
if len(sync_response.rooms.join) > 0: