1818from cloudbot .plugin import PluginManager
1919from cloudbot .event import Event , CommandEvent , RegexEvent , EventType
2020from cloudbot .util import database , formatting
21- from cloudbot .clients .irc import IrcClient
21+ from cloudbot .clients .irc import IrcClient , irc_clean
2222
2323try :
2424 from cloudbot .web .main import WebInterface
@@ -240,16 +240,19 @@ def process(self, event):
240240
241241 if event .type is EventType .message :
242242 # Commands
243- text = event .content
244- raw_text = event .content_raw
245- command = None
246- if raw_text [0 ] in command_prefix :
247- command = raw_text [1 :].split (maxsplit = 1 )[0 ]
248- elif event .chan .lower () == event .nick .lower ():
249- command = raw_text .split (maxsplit = 1 )[0 ]
250-
251- if command :
252- _ , _ , text = text .partition (' ' )
243+ if event .chan .lower () == event .nick .lower (): # private message, no command prefix
244+ command_re = r'(?i)^(?:[{}]?|{}[,;:]+\s+)(\w+)(?:$|\s+)(.*)'
245+ else :
246+ command_re = r'(?i)^(?:[{}]|{}[,;:]+\s+)(\w+)(?:$|\s+)(.*)'
247+
248+ cmd_match = re .match (
249+ command_re .format (command_prefix , event .conn .nick ),
250+ event .content_raw
251+ )
252+
253+ if cmd_match :
254+ command = cmd_match .group (1 ).lower ()
255+ text = irc_clean (cmd_match .group (2 ).strip ())
253256 if command in self .plugin_manager .commands :
254257 command_hook = self .plugin_manager .commands [command ]
255258 command_event = CommandEvent (hook = command_hook , text = text ,
@@ -272,7 +275,7 @@ def process(self, event):
272275
273276 # Regex hooks
274277 for regex , regex_hook in self .plugin_manager .regex_hooks :
275- if not regex_hook .run_on_cmd and command :
278+ if not regex_hook .run_on_cmd and cmd_match :
276279 pass
277280 else :
278281 regex_match = regex .search (event .content )
0 commit comments