Beispiel #1
0
 /**
  * 识别指令
  *
  * @param string $message
  * @return array
  */
 public static function recognizeCommands($message)
 {
     $result = [];
     foreach (explode("\n", $message) as $line) {
         foreach (self::COMMAND_SIGNS as $name => $signs) {
             foreach ($signs as $sign) {
                 if (false !== mb_strpos($line, $sign)) {
                     preg_match("|.*{$sign}(.+){$sign}.*|", $line, $matches);
                     if (!empty($matches)) {
                         if ('TOPIC' === $name) {
                             $data = Program::filterTopic($matches[1]);
                         }
                         if ('PARTICIPANT' === $name) {
                             $data = Participant::filterParticipantNames($matches[1]);
                         }
                         $result[$name] = $data ?? [];
                     }
                 }
             }
         }
     }
     return $result;
 }