peg line length at 80 and reformat
This commit is contained in:
parent
31da40aa4d
commit
4916559995
|
@ -21,9 +21,9 @@ from urllib.parse import urlparse
|
||||||
from matrix_client.api import MatrixHttpApi
|
from matrix_client.api import MatrixHttpApi
|
||||||
import PIL
|
import PIL
|
||||||
import requests
|
import requests
|
||||||
from flask import Flask, jsonify, request
|
import flask
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
minecraft = None
|
minecraft = None
|
||||||
roomsync = set()
|
roomsync = set()
|
||||||
|
|
||||||
|
@ -199,18 +199,23 @@ class MinecraftWrapper(socket_util):
|
||||||
|
|
||||||
def cli_poll(self):
|
def cli_poll(self):
|
||||||
prog = re.compile("\[.*\] \[(.*)\] \[(.*)\]: <(.*)> (.*)")
|
prog = re.compile("\[.*\] \[(.*)\] \[(.*)\]: <(.*)> (.*)")
|
||||||
EXAMPLE = (
|
EXAMPLE = "[07:36:28] [Server thread/INFO] [minecraft/DedicatedServer]: <khr_> test"
|
||||||
"[07:36:28] [Server thread/INFO] [minecraft/DedicatedServer]: <khr_> test"
|
|
||||||
)
|
|
||||||
for line in self.exe_mc():
|
for line in self.exe_mc():
|
||||||
self.logger.info(line.rstrip("\n"))
|
self.logger.info(line.rstrip("\n"))
|
||||||
result = prog.search(line)
|
result = prog.search(line)
|
||||||
if result:
|
if result:
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
"user: " + result.group(3) + " msg: " + result.group(4).rstrip("\n")
|
"user: "
|
||||||
|
+ result.group(3)
|
||||||
|
+ " msg: "
|
||||||
|
+ result.group(4).rstrip("\n")
|
||||||
)
|
)
|
||||||
self.msglist.insert(
|
self.msglist.insert(
|
||||||
0, {"user": result.group(3), "msg": result.group(4).rstrip("\n")}
|
0,
|
||||||
|
{
|
||||||
|
"user": result.group(3),
|
||||||
|
"msg": result.group(4).rstrip("\n"),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -234,7 +239,9 @@ class MinecraftServerBridge(socket_util):
|
||||||
# socket and other init
|
# socket and other init
|
||||||
super().__init__(minecraft_bind_host, minecraft_bind_port)
|
super().__init__(minecraft_bind_host, minecraft_bind_port)
|
||||||
LOG.info("Calling Matrix Api")
|
LOG.info("Calling Matrix Api")
|
||||||
self.api = MatrixHttpApi("http://localhost:8008", token=appservice_token)
|
self.api = MatrixHttpApi(
|
||||||
|
"http://localhost:8008", token=appservice_token
|
||||||
|
)
|
||||||
self.avatar_update_log = {}
|
self.avatar_update_log = {}
|
||||||
LOG.info("Finished Init")
|
LOG.info("Finished Init")
|
||||||
|
|
||||||
|
@ -327,7 +334,8 @@ class MinecraftServerBridge(socket_util):
|
||||||
LOG.info("Checking if we need to update avatar...")
|
LOG.info("Checking if we need to update avatar...")
|
||||||
if (
|
if (
|
||||||
msg["user"] not in self.avatar_update_log.keys()
|
msg["user"] not in self.avatar_update_log.keys()
|
||||||
or abs(self.avatar_update_log[msg["user"]] - time.time()) > 180
|
or abs(self.avatar_update_log[msg["user"]] - time.time())
|
||||||
|
> 180
|
||||||
):
|
):
|
||||||
self.avatar_update_log[msg["user"]] = time.time()
|
self.avatar_update_log[msg["user"]] = time.time()
|
||||||
avatar_url = self.get_mc_skin(msg["user"], user_id)
|
avatar_url = self.get_mc_skin(msg["user"], user_id)
|
||||||
|
@ -408,9 +416,9 @@ class MinecraftServerBridge(socket_util):
|
||||||
# POST /_matrix/media/r0/upload
|
# POST /_matrix/media/r0/upload
|
||||||
LOG.debug("Returning updated avatar")
|
LOG.debug("Returning updated avatar")
|
||||||
LOG.debug(image_buffer_head)
|
LOG.debug(image_buffer_head)
|
||||||
return self.api.media_upload(image_buffer_head.getvalue(), "image/png")[
|
return self.api.media_upload(
|
||||||
"content_uri"
|
image_buffer_head.getvalue(), "image/png"
|
||||||
]
|
)["content_uri"]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -421,7 +429,7 @@ USER_RE = re.compile("(?<=\@).*(?=\:)")
|
||||||
@app.route("/transactions/<transaction>", methods=["PUT"])
|
@app.route("/transactions/<transaction>", methods=["PUT"])
|
||||||
def on_receive_events(transaction):
|
def on_receive_events(transaction):
|
||||||
LOG.info("got event")
|
LOG.info("got event")
|
||||||
events = request.get_json()["events"]
|
events = flask.request.get_json()["events"]
|
||||||
for event in events:
|
for event in events:
|
||||||
LOG.info("User: %s Room: %s" % (event["user_id"], event["room_id"]))
|
LOG.info("User: %s Room: %s" % (event["user_id"], event["room_id"]))
|
||||||
LOG.info("Event Type: %s" % event["type"])
|
LOG.info("Event Type: %s" % event["type"])
|
||||||
|
@ -437,13 +445,13 @@ def on_receive_events(transaction):
|
||||||
m_cont = event["content"]["body"]
|
m_cont = event["content"]["body"]
|
||||||
# minecraft.msglist.insert(0, "/tellraw @a {\"text\":\"<" + m_user + "> " + m_cont + "\",\"insertion\":\"/tellraw @p %s\"}")
|
# minecraft.msglist.insert(0, "/tellraw @a {\"text\":\"<" + m_user + "> " + m_cont + "\",\"insertion\":\"/tellraw @p %s\"}")
|
||||||
|
|
||||||
return jsonify({})
|
return flask.jsonify({})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/rooms/<room>", methods=["GET"])
|
@app.route("/rooms/<room>", methods=["GET"])
|
||||||
def on_room(room):
|
def on_room(room):
|
||||||
LOG.info("returning: " + str(room))
|
LOG.info("returning: " + str(room))
|
||||||
return jsonify({})
|
return flask.jsonify({})
|
||||||
|
|
||||||
|
|
||||||
BRIDGE_CFG_SKELETON = {
|
BRIDGE_CFG_SKELETON = {
|
||||||
|
@ -500,7 +508,9 @@ def main():
|
||||||
config = make_config("wrapper.json", server=False)
|
config = make_config("wrapper.json", server=False)
|
||||||
ip_addr_info = socket.gethostbyname_ex(config["server_name"])
|
ip_addr_info = socket.gethostbyname_ex(config["server_name"])
|
||||||
minecraft = MinecraftWrapper(
|
minecraft = MinecraftWrapper(
|
||||||
args.command, host=ip_addr_info[2][0], port=config["wrapper_mcdata_port"],
|
args.command,
|
||||||
|
host=ip_addr_info[2][0],
|
||||||
|
port=config["wrapper_mcdata_port"],
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
LOG.info("Running Minecraft Matrix Bridge Mode")
|
LOG.info("Running Minecraft Matrix Bridge Mode")
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
[tool.black]
|
||||||
|
line-length = 80
|
||||||
|
target-version = ['py36']
|
Loading…
Reference in New Issue