1
0
Fork 0

Advancements

This commit is contained in:
khr 2020-04-02 23:20:38 -07:00
parent fb9257917c
commit d13ab94d4b
2 changed files with 51 additions and 24 deletions

View File

@ -41,14 +41,12 @@ def on_receive_events(transaction):
and event["content"]["msgtype"] == "m.text"
and event["user_id"].find("@mc_") == -1
):
m_user = USER_RE.search(event["user_id"]).group(0)
m_cont = event["content"]["body"]
m_user, m_cont
if global_msg_queue is not None:
global_msg_queue.add({
"command":
'/tellraw @a {"text":"<' + m_user + '> ' + m_cont + '","insertion":"/tellraw @p %s"}',
"user": m_user,
"msg": m_cont,
})
else:
LOG.warning("No message queue available")
@ -135,14 +133,32 @@ class Appservice:
# Not the end of the world if it fails, send the message now.
# attempt to post in room
LOG.info("Attempting to post in Room")
self.api._send(
"PUT",
"/rooms/" + room + "/send/m.room.message/" + txn_id,
content={"msgtype": "m.text", "body": msg["msg"]},
query_params={"user_id": user_id},
headers={"Content-Type": "application/json"},
)
if "action" in msg:
if msg["action"] == "joined":
LOG.info("Setting {} to present".format(user_id))
self.api._send(
"PUT",
"/presence/" + user_id + "/status",
content={"presence":"online"},
headers={"Content-Type": "application/json"},
)
elif msg["action"] == "left":
LOG.info("Setting {} to offline".format(user_id))
self.api._send(
"PUT",
"/presence/" + user_id + "/status",
content={"presence":"offline"},
headers={"Content-Type": "application/json"},
)
if "msg" in msg:
LOG.info("Attempting to post in Room")
self.api._send(
"PUT",
"/rooms/" + room + "/send/m.room.message/" + txn_id,
content={"msgtype": "m.text", "body": msg["msg"]},
query_params={"user_id": user_id},
headers={"Content-Type": "application/json"},
)
def get_mc_skin(self, user, user_id):
LOG.info("Getting Minecraft Avatar")

View File

@ -41,21 +41,26 @@ class ProcessWrapper:
def send_process_output(
process: ProcessWrapper, msg_queue: message_queue.MessageQueue
):
# "[07:36:28] [Server thread/INFO] [minecraft/DedicatedServer]: <khr_> test"
log = LOG.getChild("process_output")
prog = re.compile(r"(\[.*\] )?\[(.*)\] \[(.*)\]: <(.*)> (.*)")
# "[07:36:28] [Server thread/INFO] [minecraft/DedicatedServer]: <khr_> test"
chat_pattern = re.compile(r"(\[.*\] )?\[(.*)\] \[(.*)\]: <(.*)> (.*)")
# "[05:09:54] [Server thread/INFO] [minecraft/DedicatedServer]: khr_ joined the game"
login_pattern = re.compile(r"\[.*\] \[(.*)\] \[(.*)\]: ([^ ]*]) joined the game")
# "[05:12:24] [Server thread/INFO] [minecraft/DedicatedServer]: khr_ left the game"
logout_pattern = re.compile(r"\[.*\] \[(.*)\] \[(.*)\]: ([^ ]*]) left the game")
for line in process:
log.info(line.rstrip("\n"))
result = prog.search(line)
if result:
log.info(
"user: {} msg: {}".format(
result.group(4), result.group(5).rstrip("\n"),
)
)
chat_result = chat_pattern.search(line)
login_result = login_pattern.search(line)
logout_result = logout_pattern.search(line)
if chat_result:
msg_queue.add(
{"user": result.group(4), "msg": result.group(5).rstrip("\n")},
{"user": result.group(4), "action": "chat", "msg": result.group(5).rstrip("\n")},
)
elif login_result:
msg_queue.add({"user": result.group(3), "action": "joined"})
elif logout_result:
msg_queue.add({"user": result.group(3), "action": "left"})
def relay_queue_input(
@ -66,8 +71,14 @@ def relay_queue_input(
try:
for message in msg_queue:
log.debug(message)
if "command" in message:
command = message["command"] + "\n"
if "msg" in message:
tellraw_params = {
"text": "<{}> {}".format(
message["user"], message["msg"]
),
"insertion": "/tellraw @p %s",
}
command = "/tellraw @a {}\n".format(tellraw_params)
log.debug("forwarding to process: {!r}".format(command))
process.send(command)
else: