Skip to content

Commit

Permalink
feat(node): ✨ Added new leave node
Browse files Browse the repository at this point in the history
  • Loading branch information
egalvis39 committed Nov 27, 2023
1 parent 8f69405 commit 507a53e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions menuflow/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
HTTPRequest,
Input,
InteractiveInput,
Leave,
Location,
Media,
Message,
Expand Down Expand Up @@ -134,6 +135,10 @@ def node(
node_initialized = InteractiveInput(
interactive_input_data=node_data, room=room, default_variables=self.flow_variables
)
elif node_data.get("type") == "leave":
node_initialized = Leave(
leave_node_data=node_data, room=room, default_variables=self.flow_variables
)
else:
return

Expand Down
1 change: 1 addition & 0 deletions menuflow/nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .http_request import HTTPRequest
from .input import Input
from .interactive_input import InteractiveInput
from .leave import Leave
from .location import Location
from .media import Media
from .message import Message
Expand Down
22 changes: 22 additions & 0 deletions menuflow/nodes/leave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Dict

from ..db.room import RoomState
from ..repository import Leave as LeaveModel
from ..room import Room
from .base import Base


class Leave(Base):
def __init__(self, leave_node_data: LeaveModel, room: Room, default_variables: Dict) -> None:
Base.__init__(self, room=room, default_variables=default_variables)
self.log = self.log.getChild(leave_node_data.get("id"))
self.content: Dict = leave_node_data

@property
def reason(self) -> str:
return self.render_data(data=self.content.get("reason", ""))

async def run(self):
self.log.debug(f"Room {self.room.room_id} enters leave node {self.id}")
await self.room.matrix_client.leave_room(self.room.room_id, self.reason)
await self.room.update_menu(node_id=None, state=RoomState.END)
1 change: 1 addition & 0 deletions menuflow/repository/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Input,
InteractiveInput,
InteractiveMessage,
Leave,
Location,
Media,
Message,
Expand Down
1 change: 1 addition & 0 deletions menuflow/repository/nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .http_request import HTTPRequest
from .input import InactivityOptions, Input
from .interactive_input import InteractiveInput, InteractiveMessage
from .leave import Leave
from .location import Location
from .media import Media
from .message import Message
Expand Down
19 changes: 19 additions & 0 deletions menuflow/repository/nodes/leave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from __future__ import annotations

from attr import dataclass, ib

from ..flow_object import FlowObject


@dataclass
class Leave(FlowObject):
"""
## Leave
Leave the room.
- id: leave1
type: leave
reason: "I'm leaving"
"""

reason: str = ib(default=None)

0 comments on commit 507a53e

Please sign in to comment.