Got rid of proxy methods in MatrixBot, v0.6.0

- Updated README.md
- Updated examples
- `MatrixBot` does not redefine methods from classes it is composed of anymore
This commit is contained in:
2026-09-27 16:17:40 +03:00
parent 16b849ebd8
commit 2867582c01
10 changed files with 107 additions and 311 deletions

View File

@@ -18,18 +18,18 @@ from _environment import check_environment
async def on_text_message(ctx: EventContext) -> None:
"""This callback is called when a text message arrives."""
await ctx.bot.send_text(ctx.room, "Please send a file/image/video")
await ctx.bot.send.text(ctx.room, "Please send a file/image/video")
async def on_file_message(ctx: EventContext) -> None:
"""This callback is called when a file arrives."""
sha = hashlib.sha256()
does_temp_exist = False
if ctx[CTX_FILE_SIZE] > 1_000_000:
await ctx.bot.send_text(
await ctx.bot.send.text(
ctx.room,
"The file is larger than 1 MB, downloading to filesystem"
)
await ctx.bot.download_file(ctx, path="temp.tmp")
await ctx.bot.download.file(ctx, path="temp.tmp")
async with aiofiles.open("temp.tmp", "rb") as f:
while True:
data = await f.read(64 * 1024)
@@ -38,16 +38,16 @@ async def on_file_message(ctx: EventContext) -> None:
sha.update(data)
does_temp_exist = True
else:
await ctx.bot.send_text(
await ctx.bot.send.text(
ctx.room,
"The file is smaller than 1 MB, downloading to RAM"
)
content = await ctx.bot.download_file(ctx, path=None)
content = await ctx.bot.download.file(ctx, path=None)
sha.update(content)
# result
response = f"SHA256 for file `{ctx[CTX_FILE_NAME]}`"
response += f" ({ctx[CTX_FILE_SIZE]} bytes, {ctx[CTX_FILE_MIME]})"
await ctx.bot.send_file_bytes(
await ctx.bot.send.file_bytes(
room=ctx.room,
data=sha.hexdigest().encode("utf-8"),
filename="hash of the file.txt",
@@ -56,7 +56,7 @@ async def on_file_message(ctx: EventContext) -> None:
)
# resend the file to test uploading
if does_temp_exist:
await ctx.bot.send_file(
await ctx.bot.send.file(
room=ctx.room,
path="temp.tmp",
filename=ctx[CTX_FILE_NAME],