@@ -4,70 +4,85 @@ import "package:codercord/values.dart";
4
4
import "package:nyxx/nyxx.dart" ;
5
5
import "package:nyxx_interactions/nyxx_interactions.dart" ;
6
6
7
- Future <void > handleResolve (ISlashCommandInteractionEvent p0, bool resolve,
7
+ final resolvedWords = {true : "resolved" , false : "unresolved" };
8
+
9
+ Future <void > handleResolve (IThreadChannel threadChannel, IUser resolver,
10
+ Function respond, bool resolve,
8
11
[bool lock = false ]) async {
9
- final interactionChannel = await p0.interaction.channel. download () ;
12
+ final resolvedWord = resolvedWords[resolve] ;
10
13
11
- if (interactionChannel.channelType == ChannelType .guildPublicThread) {
12
- final resolvedWord = resolve == true ? "resolved" : "unresolved" ;
14
+ final tagToAdd = resolve == true ? resolvedTagID : unresolvedTagID;
15
+ final tagToRemove = resolve == true ? unresolvedTagID : resolvedTagID ;
13
16
14
- final threadChannel = interactionChannel as IThreadChannel ;
17
+ final postTags = threadChannel.appliedTags ;
15
18
16
- if ( await threadChannel.isHelpPost) {
17
- if (canUserInteractWithThread (threadChannel.owner, p0.interaction )) {
18
- final tagToAdd = resolve == true ? resolvedTagID : unresolvedTagID ;
19
- final tagToRemove = resolve == true ? unresolvedTagID : resolvedTagID;
19
+ try {
20
+ if (! postTags. contains (tagToAdd )) {
21
+ postTags. add ( tagToAdd) ;
22
+ }
20
23
21
- final postTags = threadChannel.appliedTags;
24
+ if (postTags.contains (tagToRemove)) {
25
+ postTags.remove (tagToRemove);
26
+ }
22
27
23
- try {
24
- if (! postTags.contains (tagToAdd)) {
25
- postTags.add (tagToAdd);
26
- }
28
+ await threadChannel.setPostTags (postTags);
27
29
28
- if (postTags.contains (tagToRemove)) {
29
- postTags.remove (tagToRemove);
30
- }
30
+ await respond (
31
+ MessageBuilder .content (
32
+ "${resolver .mention } marked the thread as $resolvedWord ." ,
33
+ )..flags = (MessageFlagBuilder ()..suppressNotifications = true ),
34
+ );
31
35
32
- await threadChannel.setPostTags (postTags);
36
+ if (resolve == true && threadChannel.archived == false ) {
37
+ try {
38
+ await threadChannel.archive (true , lock);
39
+ } catch (_) {}
40
+ }
41
+ } catch (e) {
42
+ await respond (
43
+ MessageBuilder .content (
44
+ "Could not mark the thread as $resolvedWord because of an unexpected error." ,
45
+ ),
46
+ hidden: true ,
47
+ );
48
+ }
49
+ }
50
+
51
+ Future <void > handleResolveCommand (
52
+ ISlashCommandInteractionEvent p0, bool resolve,
53
+ [bool lock = false ]) async {
54
+ final interactionChannel = await p0.interaction.channel.download ();
33
55
34
- await p0.respond (
35
- MessageBuilder .content (
36
- "${p0 .interaction .userAuthor !.mention } marked the thread as $resolvedWord ." ,
37
- )..flags = (MessageFlagBuilder ()..suppressNotifications = true ),
38
- );
56
+ if (interactionChannel.channelType == ChannelType .guildPublicThread) {
57
+ final threadChannel = interactionChannel as IThreadChannel ;
58
+ final resolvedWord = resolvedWords[resolve];
39
59
40
- if (resolve == true && threadChannel.archived == false ) {
41
- try {
42
- await threadChannel.archive (true , lock);
43
- } catch (_) {}
44
- }
45
- } catch (e) {
46
- await p0.respond (
47
- MessageBuilder .content (
48
- "Could not mark the thread as $resolvedWord because of an unexpected error." ,
49
- ),
50
- hidden: true ,
51
- );
52
- }
60
+ if (await threadChannel.isHelpPost) {
61
+ if (canUserInteractWithThread (threadChannel.owner, p0.interaction)) {
62
+ return handleResolve (
63
+ threadChannel,
64
+ p0.interaction.userAuthor! ,
65
+ p0.respond,
66
+ resolve,
67
+ );
53
68
} else {
54
- p0.respond (
69
+ await p0.respond (
55
70
MessageBuilder .content (
56
71
"You cannot mark this thread as $resolvedWord since you are not the OP." ,
57
72
),
58
73
hidden: true ,
59
74
);
60
75
}
61
76
} else {
62
- p0.respond (
77
+ await p0.respond (
63
78
MessageBuilder .content (
64
79
"Please run this command in a <#${helpChannel .id }> post." ,
65
80
),
66
81
hidden: true ,
67
82
);
68
83
}
69
84
} else {
70
- p0.respond (
85
+ await p0.respond (
71
86
MessageBuilder .content (
72
87
"You can only run this command in a <#${helpChannel .id }> post." ,
73
88
),
@@ -94,7 +109,7 @@ SlashCommandBuilder getCommand() {
94
109
guild: coderServer.id,
95
110
canBeUsedInDm: false ,
96
111
)..registerHandler ((p0) async {
97
- await handleResolve (
112
+ await handleResolveCommand (
98
113
p0,
99
114
true ,
100
115
p0.args.isNotEmpty ? p0.args[0 ].value : false ,
0 commit comments