luceos
I changed the script a little bit to organize the multitude of responses for various keywords. But for some reason, despite everything working as it should - I cannot seem to get my designated User to auto respond. Here's what my adjusted script looks like:
Some additional information:
- I've verified that the appropriate permissions have been set on the new sub-directory.
- I took out my public-facing IP address in the script below, but I can ensure you that it's provided in the one I'm trying to utilize.
return [
(new Extend\Event())
->listen(\Flarum\Post\Event\Posted::class, function (\Flarum\Post\Event\Posted $event) {
if ($event->post->type === 'comment') {
$keywords = ['!keyword0', '!keyword1'; // List of keywords to listen for, add more as necessary.
foreach ($keywords as $keyword) {
if (str_contains($event->post->content, $keyword)) {
$filesystem = new Filesystem();
$responsePath = base_path('./auto_responses'); // The local path where the "auto response" files exist.
$responseFile = $responsePath . '/' . substr($keyword, 1) . '.txt';
if ($filesystem->exists($responseFile)) {
$response = $filesystem->get($responseFile);
\Flarum\Post\CommentPost::reply($event->post->discussion_id, $response, 2, 'my.ip.address', $event->actor); //Posts a comment, using the corresponding "auto response" file.
}
break;
}
}
}
}),
];