mirror of
https://git.freetards.xyz/array.in.a.matrix/TexLiLy.git
synced 2025-04-02 13:21:42 -04:00
37 lines
951 B
Python
37 lines
951 B
Python
from nio import *
|
|
|
|
def set_client(c: AsyncClient) -> None:
|
|
global client
|
|
client = c
|
|
|
|
def get_client() -> AsyncClient:
|
|
return client
|
|
|
|
async def send_png(room: MatrixRoom, filename: str) -> None:
|
|
import imagesize
|
|
import os
|
|
basename = os.path.basename(filename)
|
|
w, h = imagesize.get(filename)
|
|
|
|
file = open(filename, "r+b")
|
|
size = os.path.getsize(filename)
|
|
|
|
filename = os.path.basename(filename)
|
|
resp, keys = await client.upload(file, content_type="image/png", filename=basename)
|
|
|
|
if not isinstance(resp, UploadResponse):
|
|
raise OSError("Couldn't upload file.")
|
|
|
|
content = {
|
|
"body": basename,
|
|
"info": {
|
|
"size": size,
|
|
"mimetype": "image/png",
|
|
"w": w, "h": h
|
|
},
|
|
"msgtype": "m.image",
|
|
"url": resp.content_uri,
|
|
}
|
|
file.close()
|
|
|
|
await client.room_send(room.room_id, message_type="m.room.message", content=content)
|