Refactoring in progress
- Context variables are no longer stored in `EventContext`, they are stored in `ContextVars` from now on - Context variables related stuff has been moved to `mab.context.vars` - Removed `CTX_FILE` - Changed variable builder name prefix to `autobuild_` - Changed variable builder signature to (EventContext, ContextVars) - Most examples are broken
This commit is contained in:
@@ -13,9 +13,9 @@ from mab import *
|
||||
|
||||
from _environment import check_environment
|
||||
|
||||
async def on_text_message(ctx: EventContext) -> None:
|
||||
async def on_text_message(ctx: EventContext, vars: ContextVars) -> None:
|
||||
"""This callback is called when a text message arrives."""
|
||||
await ctx.bot.send.text(ctx.room, ctx[CTX_MESSAGE].body)
|
||||
await ctx.bot.send.text(ctx.room, vars[CTX_MESSAGE].body)
|
||||
|
||||
async def main() -> None:
|
||||
"""Application entry point"""
|
||||
|
||||
@@ -24,7 +24,10 @@ 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:
|
||||
file = ctx[CTX_FILE]
|
||||
if not file.size:
|
||||
file.size = 0
|
||||
if file.size > 1_000_000:
|
||||
await ctx.bot.send.text(
|
||||
ctx.room,
|
||||
"The file is larger than 1 MB, downloading to filesystem"
|
||||
|
||||
@@ -22,7 +22,7 @@ async def on_gen_command(data: EventContext) -> None:
|
||||
"""This callback is called when `!gen R G B` command is received."""
|
||||
# convert R, G and B to floats
|
||||
try:
|
||||
r, g, b = [float(v) for v in data[CTX_CMD_ARGS]]
|
||||
r, g, b = [float(f) for f in data[CTX_MESSAGE].body.split()[1:]]
|
||||
except:
|
||||
await data.bot.send.text(data.room, "Invalid arguments")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user