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

11
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,9 +211,11 @@ 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):
print("Image was uploaded successfully to server. ")
gif_uri = response.content_uri
await client.room_send( await client.room_send(
room_id=room_id, room_id=room_id,
message_type="m.room.message", message_type="m.room.message",
@ -224,6 +226,9 @@ async def message_callback(client, room, event):
"info": {"mimetype": "image/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