Added overloads for MatrixBot.download_file
This commit is contained in:
@@ -52,9 +52,6 @@ async def on_image(ctx: EventContext) -> None:
|
|||||||
s = time.time()
|
s = time.time()
|
||||||
data = await ctx.bot.download_file(ctx)
|
data = await ctx.bot.download_file(ctx)
|
||||||
took_time = time.time() - s
|
took_time = time.time() - s
|
||||||
if not isinstance(data, bytes):
|
|
||||||
await ctx.bot.send_text(ctx.room, "😧")
|
|
||||||
return
|
|
||||||
# convert to Image
|
# convert to Image
|
||||||
with BytesIO(data) as buf:
|
with BytesIO(data) as buf:
|
||||||
img = Image.open(buf)
|
img = Image.open(buf)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from typing import Callable, Coroutine, Any
|
from typing import Callable, Coroutine, Any, overload
|
||||||
|
|
||||||
from nio import AsyncClient, MatrixRoom, Event
|
from nio import AsyncClient, MatrixRoom, Event
|
||||||
|
|
||||||
@@ -252,6 +252,18 @@ class MatrixBot:
|
|||||||
timeout=timeout
|
timeout=timeout
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@overload
|
||||||
|
async def download_file(self,
|
||||||
|
source: EventContext | Event,
|
||||||
|
*,
|
||||||
|
path: str | Path) -> Path: ...
|
||||||
|
|
||||||
|
@overload
|
||||||
|
async def download_file(self,
|
||||||
|
source: EventContext | Event,
|
||||||
|
*,
|
||||||
|
path: None = None) -> bytes: ...
|
||||||
|
|
||||||
async def download_file(self,
|
async def download_file(self,
|
||||||
source: EventContext | Event,
|
source: EventContext | Event,
|
||||||
*,
|
*,
|
||||||
|
|||||||
Reference in New Issue
Block a user