1414from watchdog .observers import Observer
1515
1616from cloudbot .client import Client , CLIENTS
17- from cloudbot .clients .irc import IrcClient , irc_clean
17+ from cloudbot .clients .irc import irc_clean
1818from cloudbot .config import Config
1919from cloudbot .event import Event , CommandEvent , RegexEvent , EventType
2020from cloudbot .hook import Action
@@ -277,6 +277,8 @@ def add_hook(hook, _event, _run_before=False):
277277 # The hook has an action of Action.HALT* so stop adding new tasks
278278 break
279279
280+ matched_command = False
281+
280282 if event .type is EventType .message :
281283 # Commands
282284 if event .chan .lower () == event .nick .lower (): # private message, no command prefix
@@ -297,12 +299,14 @@ def add_hook(hook, _event, _run_before=False):
297299 command_event = CommandEvent (hook = command_hook , text = text ,
298300 triggered_command = command , base_event = event )
299301 add_hook (command_hook , command_event )
302+ matched_command = True
300303 else :
301304 potential_matches = []
302305 for potential_match , plugin in self .plugin_manager .commands .items ():
303306 if potential_match .startswith (command ):
304307 potential_matches .append ((potential_match , plugin ))
305308 if potential_matches :
309+ matched_command = True
306310 if len (potential_matches ) == 1 :
307311 command_hook = potential_matches [0 ][1 ]
308312 command_event = CommandEvent (hook = command_hook , text = text ,
@@ -312,10 +316,11 @@ def add_hook(hook, _event, _run_before=False):
312316 event .notice ("Possible matches: {}" .format (
313317 formatting .get_text_list ([command for command , plugin in potential_matches ])))
314318
319+ if event .type in (EventType .message , EventType .action ):
315320 # Regex hooks
316321 regex_matched = False
317322 for regex , regex_hook in self .plugin_manager .regex_hooks :
318- if not regex_hook .run_on_cmd and cmd_match :
323+ if not regex_hook .run_on_cmd and matched_command :
319324 continue
320325
321326 if regex_hook .only_no_match and regex_matched :
0 commit comments