Give up on ficing GIF upload.

Signed-off-by: Abdulkadir Furkan Şanlı <me@abdulocra.cy>
This commit is contained in:
Abdulkadir Furkan Şanlı 2024-01-23 18:38:31 +01:00
parent 242c0ba362
commit 734362014c
Signed by: afk
SSH Key Fingerprint: SHA256:s1hULLl4YWdqU501MUfGe1CAG/m1pf9Cs6vFsqeTNHk

31
main.py
View File

@ -14,7 +14,7 @@ from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build from googleapiclient.discovery import build
from googleapiclient import errors from googleapiclient import errors
from nio import AsyncClient, RoomMessageText, SyncResponse from nio import AsyncClient, RoomMessageText, SyncResponse, UploadResponse
DATA_DIR = os.getenv("DATA_DIR", "./") DATA_DIR = os.getenv("DATA_DIR", "./")
DB_PATH = os.path.join(DATA_DIR, "parkerbot.sqlite3") DB_PATH = os.path.join(DATA_DIR, "parkerbot.sqlite3")
@ -211,19 +211,24 @@ async def message_callback(client, room, event):
message_type="m.room.message", message_type="m.room.message",
content={"msgtype": "m.text", "body": intro_message}, content={"msgtype": "m.text", "body": intro_message},
) )
with open("./parker.gif", "rb") as gif_file: with open("./parker.gif", "rb") as gif_file: # this is broken as shit
response = await client.upload(gif_file, content_type="image/gif") response = await client.upload(gif_file, content_type="image/gif")
gif_uri = response[0] if isinstance(response, UploadResponse):
await client.room_send( print("Image was uploaded successfully to server. ")
room_id=room_id, gif_uri = response.content_uri
message_type="m.room.message", await client.room_send(
content={ room_id=room_id,
"msgtype": "m.image", message_type="m.room.message",
"url": gif_uri, content={
"body": "parker.gif", "msgtype": "m.image",
"info": {"mimetype": "image/gif"}, "url": gif_uri,
}, "body": "parker.gif",
) "info": {"mimetype": "image/gif"},
},
)
else:
print(f"Failed to upload image. Failure response: {resp}")
if body == "!pow" and current_time - timestamp_sec < datetime.timedelta( if body == "!pow" and current_time - timestamp_sec < datetime.timedelta(
seconds=30 seconds=30