Partial SyWeb compatibility
This commit is contained in:
@@ -27,11 +27,13 @@ client = Blueprint("c2s", __name__)
|
||||
@client.route("/_matrix/client/v3/rooms/<roomId>/read_markers", methods=["POST"])
|
||||
@client.route("/_matrix/client/r0/rooms/<roomId>/read_markers", methods=["POST"])
|
||||
@client.route("/_matrix/client/v3/rooms/<room>/typing/<user>", methods=["PUT"])
|
||||
@client.route("/_matrix/client/api/v1/rooms/<room>/typing/<user>", methods=["PUT"])
|
||||
@client.route("/_matrix/client/v3/keys/device_signing/upload", methods=["POST"])
|
||||
@client.route("/_matrix/client/v3/rooms/<room>/receipt/<type>/<event>", methods=["POST"])
|
||||
@client.route("/_matrix/client/v3/users/<user>/report", methods=["POST"])
|
||||
@client.route("/_matrix/client/v3/voip/turnServer")
|
||||
@client.route("/_matrix/client/r0/voip/turnServer")
|
||||
@client.route("/_matrix/client/api/v1/voip/turnServer")
|
||||
@client.route("/_matrix/client/v3/rooms/<r>/report/<e>")
|
||||
@client.route("/_matrix/client/v3/rooms/<r>/report")
|
||||
@client.route("/_matrix/client/v3/users/<u>/report")
|
||||
@@ -99,9 +101,10 @@ async def lock(user):
|
||||
return jsonify({"locked": True})
|
||||
|
||||
|
||||
@client.route("/_matrix/client/api/v1/rooms/<roomId>/members")
|
||||
@client.route("/_matrix/client/v3/rooms/<roomId>/members")
|
||||
@client.route("/_matrix/client/r0/rooms/<roomId>/members")
|
||||
async def room_member_count(roomId):
|
||||
async def room_members(roomId):
|
||||
return jsonify({
|
||||
"chunk": [{
|
||||
"content": {
|
||||
@@ -109,7 +112,7 @@ async def room_member_count(roomId):
|
||||
"displayname": "Vona",
|
||||
"membership": "join"
|
||||
},
|
||||
"event_id": globals.make_event_id(),
|
||||
"event_id": globals.make_event_id(seed=roomId),
|
||||
"origin_server_ts": config.the_funny_number,
|
||||
"room_id": roomId,
|
||||
"sender": f"@vona:{config.server_name}",
|
||||
@@ -128,6 +131,7 @@ async def whoami():
|
||||
})
|
||||
|
||||
|
||||
@client.route("/_matrix/client/v2_alpha/register", methods=["POST"])
|
||||
@client.route("/_matrix/client/v3/register", methods=["POST"])
|
||||
@client.route("/_matrix/client/v1/register", methods=["POST"])
|
||||
@client.route("/_matrix/client/r0/register", methods=["POST"])
|
||||
@@ -282,6 +286,7 @@ async def filter(**kwargs):
|
||||
return jsonify({"filter_id": "vvvooonnnaaa"})
|
||||
|
||||
|
||||
@client.route("/_matrix/client/api/v1/join/<room>", methods=["POST"])
|
||||
@client.route("/_matrix/client/v3/join/<room>", methods=["POST"])
|
||||
@client.route("/_matrix/client/r0/join/<room>", methods=["POST"])
|
||||
@client.route("/_matrix/client/v3/rooms/<room>/join", methods=["POST"])
|
||||
@@ -290,6 +295,7 @@ async def join(room):
|
||||
return jsonify({"room_id": room})
|
||||
|
||||
|
||||
@client.route("/_matrix/client/api/v1/initialSync")
|
||||
@client.route("/_matrix/client/v3/initialSync")
|
||||
@client.route("/_matrix/client/v3/sync")
|
||||
@client.route("/_matrix/client/r0/sync")
|
||||
@@ -298,39 +304,12 @@ async def sync():
|
||||
def get_json():
|
||||
return {}
|
||||
|
||||
async def remove_keys(l, keys_to_remove) -> dict:
|
||||
if not isinstance(l, list):
|
||||
return l
|
||||
|
||||
new_list = []
|
||||
for d in l:
|
||||
if not isinstance(d, dict):
|
||||
new_list.append(d)
|
||||
continue
|
||||
|
||||
new_dict = {}
|
||||
for k, v in d.items():
|
||||
if k in keys_to_remove:
|
||||
continue
|
||||
new_dict[k] = await remove_keys(v, keys_to_remove)
|
||||
new_list.append(new_dict)
|
||||
return new_list
|
||||
|
||||
room = globals.make_event_id().replace("$", "!")
|
||||
old_room_state = send_join(
|
||||
bullshit,
|
||||
room
|
||||
)["state"]
|
||||
|
||||
room_state = await remove_keys(
|
||||
old_room_state,
|
||||
[
|
||||
"auth_events",
|
||||
"prev_events",
|
||||
"signatures",
|
||||
"hashes",
|
||||
"depth"
|
||||
]
|
||||
room_state = globals.strip_state(
|
||||
send_join(
|
||||
bullshit,
|
||||
room
|
||||
)["state"]
|
||||
)
|
||||
|
||||
room_name = {
|
||||
@@ -383,6 +362,78 @@ async def sync():
|
||||
})
|
||||
|
||||
|
||||
@client.route("/_matrix/client/api/v1/rooms/<room>/initialSync")
|
||||
async def room_initsync(room):
|
||||
class bullshit:
|
||||
def get_json():
|
||||
return {}
|
||||
|
||||
room_state = globals.strip_state(
|
||||
send_join(
|
||||
bullshit,
|
||||
room
|
||||
)["state"]
|
||||
)
|
||||
|
||||
for evt in room_state:
|
||||
evt["age"] = config.the_funny_number
|
||||
|
||||
return jsonify({
|
||||
"membership": "join",
|
||||
"room_id": room,
|
||||
"messages": {
|
||||
"chunk": [
|
||||
{
|
||||
"age": config.the_funny_number,
|
||||
"content": {
|
||||
"msgtype": "m.text",
|
||||
"body": "Number 15: Burger King Foot Lettuce.\nThe last thing you'd want in your Burger King burger is someones foot fungus, but as it turns out, that might be what you get. A 4channer uploaded a photo, anonymously to the site showcasing his feet in a plastic bin of lettuce with the statement \"This is the lettuce you eat at Burger King.\". Admittedly, he had shoes on, but thats even worse. The post went live at 11:38 PM on July 16 and a mere 20 minutes later the Burger King in question was alerted to the rogue employee. At least, I hope hes rogue. How did it happen? Well, the BK employee hadn't removed the EXIF data from the uploaded photo, which suggested that the culprit was somewhere in Mayfield Heights, Ohio. This was at 11:47. 3 minutes later, at 11:50, the Burger King branch was posted with wishes of happy unemployment. 5 minutes later, the news station was contacted by another 4channer, and 3 minutes later at 11:58 a link was posted: BK's tell us about us online forum. The foot photo, otherwise known as Exhibit A, was attached. Cleveland Seen Magazine contacted the BK in question and the next day when questioned, the breakfast shift manager said \"Oh, I know who that is, hes getting fired\". Mystery solved, by 4chan. Now we can go back to eating our fast food in peace.",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": "Number 15: Burger King Foot Lettuce.<br />The last thing you'd want in your Burger King burger is someones foot fungus, but as it turns out, that might be what you get. A 4channer uploaded a photo, anonymously to the site showcasing his feet in a plastic bin of lettuce with the statement "This is the lettuce you eat at Burger King.". Admittedly, he had shoes on, but thats even worse. The post went live at 11:38 PM on July 16 and a mere 20 minutes later the Burger King in question was alerted to the rogue employee. At least, I hope hes rogue. How did it happen? Well, the BK employee hadn't removed the EXIF data from the uploaded photo, which suggested that the culprit was somewhere in Mayfield Heights, Ohio. This was at 11:47. 3 minutes later, at 11:50, the Burger King branch was posted with wishes of happy unemployment. 5 minutes later, the news station was contacted by another 4channer, and 3 minutes later at 11:58 a link was posted: BK's tell us about us online forum. The foot photo, otherwise known as Exhibit A, was attached. Cleveland Seen Magazine contacted the BK in question and the next day when questioned, the breakfast shift manager said "Oh, I know who that is, hes getting fired". Mystery solved, by 4chan. Now we can go back to eating our fast food in peace."
|
||||
},
|
||||
"event_id": globals.make_event_id(),
|
||||
"origin_server_ts": 1432804485886,
|
||||
"room_id": globals.make_event_id(),
|
||||
"type": "m.room.message",
|
||||
"user_id": f"@vona:{config.server_name}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"state": room_state
|
||||
})
|
||||
|
||||
|
||||
@client.route("/_matrix/client/api/v1/events")
|
||||
async def events():
|
||||
if "timeout" in request.args:
|
||||
try:
|
||||
await asyncio.sleep(int(request.args["timeout"]) / 1000)
|
||||
except:
|
||||
pass
|
||||
|
||||
return jsonify({
|
||||
"start": os.urandom(32).hex(),
|
||||
"end": os.urandom(32).hex(),
|
||||
"chunk": [
|
||||
{
|
||||
"age": config.the_funny_number,
|
||||
"content": {
|
||||
"msgtype": "m.text",
|
||||
"body": "Number 15: Burger King Foot Lettuce.\nThe last thing you'd want in your Burger King burger is someones foot fungus, but as it turns out, that might be what you get. A 4channer uploaded a photo, anonymously to the site showcasing his feet in a plastic bin of lettuce with the statement \"This is the lettuce you eat at Burger King.\". Admittedly, he had shoes on, but thats even worse. The post went live at 11:38 PM on July 16 and a mere 20 minutes later the Burger King in question was alerted to the rogue employee. At least, I hope hes rogue. How did it happen? Well, the BK employee hadn't removed the EXIF data from the uploaded photo, which suggested that the culprit was somewhere in Mayfield Heights, Ohio. This was at 11:47. 3 minutes later, at 11:50, the Burger King branch was posted with wishes of happy unemployment. 5 minutes later, the news station was contacted by another 4channer, and 3 minutes later at 11:58 a link was posted: BK's tell us about us online forum. The foot photo, otherwise known as Exhibit A, was attached. Cleveland Seen Magazine contacted the BK in question and the next day when questioned, the breakfast shift manager said \"Oh, I know who that is, hes getting fired\". Mystery solved, by 4chan. Now we can go back to eating our fast food in peace.",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": "Number 15: Burger King Foot Lettuce.<br />The last thing you'd want in your Burger King burger is someones foot fungus, but as it turns out, that might be what you get. A 4channer uploaded a photo, anonymously to the site showcasing his feet in a plastic bin of lettuce with the statement "This is the lettuce you eat at Burger King.". Admittedly, he had shoes on, but thats even worse. The post went live at 11:38 PM on July 16 and a mere 20 minutes later the Burger King in question was alerted to the rogue employee. At least, I hope hes rogue. How did it happen? Well, the BK employee hadn't removed the EXIF data from the uploaded photo, which suggested that the culprit was somewhere in Mayfield Heights, Ohio. This was at 11:47. 3 minutes later, at 11:50, the Burger King branch was posted with wishes of happy unemployment. 5 minutes later, the news station was contacted by another 4channer, and 3 minutes later at 11:58 a link was posted: BK's tell us about us online forum. The foot photo, otherwise known as Exhibit A, was attached. Cleveland Seen Magazine contacted the BK in question and the next day when questioned, the breakfast shift manager said "Oh, I know who that is, hes getting fired". Mystery solved, by 4chan. Now we can go back to eating our fast food in peace."
|
||||
},
|
||||
"event_id": globals.make_event_id(),
|
||||
"origin_server_ts": 1432804485886,
|
||||
"room_id": globals.make_event_id(),
|
||||
"type": "m.room.message",
|
||||
"user_id": f"@vona:{config.server_name}"
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
@client.route("/_matrix/client/api/v1/rooms/<room>/send/<eventType>/<txnId>", methods=["POST", "PUT"])
|
||||
@client.route("/_matrix/client/v3/rooms/<room>/send/<eventType>/<txnId>", methods=["POST", "PUT"])
|
||||
@client.route("/_matrix/client/r0/rooms/<room>/send/<eventType>/<txnId>", methods=["POST", "PUT"])
|
||||
async def send_message(room, eventType, txnId):
|
||||
@@ -575,6 +626,7 @@ async def media_config():
|
||||
return jsonify({"m.upload.size": config.the_funny_number * 69420})
|
||||
|
||||
|
||||
@client.route("/_matrix/client/api/v1/profile/<userId>/<key>", methods=["GET", "PUT", "DELETE"])
|
||||
@client.route("/_matrix/client/v3/profile/<userId>/<key>", methods=["GET", "PUT", "DELETE"])
|
||||
@client.route("/_matrix/client/r0/profile/<userId>/<key>", methods=["GET", "PUT", "DELETE"])
|
||||
async def profile_keys(userId, key):
|
||||
@@ -601,6 +653,7 @@ async def user_profile(userId):
|
||||
})
|
||||
|
||||
|
||||
@client.route("/_matrix/client/api/v1/rooms/<roomId>/messages")
|
||||
@client.route("/_matrix/client/v3/rooms/<roomId>/messages")
|
||||
@client.route("/_matrix/client/r0/rooms/<roomId>/messages")
|
||||
async def room_messages(roomId):
|
||||
@@ -652,6 +705,7 @@ async def mutual_rooms():
|
||||
})
|
||||
|
||||
|
||||
@client.route("/_matrix/client/api/v1/presence/<user>/status", methods=["GET", "PUT"])
|
||||
@client.route("/_matrix/client/r0/presence/<user>/status", methods=["GET", "PUT"])
|
||||
async def presence(user):
|
||||
if request.method == "PUT":
|
||||
@@ -660,7 +714,20 @@ async def presence(user):
|
||||
return jsonify({"presence": "online"})
|
||||
|
||||
|
||||
@client.route("/_matrix/client/api/v1/publicRooms", methods=["GET", "POST"])
|
||||
@client.route("/_matrix/client/v3/publicRooms", methods=["GET", "POST"])
|
||||
@client.route("/_matrix/client/r0/publicRooms", methods=["GET", "POST"])
|
||||
async def room_directory():
|
||||
return jsonify(globals.room_dir)
|
||||
|
||||
|
||||
@client.route("/_matrix/client/api/v1/rooms/<room>/state/<evttype>/<key>", methods=["GET", "PUT"])
|
||||
@client.route("/_matrix/client/api/v1/rooms/<room>/state/<evttype>/", methods=["GET", "PUT"])
|
||||
async def state(room, evttype, key=None):
|
||||
if request.method == "GET":
|
||||
return jsonify({
|
||||
"errcode": "M_NOT_FOUND",
|
||||
"error": f"Event with type {evttype} and key {key} not found"
|
||||
}), 404
|
||||
|
||||
return jsonify({"event_id": os.urandom(5).hex()})
|
||||
|
||||
@@ -347,3 +347,30 @@ class http_client:
|
||||
headers=headers,
|
||||
extensions={"sni_hostname": resolved.sni}
|
||||
)
|
||||
|
||||
|
||||
def strip_state(l) -> dict:
|
||||
if not isinstance(l, list):
|
||||
return l
|
||||
|
||||
keys_to_remove = [
|
||||
"auth_events",
|
||||
"prev_events",
|
||||
"signatures",
|
||||
"hashes",
|
||||
"depth"
|
||||
]
|
||||
|
||||
new_list = []
|
||||
for d in l:
|
||||
if not isinstance(d, dict):
|
||||
new_list.append(d)
|
||||
continue
|
||||
|
||||
new_dict = {}
|
||||
for k, v in d.items():
|
||||
if k in keys_to_remove:
|
||||
continue
|
||||
new_dict[k] = strip_state(v)
|
||||
new_list.append(new_dict)
|
||||
return new_list
|
||||
|
||||
Reference in New Issue
Block a user