Compare commits
2 Commits
b3ab94ef78
...
e94fc2d4d3
Author | SHA1 | Date |
---|---|---|
Bram van den Heuvel | e94fc2d4d3 | |
Bram van den Heuvel | 6a606a61f5 |
|
@ -7,10 +7,6 @@ WORKDIR /usr/src/app
|
|||
COPY requirements.txt ./
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# # Prepare MC server
|
||||
# COPY server.jar ./
|
||||
# RUN java -jar server.jar --nogui
|
||||
|
||||
COPY src/ ./src/
|
||||
COPY main.py ./
|
||||
|
||||
|
|
|
@ -38,4 +38,6 @@ services:
|
|||
- <your whitelist>:/usr/src/app/whitelist.json
|
||||
- <your world folder>:/usr/src/app/world
|
||||
- <your server jar file>:/usr/src/app/server.jar
|
||||
ports:
|
||||
- 25565:25565
|
||||
```
|
|
@ -39,11 +39,11 @@ matrix:
|
|||
# When multiple RegEx strings apply, all are included.
|
||||
alternative_platforms:
|
||||
Discord:
|
||||
match: "@_?discord_\d+:.+"
|
||||
match: "@_?discord_\\d+:.+"
|
||||
text: D
|
||||
color: aqua
|
||||
WhatsApp:
|
||||
match: "@whatsapp_\d+:.+"
|
||||
match: "@whatsapp_\\d+:.+"
|
||||
text: W
|
||||
color: green
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from typing import Any, List, Optional
|
|||
import yaml
|
||||
|
||||
with open('config.yaml', 'r') as open_file:
|
||||
SETTINGS = yaml.load(open_file)
|
||||
SETTINGS = yaml.load(open_file, Loader=yaml.Loader)
|
||||
|
||||
def at(keys : List[str]) -> Optional[Any]:
|
||||
"""
|
||||
|
|
|
@ -10,7 +10,7 @@ from typing import Union
|
|||
import asyncio
|
||||
import json
|
||||
import re
|
||||
from src.nbsr import NonBlockingStreamReader as NBSR
|
||||
from src.nbsr import NonBlockingStreamReader as NBSR, ProcessHasTerminated
|
||||
import src.config as config
|
||||
import src.build_server as build
|
||||
|
||||
|
@ -23,15 +23,24 @@ p = Popen(config.RUN_COMMAND,
|
|||
stdin = PIPE, stdout = PIPE, stderr = PIPE, shell = False)
|
||||
# wrap p.stdout with a NonBlockingStreamReader object:
|
||||
nbsr = NBSR(p.stdout)
|
||||
err_nbsr = NBSR(p.stderr)
|
||||
|
||||
async def start(client, mc_channel):
|
||||
"""
|
||||
Start reading from the Minecraft subprocess.
|
||||
"""
|
||||
# Provide 3 seconds to prepare the server
|
||||
await asyncio.sleep(3)
|
||||
|
||||
while True:
|
||||
output = nbsr.readline(0.1)
|
||||
try:
|
||||
output = nbsr.readline(0.1)
|
||||
except ProcessHasTerminated:
|
||||
print('==================================\nERROR LOGS :')
|
||||
|
||||
while True:
|
||||
output = err_nbsr.readline(0.1)
|
||||
print(output)
|
||||
# 0.1 secs to let the shell output the result
|
||||
if not output:
|
||||
await asyncio.sleep(1)
|
||||
|
@ -81,7 +90,7 @@ def process_message(sentence : str) -> Union[str, None]:
|
|||
r"\[[\d:]+\] \[Server thread\/INFO\]: Done \(\d+.?\d*s\)! For help, type \"help\"",
|
||||
sentence):
|
||||
server_live = True
|
||||
return f"The Minecraft server is live. The server is reacable at <code>{config.SERVER_IP}</code>.", f"The minecraft server is live. The server is reacable at <code>{config.SERVER_IP}</code>."
|
||||
return f"The Minecraft server is live. The server is reachable at <code>{config.SERVER_IP}</code>.", f"The minecraft server is live. The server is reachable at <code>{config.SERVER_IP}</code>."
|
||||
|
||||
if re.fullmatch(
|
||||
r"\[[\d:]+\] \[Server thread\/INFO\]: Stopping server",
|
||||
|
|
|
@ -46,6 +46,11 @@ class NonBlockingStreamReader:
|
|||
return self._q.get(block = timeout is not None,
|
||||
timeout = timeout)
|
||||
except Empty:
|
||||
return None
|
||||
if self._t.is_alive():
|
||||
return None
|
||||
else:
|
||||
raise ProcessHasTerminated
|
||||
|
||||
class UnexpectedEndOfStream(Exception): pass
|
||||
class UnexpectedEndOfStream(Exception): pass
|
||||
|
||||
class ProcessHasTerminated(Exception): pass
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
[]
|
Loading…
Reference in New Issue