Advancements
This commit is contained in:
parent
fb9257917c
commit
d13ab94d4b
40
service.py
40
service.py
|
@ -41,14 +41,12 @@ def on_receive_events(transaction):
|
||||||
and event["content"]["msgtype"] == "m.text"
|
and event["content"]["msgtype"] == "m.text"
|
||||||
and event["user_id"].find("@mc_") == -1
|
and event["user_id"].find("@mc_") == -1
|
||||||
):
|
):
|
||||||
|
|
||||||
m_user = USER_RE.search(event["user_id"]).group(0)
|
m_user = USER_RE.search(event["user_id"]).group(0)
|
||||||
m_cont = event["content"]["body"]
|
m_cont = event["content"]["body"]
|
||||||
m_user, m_cont
|
|
||||||
if global_msg_queue is not None:
|
if global_msg_queue is not None:
|
||||||
global_msg_queue.add({
|
global_msg_queue.add({
|
||||||
"command":
|
"user": m_user,
|
||||||
'/tellraw @a {"text":"<' + m_user + '> ' + m_cont + '","insertion":"/tellraw @p %s"}',
|
"msg": m_cont,
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
LOG.warning("No message queue available")
|
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.
|
# Not the end of the world if it fails, send the message now.
|
||||||
|
|
||||||
# attempt to post in room
|
# attempt to post in room
|
||||||
LOG.info("Attempting to post in Room")
|
if "action" in msg:
|
||||||
self.api._send(
|
if msg["action"] == "joined":
|
||||||
"PUT",
|
LOG.info("Setting {} to present".format(user_id))
|
||||||
"/rooms/" + room + "/send/m.room.message/" + txn_id,
|
self.api._send(
|
||||||
content={"msgtype": "m.text", "body": msg["msg"]},
|
"PUT",
|
||||||
query_params={"user_id": user_id},
|
"/presence/" + user_id + "/status",
|
||||||
headers={"Content-Type": "application/json"},
|
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):
|
def get_mc_skin(self, user, user_id):
|
||||||
LOG.info("Getting Minecraft Avatar")
|
LOG.info("Getting Minecraft Avatar")
|
||||||
|
|
35
wrapper.py
35
wrapper.py
|
@ -41,21 +41,26 @@ class ProcessWrapper:
|
||||||
def send_process_output(
|
def send_process_output(
|
||||||
process: ProcessWrapper, msg_queue: message_queue.MessageQueue
|
process: ProcessWrapper, msg_queue: message_queue.MessageQueue
|
||||||
):
|
):
|
||||||
# "[07:36:28] [Server thread/INFO] [minecraft/DedicatedServer]: <khr_> test"
|
|
||||||
log = LOG.getChild("process_output")
|
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:
|
for line in process:
|
||||||
log.info(line.rstrip("\n"))
|
log.info(line.rstrip("\n"))
|
||||||
result = prog.search(line)
|
chat_result = chat_pattern.search(line)
|
||||||
if result:
|
login_result = login_pattern.search(line)
|
||||||
log.info(
|
logout_result = logout_pattern.search(line)
|
||||||
"user: {} msg: {}".format(
|
if chat_result:
|
||||||
result.group(4), result.group(5).rstrip("\n"),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
msg_queue.add(
|
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(
|
def relay_queue_input(
|
||||||
|
@ -66,8 +71,14 @@ def relay_queue_input(
|
||||||
try:
|
try:
|
||||||
for message in msg_queue:
|
for message in msg_queue:
|
||||||
log.debug(message)
|
log.debug(message)
|
||||||
if "command" in message:
|
if "msg" in message:
|
||||||
command = message["command"] + "\n"
|
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))
|
log.debug("forwarding to process: {!r}".format(command))
|
||||||
process.send(command)
|
process.send(command)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue