<commit_before><?php namespace Wechat;

class Webot {
  /**
   * text rules
   *
   * @var Webot\Rules
   */
  public $rules;

  /**
   * click rules
   *
   * @var Webot\Rules
   */
  public $menus;

  /**
   * @var Wechat
   */
  public $wechat;

  /**
   * @var Webot\Handler
   */
  private $handler;

  /**
   * @var Webot\Hooks
   */
  private $hook;

  /**
   * @param string $token
   */
  public function __construct($token='') {
    $this->rules = new Webot\Rules;
    $this->menus = new Webot\Rules;
    $this->wechat = new Wechat($token);
    $this->handler = new Webot\Handler($this->wechat);
    $this->hook = new Webot\Hooks([
      'request' => $this->wechat->request,
      'response' => $this->wechat->response,
    ]);
    $this->hook->dispatch('init');
  }

  public function run() {
    if (!$this->wechat->request->valid()) {
      $this->hook->dispatch('request.invalid');
      return;
    }

    switch ($this->wechat->request->msgtype) {
      case 'text':
        $this->hook->dispatch('text', [
          'content' => $this->wechat->request->content,
        ]);
        $this->handler->matchs($this->rules);
        break;

      case 'image':
        $this->hook->dispatch('image', [
          'picture' => $this->wechat->request->picurl,
          'mediaId' => $this->wechat->request->mediaId,
        ]);
        break;

      case 'link':
        $this->hook->dispatch('link');<commit_msg>完善 token 验证，及 echostr 的返回<commit_after><?php namespace Wechat;

class Webot {
  /**
   * text rules
   *
   * @var Webot\Rules
   */
  public $rules;

  /**
   * click rules
   *
   * @var Webot\Rules
   */
  public $menus;

  /**
   * @var Wechat
   */
  public $wechat;

  /**
   * @var Webot\Handler
   */
  private $handler;

  /**
   * @var Webot\Hooks
   */
  private $hook;

  /**
   * @param string $token
   */
  public function __construct($token='') {
    $this->rules = new Webot\Rules;
    $this->menus = new Webot\Rules;
    $this->wechat = new Wechat($token);
    $this->handler = new Webot\Handler($this->wechat);
    $this->hook = new Webot\Hooks([
      'request' => $this->wechat->request,
      'response' => $this->wechat->response,
    ]);
    $this->hook->dispatch('init');
  }

  public function run() {
    if ($this->wechat->token && !$this->wechat->request->valid()) {
      $this->hook->dispatch('request.invalid');
      return;
    } elseif (isset($_GET['echostr'])) {
      echo $_GET['echostr'];
    }

    switch ($this->wechat->request->msgtype) {
      case 'text':
        $this->hook->dispatch('text', [
          'content' => $this->wechat->request->content,
        ]);
        $this->handler->matchs($this->rules);
        break;

      case 'image':
        $this->hook->dispatch('image', [
          'picture' => $this->wechat->request->picurl,
          'mediaId' => $this->wechat->request->mediaId,
        ]);
        break;

      case 'link':
        $this->hook->dispatch('link');
{'fraction_non_alphanumeric': 0.19830508474576272, 'fraction_numerical': 0.0, 'mean_word_length': 2.218102508178844, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3339063', 'n_tokens_mistral': 1011, 'n_tokens_neox': 1000, 'n_words': 172}