Commit 4d46176 1 parent 945833e commit 4d46176 Copy full SHA for 4d46176
File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 5
5
use Flarum \Post \Event \Posted ;
6
6
use Flarum \Settings \SettingsRepositoryInterface ;
7
7
use Illuminate \Contracts \Queue \Queue ;
8
+ use Illuminate \Support \Arr ;
8
9
use Msc \ChatGPT \Agent ;
9
10
use Msc \ChatGPT \Job \ReplyPostJob ;
10
11
@@ -24,7 +25,21 @@ public function __construct(
24
25
public function handle (Posted $ event ): void
25
26
{
26
27
$ settings = resolve (SettingsRepositoryInterface::class);
28
+ $ enabledTagIds = $ settings ->get ('muhammedsaidckr-chatgpt.enabled-tags ' , []);
27
29
$ 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
+
28
43
29
44
if (!$ enabled ) {
30
45
$ this ->agent ->repliesToCommentPost ($ event ->post );
Original file line number Diff line number Diff line change 5
5
use Flarum \Discussion \Event \Started ;
6
6
use Flarum \Settings \SettingsRepositoryInterface ;
7
7
use Illuminate \Contracts \Queue \Queue ;
8
+ use Illuminate \Support \Arr ;
8
9
use Msc \ChatGPT \Agent ;
9
10
use Msc \ChatGPT \Job \ReplyJob ;
10
11
@@ -25,6 +26,19 @@ public function handle(Started $event): void
25
26
{
26
27
$ settings = resolve (SettingsRepositoryInterface::class);
27
28
$ 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 );
28
42
29
43
if (!$ enabled ) {
30
44
$ this ->agent ->repliesTo ($ event ->discussion );
You can’t perform that action at this time.
0 commit comments