public function validatePost(PostWillBeSaved $event) { $post = $event->post; if ($post->exists || $post->user->groups()->count()) { return; } $akismet = new Akismet($this->settings->get('akismet.api_key'), Core::url()); $isSpam = $akismet->isSpam($post->content, $post->user->username, $post->user->email, null, 'comment'); if ($isSpam) { $post->hide(); $this->savingPost = $post; CommentPost::saved(function (CommentPost $post) { if ($post !== $this->savingPost) { return; } $report = new Report(); $report->post_id = $post->id; $report->reporter = 'Akismet'; $report->reason = 'spam'; $report->time = time(); $report->save(); $this->savingPost = null; }); } }