@@ -132,41 +132,16 @@ static TEXT_COMMAND_CALLBACK: TriggerCallback = |app_state, trigger_id, _chat_me
132132// - indicate to users of our service that we are being created, and make them wait for us to finish.
133133// - move creation of out service into l1 state. The creation of this just requires the DB, the execution is difficult
134134// we also can't just create an emtpy version of ourselves, and fill the rest in later, because then our users would try to modify non existing commands
135- #[ derive( Default ) ]
136135pub struct CommandExecutorService {
137136 triggers : RwLock < Vec < CommandTrigger > > ,
138137 cooldown_service : CooldownService ,
139138}
140139
141- impl CommandExecutorService {
142- pub async fn process_chat_message ( app_state : Arc < FullState > , message : ChatMessage ) {
143- for trigger in app_state. l2 . command_executor_service . triggers . read ( ) . await . iter ( ) {
144- app_state. l2 . command_executor_service . execute_trigger_if_matching ( app_state. clone ( ) , trigger, message. clone ( ) ) . await
145- }
146- }
147-
148- async fn execute_trigger_if_matching ( & self , app_state : Arc < FullState > , trigger : & CommandTrigger , chat_message : ChatMessage ) {
149- if chat_message. user . permission < trigger. permission {
150- // logger.debug("User {} with {}, missing {} permission for command {}", message.user().name(), message.user().permission(), trigger.permission(), trigger.id());
151- return ;
152- }
153-
154- if !trigger. patterns . iter ( ) . any ( |r| r. is_match ( & chat_message. message ) ) {
155- return ;
156- }
157-
158- let cooldown_res = self . cooldown_service . check_update_cooldown ( & chat_message, trigger. id . as_ref ( ) , & trigger. user_cooldown , & trigger. global_cooldown ) ;
159- if cooldown_res. is_some ( ) {
160- // logger.debug("Call to command {} from {} rejected because of global cooldowns", trigger.id(), message.user().name());
161- // logger.debug("Call to command {} from {} rejected because of user cooldowns", trigger.id(), message.user().name());
162- return ;
163- }
164-
165- ( trigger. callback ) ( app_state, trigger. id . clone ( ) , chat_message) . await ;
140+ impl CommandExecutorService {
141+ pub ( crate ) async fn new ( _db : & ProdDB ) -> CommandExecutorService {
142+ todo ! ( "get commands from db, and also return Result here" )
166143 }
167- }
168144
169- impl CommandExecutorService {
170145 pub ( crate ) async fn remove_command ( & self , command_id : & TriggerId ) {
171146 self . triggers . write ( ) . await . retain ( |c| c. id . as_ref ( ) != command_id) ;
172147 }
@@ -210,3 +185,31 @@ impl CommandExecutorService {
210185 }
211186}
212187
188+ impl CommandExecutorService {
189+ pub async fn process_chat_message ( app_state : Arc < FullState > , message : ChatMessage ) {
190+ for trigger in app_state. l1 . command_executor_service . triggers . read ( ) . await . iter ( ) {
191+ app_state. l1 . command_executor_service . execute_trigger_if_matching ( app_state. clone ( ) , trigger, message. clone ( ) ) . await
192+ }
193+ }
194+
195+ async fn execute_trigger_if_matching ( & self , app_state : Arc < FullState > , trigger : & CommandTrigger , chat_message : ChatMessage ) {
196+ if chat_message. user . permission < trigger. permission {
197+ // logger.debug("User {} with {}, missing {} permission for command {}", message.user().name(), message.user().permission(), trigger.permission(), trigger.id());
198+ return ;
199+ }
200+
201+ if !trigger. patterns . iter ( ) . any ( |r| r. is_match ( & chat_message. message ) ) {
202+ return ;
203+ }
204+
205+ let cooldown_res = self . cooldown_service . check_update_cooldown ( & chat_message, trigger. id . as_ref ( ) , & trigger. user_cooldown , & trigger. global_cooldown ) ;
206+ if cooldown_res. is_some ( ) {
207+ // logger.debug("Call to command {} from {} rejected because of global cooldowns", trigger.id(), message.user().name());
208+ // logger.debug("Call to command {} from {} rejected because of user cooldowns", trigger.id(), message.user().name());
209+ return ;
210+ }
211+
212+ ( trigger. callback ) ( app_state, trigger. id . clone ( ) , chat_message) . await ;
213+ }
214+ }
215+
0 commit comments