Compare commits

..

10 Commits

Author SHA1 Message Date
a2e74105c5 wip: moving to fsm 2024-05-14 14:48:42 +03:00
49cfb9c649 limit pipelines to master
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-14 14:48:36 +03:00
22fac48796 update compose prod sample
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-13 21:51:06 +03:00
4fdc64c03b change fsm behavior, unknown command state
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-13 21:46:05 +03:00
b4ee5f77b8 little refactoring
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-13 19:46:55 +03:00
3b6c3e28f3 doc comments for wizard packages
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-13 19:22:31 +03:00
1a28ab584a move fsm wizard to its own package, little refactor
Some checks are pending
continuous-integration/drone/push Build is running
2024-05-13 19:21:34 +03:00
68f2975201 refactor fsm to pkg, copy more wizard logic to states
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-13 19:08:46 +03:00
77eaceb152 move more logic to fsm
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-13 17:18:22 +03:00
37b638712c wip: moving setup logic to fsm
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-13 16:57:55 +03:00
4 changed files with 4 additions and 22 deletions

View File

@ -82,7 +82,3 @@ func (s State) LogError(err error) {
func (s State) Move(mc fsm.MachineControls[Wizard], stateID fsm.StateID, pl *Wizard) {
s.LogError(mc.Move(stateID, pl))
}
func (s State) MoveForHandle(mc fsm.MachineControls[Wizard], stateID fsm.StateID, pl *Wizard) {
s.LogError(mc.MoveForHandle(stateID, pl))
}

View File

@ -24,12 +24,12 @@ func (s *WaitingForMemberWebhookState) Enter(pl *Wizard, mc fsm.MachineControls[
}
if !cm.OldChatMember.MemberIsMember() && cm.OldChatMember.MemberUser().ID == s.App.TGProfile().ID &&
cm.NewChatMember.MemberIsMember() && cm.NewChatMember.MemberUser().ID == s.App.TGProfile().ID {
s.MoveForHandle(mc, AddChatMemberStateID, pl)
s.Move(mc, AddChatMemberStateID, pl)
return nil
}
if cm.OldChatMember.MemberIsMember() && cm.OldChatMember.MemberUser().ID == s.App.TGProfile().ID &&
!cm.NewChatMember.MemberIsMember() && cm.NewChatMember.MemberUser().ID == s.App.TGProfile().ID {
s.MoveForHandle(mc, RemoveChatMemberStateID, pl)
s.Move(mc, RemoveChatMemberStateID, pl)
return nil
}

View File

@ -43,7 +43,6 @@ type Machine[T any] struct {
initialState StateID
states *types.Map[StateID, IState[T]]
errHandler ErrorState[T]
handleNow bool
}
// New machine.
@ -90,11 +89,6 @@ func (m *Machine[T]) Move(id StateID, payload *T) error {
return nil
}
func (m *Machine[T]) MoveForHandle(id StateID, payload *T) error {
m.handleNow = true
return m.Move(id, payload)
}
// Handle the input.
func (m *Machine[T]) Handle(provider MachineStateProvider[T]) error {
if provider != nil {
@ -107,14 +101,8 @@ func (m *Machine[T]) Handle(provider MachineStateProvider[T]) error {
if st == nil || err != nil {
return err
}
for {
st.Handle(m.payload, m)
if m.handleNow { // MoveForHandle was called, trying to handle again.
m.handleNow = false
continue
}
return nil
}
}
// State of the Machine.

View File

@ -10,8 +10,6 @@ const NilStateID = StateID("")
// It may fail with an error which should be handled by the IState implementation.
type MachineControls[T any] interface {
Move(StateID, *T) error
// MoveForHandle is the same as Move but it also triggers Handle immediately for the next state.
MoveForHandle(StateID, *T) error
Reset()
}