Added CTX_ROOM_EVENT
This commit is contained in:
@@ -34,7 +34,6 @@ async def on_help_message(ctx: EventContext, vars: ContextVars) -> None:
|
||||
|
||||
async def on_cmd_create(ctx: EventContext, vars: ContextVars) -> None:
|
||||
"""!create"""
|
||||
raise NotImplementedError()
|
||||
await ctx.bot.rooms.create()
|
||||
alias = "".join([random.choice("abcdefghj") for i in range(10)])
|
||||
name = alias.capitalize()
|
||||
@@ -44,7 +43,7 @@ async def on_cmd_create(ctx: EventContext, vars: ContextVars) -> None:
|
||||
alias=alias,
|
||||
name=name,
|
||||
topic=topic,
|
||||
invite_list=[vars[CTX_EVENT]]
|
||||
invite_list=[vars[CTX_ROOM_EVENT].sender]
|
||||
)
|
||||
await ctx.bot.send.text(ctx.room, f"Created the room {res}")
|
||||
except:
|
||||
|
||||
@@ -11,4 +11,5 @@ from .context.vars import ContextVars
|
||||
|
||||
# Context variables
|
||||
from .context.vars.command import *
|
||||
from .context.vars.message import *
|
||||
from .context.vars.message import *
|
||||
from .context.vars.room_event import *
|
||||
3
src/mab/context/vars/room_event/__init__.py
Normal file
3
src/mab/context/vars/room_event/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .types import *
|
||||
from .keys import *
|
||||
from . import builders
|
||||
17
src/mab/context/vars/room_event/builders.py
Normal file
17
src/mab/context/vars/room_event/builders.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from ... import EventContext
|
||||
from .. import ContextVars, ContextVarsPopulator
|
||||
|
||||
from . import *
|
||||
|
||||
@ContextVarsPopulator.autobuilder
|
||||
def _build_room_event(ctx: EventContext, vars: ContextVars) -> None:
|
||||
ev = ctx.event
|
||||
vars[CTX_ROOM_EVENT] = RoomEvent(
|
||||
source=ev.source,
|
||||
content=ev.source["content"],
|
||||
event_id=ev.event_id,
|
||||
origin_server_ts=ev.source["origin_server_ts"],
|
||||
room_id=ev.source["room_id"],
|
||||
sender=ev.sender,
|
||||
type=ev.source["type"]
|
||||
)
|
||||
5
src/mab/context/vars/room_event/keys.py
Normal file
5
src/mab/context/vars/room_event/keys.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from .types import *
|
||||
from .. import ContextVarKey
|
||||
|
||||
CTX_ROOM_EVENT = ContextVarKey[RoomEvent]("CTX_ROOM_EVENT")
|
||||
"""Variable that describes the event that has happened in the room."""
|
||||
29
src/mab/context/vars/room_event/types.py
Normal file
29
src/mab/context/vars/room_event/types.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
class RoomEvent(BaseModel):
|
||||
"""This model defines basic fields of the room event."""
|
||||
|
||||
source: dict
|
||||
"""`event.source` as returned by `matrix-nio`."""
|
||||
|
||||
content: dict
|
||||
"""Raw event content as returned by the matrix homeserver. You should
|
||||
validate it as it is not guranteed that the schema is valid."""
|
||||
|
||||
event_id: str
|
||||
"""The globally unique identifier for the event. It is completely opaque and
|
||||
is not intended to be human-readable."""
|
||||
|
||||
origin_server_ts: int
|
||||
"""Timestamp (in milliseconds since the unix epoch) on originating
|
||||
homeserver when this event was sent."""
|
||||
|
||||
room_id: str
|
||||
"""Opaque identifier of a room starting with excamation mark. They are not
|
||||
indended to be human-readable even if they contain readable domain."""
|
||||
|
||||
sender: str
|
||||
"""Fully-qualified ID of the user who sent the event."""
|
||||
|
||||
type: str
|
||||
"""The type of the event."""
|
||||
Reference in New Issue
Block a user