Added CTX_FILE variable
- Modified file_bot.py example to utilize CTX_FILE - Removed docstring for message builders.py - Removed mab.models namespace package
This commit is contained in:
@@ -24,7 +24,7 @@ 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:
|
||||
if ctx[CTX_FILE].size > 1_000_000:
|
||||
await ctx.bot.send.text(
|
||||
ctx.room,
|
||||
"The file is larger than 1 MB, downloading to filesystem"
|
||||
@@ -45,8 +45,8 @@ async def on_file_message(ctx: EventContext) -> 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]})"
|
||||
response = f"SHA256 for file `{ctx[CTX_FILE].filename}`"
|
||||
response += f" ({ctx[CTX_FILE].size} bytes, {ctx[CTX_FILE].filename})"
|
||||
await ctx.bot.send.file_bytes(
|
||||
room=ctx.room,
|
||||
data=sha.hexdigest().encode("utf-8"),
|
||||
@@ -59,7 +59,7 @@ async def on_file_message(ctx: EventContext) -> None:
|
||||
await ctx.bot.send.file(
|
||||
room=ctx.room,
|
||||
path="temp.tmp",
|
||||
filename=ctx[CTX_FILE_NAME],
|
||||
filename=ctx[CTX_FILE].filename,
|
||||
text="This is the file you have sent, but it was reuploaded"
|
||||
)
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user