Skip to content

Commit 4d46176

Browse files
Added tags and permission features
1 parent 945833e commit 4d46176

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/Listener/ReplyToCommentPost.php

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Flarum\Post\Event\Posted;
66
use Flarum\Settings\SettingsRepositoryInterface;
77
use Illuminate\Contracts\Queue\Queue;
8+
use Illuminate\Support\Arr;
89
use Msc\ChatGPT\Agent;
910
use Msc\ChatGPT\Job\ReplyPostJob;
1011

@@ -24,7 +25,21 @@ public function __construct(
2425
public function handle(Posted $event): void
2526
{
2627
$settings = resolve(SettingsRepositoryInterface::class);
28+
$enabledTagIds = $settings->get('muhammedsaidckr-chatgpt.enabled-tags', []);
2729
$enabled = $settings->get('muhammedsaidckr-chatgpt.queue_active');
30+
$actor = $event->actor;
31+
32+
if ($enabledTagIds = json_decode($enabledTagIds, true)) {
33+
$discussion = $event->post->discussion;
34+
$tagIds = Arr::pluck($discussion->tags, 'id');
35+
36+
if (!array_intersect($enabledTagIds, $tagIds)) {
37+
return;
38+
}
39+
}
40+
41+
$actor->assertCan('discussion.useChatGPTAssistant', $discussion);
42+
2843

2944
if (!$enabled) {
3045
$this->agent->repliesToCommentPost($event->post);

src/Listener/ReplyToPost.php

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Flarum\Discussion\Event\Started;
66
use Flarum\Settings\SettingsRepositoryInterface;
77
use Illuminate\Contracts\Queue\Queue;
8+
use Illuminate\Support\Arr;
89
use Msc\ChatGPT\Agent;
910
use Msc\ChatGPT\Job\ReplyJob;
1011

@@ -25,6 +26,19 @@ public function handle(Started $event): void
2526
{
2627
$settings = resolve(SettingsRepositoryInterface::class);
2728
$enabled = $settings->get('muhammedsaidckr-chatgpt.queue_active');
29+
$enabledTagIds = $settings->get('muhammedsaidckr-chatgpt.enabled-tags', []);
30+
$actor = $event->actor;
31+
32+
if ($enabledTagIds = json_decode($enabledTagIds, true)) {
33+
$discussion = $event->discussion;
34+
$tagIds = Arr::pluck($discussion->tags, 'id');
35+
36+
if (!array_intersect($enabledTagIds, $tagIds)) {
37+
return;
38+
}
39+
}
40+
41+
$actor->assertCan('discussion.useChatGPTAssistant', $discussion);
2842

2943
if (!$enabled) {
3044
$this->agent->repliesTo($event->discussion);

0 commit comments

Comments
 (0)