20
20
21
21
import io .codemc .bot .CodeMCBot ;
22
22
import io .codemc .api .database .DatabaseAPI ;
23
+ import io .codemc .api .database .Request ;
23
24
import net .dv8tion .jda .api .EmbedBuilder ;
24
25
import net .dv8tion .jda .api .entities .*;
25
26
import net .dv8tion .jda .api .entities .channel .concrete .TextChannel ;
34
35
import org .slf4j .Logger ;
35
36
import org .slf4j .LoggerFactory ;
36
37
37
- import java .util .List ;
38
-
39
38
public class ApplicationHandler {
40
39
41
40
private static final Logger LOGGER = LoggerFactory .getLogger (ApplicationHandler .class );
@@ -49,89 +48,57 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
49
48
50
49
hook .editOriginal (
51
50
"[1/5] Handling Join Request...\n " +
52
- "- [1/1] Retrieving Request Message ..."
51
+ "- [1/1] Retrieving Request..."
53
52
).queue ();
53
+
54
54
requestChannel .retrieveMessageById (messageId ).queue (message -> {
55
- hook .editOriginal (
56
- """
57
- [2/5] Handling Join Request...
58
- - [<:like:935126958193405962>] Message retrieved!
59
- - [1/3] Validating Message...
60
- - Retrieving Embed...
61
- """
62
- ).queue ();
63
- List <MessageEmbed > embeds = message .getEmbeds ();
64
- if (embeds .isEmpty ()){
65
- CommandUtil .EmbedReply .from (hook ).error ("Provided Message does not have any embeds." ).send ();
55
+ Request req = DatabaseAPI .getRequest (messageId );
56
+ if (req == null ){
57
+ CommandUtil .EmbedReply .from (hook ).error ("Request not found in Database." ).send ();
66
58
return ;
67
59
}
68
60
69
- MessageEmbed embed = embeds .get (0 );
70
- if (embed .getFooter () == null || embed .getFields ().isEmpty ()){
71
- CommandUtil .EmbedReply .from (hook ).error ("Embed does not have a Footer or any Embed Fields" ).send ();
72
- return ;
73
- }
74
-
75
61
hook .editOriginal (
76
62
"""
77
63
[2/5] Handling Join Request...
78
- - [<:like:935126958193405962>] Message retrieved!
79
- - [2/3] Validating Message...
80
- - Embed found!
81
- - Retrieving User ID...
64
+ - [<:like:935126958193405962>] Request retrieved!
65
+ - [1/2] Validating Request...
82
66
"""
83
67
).queue ();
84
68
85
- String userId = embed . getFooter (). getText () == null ? null : embed . getFooter (). getText (). trim ();
86
- if (userId == null || userId . isEmpty () ){
87
- CommandUtil .EmbedReply .from (hook ).error ("Embed does not have a valid footer ." ).send ();
69
+ long userId = req . getUserId ();
70
+ if (userId <= 0 ){
71
+ CommandUtil .EmbedReply .from (hook ).error ("Request does not have a valid user ." ).send ();
88
72
return ;
89
73
}
90
74
91
75
hook .editOriginalFormat (
92
76
"""
93
77
[2/5] Handling Join Request...
94
- - [<:like:935126958193405962>] Message retrieved!
95
- - [3/3] Validating Message...
96
- - Embed found!
97
- - Found User ID `%s`.
98
- - Find and validate User and Repository link...
78
+ - [<:like:935126958193405962>] Request retrieved!
79
+ - [2/2] Validating Request...
80
+ - Found User ID `%d`.
81
+ - Find and validate User and Repository link...
99
82
""" , userId
100
83
).queue ();
101
84
102
- if (embed .getFields ().size () < 2 ) {
103
- CommandUtil .EmbedReply .from (hook ).error ("Embed does not have all valid Fields." ).send ();
104
- return ;
105
- }
106
-
107
- MessageEmbed .Field userField = embed .getFields ().get (0 );
108
- MessageEmbed .Field repoField = embed .getFields ().get (1 );
109
- if (userField == null || repoField == null ){
110
- CommandUtil .EmbedReply .from (hook ).error ("Embed does not have all valid Fields." ).send ();
111
- return ;
112
- }
113
-
114
- String user = userField .getValue ();
115
- String repo = repoField .getValue ();
116
-
117
- String username = user .substring (1 , user .indexOf ("]" ));
118
- String userLink = user .substring (user .indexOf ("(" ) + 1 , user .length () - 1 );
119
- String repoName = repo .substring (1 , repo .indexOf ("]" ));
120
- String repoLink = repo .substring (repo .indexOf ("(" ) + 1 , repo .length () - 1 );
85
+ String username = req .getGithubName ();
86
+ String repoName = req .getRepoName ();
121
87
122
- if (username == null || userLink == null || repoName == null || repoLink == null ){
123
- CommandUtil .EmbedReply .from (hook ).error ("Embed does not have any valid Fields ." ).send ();
88
+ if (username . isEmpty () || repoName . isEmpty () ){
89
+ CommandUtil .EmbedReply .from (hook ).error ("Database Request is missing values ." ).send ();
124
90
return ;
125
91
}
92
+
93
+ String userLink = "https://github.com/" + username ;
94
+ String repoLink = userLink + "/" + repoName ;
126
95
127
96
hook .editOriginalFormat (
128
97
"""
129
98
[3/5] Handling Join Request...
130
- - [<:like:935126958193405962>] Message retrieved!
131
- - [<:like:935126958193405962>] Message validated!
132
- - Embed found!
133
- - Found User ID `%s`.
134
- - User and Repository Link found and validated!
99
+ - [<:like:935126958193405962>] Request retrieved!
100
+ - Found User ID `%s`.
101
+ - User and Repository found and validated!
135
102
- [1/1] Finding `%s-requests` channel...
136
103
""" , userId , (accepted ? "accepted" : "rejected" )
137
104
).queue ();
@@ -150,14 +117,12 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
150
117
hook .editOriginalFormat (
151
118
"""
152
119
[4/5] Handling Join Request...
153
- - [<:like:935126958193405962>] Message retrieved!
154
- - [<:like:935126958193405962>] Message validated!
155
- - Embed found!
156
- - Found User ID `%s`.
157
- - User and Repository Link found and validated!
120
+ - [<:like:935126958193405962>] Request retrieved!
121
+ - Found User ID `%d`.
122
+ - User and Repository Link found and validated!
158
123
- [<:like:935126958193405962>] `%s-requests` channel found!
159
124
- [1/2] Removing Join Request...
160
- - Archive Thread...
125
+ - Archive Thread...
161
126
""" , userId , (accepted ? "accepted" : "rejected" )
162
127
).queue ();
163
128
@@ -179,8 +144,8 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
179
144
DatabaseAPI .addUser (username , member .getIdLong ());
180
145
}
181
146
}
182
-
183
- channel .sendMessage (getMessage (bot , userId , userLink , repoLink , str == null ? jenkinsUrl : str , hook .getInteraction ().getUser (), accepted )).queue (m -> {
147
+
148
+ channel .sendMessage (getMessage (bot , String . valueOf ( userId ) , userLink , repoLink , str == null ? jenkinsUrl : str , hook .getInteraction ().getUser (), accepted )).queue (m -> {
184
149
ThreadChannel thread = message .getStartedThread ();
185
150
if (thread != null && !thread .isArchived ()){
186
151
thread .getManager ().setArchived (true )
@@ -191,15 +156,13 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
191
156
hook .editOriginalFormat (
192
157
"""
193
158
[4/5] Handling Join Request...
194
- - [<:like:935126958193405962>] Message retrieved!
195
- - [<:like:935126958193405962>] Message validated!
196
- - Embed found!
197
- - Found User ID `%s`.
198
- - User and Repository Link found and validated!
159
+ - [<:like:935126958193405962>] Request retrieved!
160
+ - Found User ID `%d`.
161
+ - User and Repository found and validated!
199
162
- [<:like:935126958193405962>] `%s-requests` channel found!
200
163
- [2/2] Removing Join Request...
201
- - Thread archived!
202
- - Delete Request Message...
164
+ - Thread archived!
165
+ - Delete Request Message...
203
166
""" , userId , (accepted ? "accepted" : "rejected" )
204
167
).queue ();
205
168
@@ -208,15 +171,13 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
208
171
hook .editOriginalFormat (
209
172
"""
210
173
[5/5] Handling Join Request...
211
- - [<:like:935126958193405962>] Message retrieved!
212
- - [<:like:935126958193405962>] Message validated!
213
- - Embed found!
214
- - Found User ID `%s`.
215
- - User and Repository Link found and validated!
174
+ - [<:like:935126958193405962>] Request retrieved!
175
+ - Found User ID `%d`.
176
+ - User and Repository Link found and validated!
216
177
- [<:like:935126958193405962>] `%s-requests` channel found!
217
178
- [<:like:935126958193405962>] Join Request removed!
218
- - Thread archived!
219
- - Request Message deleted!
179
+ - Thread archived!
180
+ - Request Message deleted!
220
181
- %s
221
182
""" , userId , (accepted ? "accepted" : "rejected" ), (accepted ? "[1/2] Giving User role...\n - Finding Author role..." : "[1/1] Finishing..." )
222
183
).queue ();
@@ -225,15 +186,13 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
225
186
hook .editOriginalFormat (
226
187
"""
227
188
[<:like:935126958193405962>] Handling of Join Request complete!
228
- - [<:like:935126958193405962>] Message retrieved!
229
- - [<:like:935126958193405962>] Message validated!
230
- - Embed found!
231
- - Found User ID `%s`.
232
- - User and Repository Link found and validated!
189
+ - [<:like:935126958193405962>] Request retrieved!
190
+ - Found User ID `%d`.
191
+ - User and Repository found and validated!
233
192
- [<:like:935126958193405962>] `rejected-requests` channel found!
234
193
- [<:like:935126958193405962>] Join Request removed!
235
- - Thread archived!
236
- - Request Message deleted!
194
+ - Thread archived!
195
+ - Request Message deleted!
237
196
- [<:like:935126958193405962>] Finished rejecting join request of %s!
238
197
""" , userId , (member == null ? "*Unknown*" : member .getUser ().getEffectiveName ())
239
198
).queue ();
@@ -249,18 +208,16 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
249
208
hook .editOriginalFormat (
250
209
"""
251
210
[5/5] Handling Join Request...
252
- - [<:like:935126958193405962>] Message retrieved!
253
- - [<:like:935126958193405962>] Message validated!
254
- - Embed found!
255
- - Found User ID `%s`.
256
- - User and Repository Link found and validated!
211
+ - [<:like:935126958193405962>] Request retrieved!
212
+ - Found User ID `%d`.
213
+ - User and Repository found and validated!
257
214
- [<:like:935126958193405962>] `accepted-requests` channel found!
258
215
- [<:like:935126958193405962>] Join Request removed!
259
- - Thread archived!
260
- - Request Message deleted!
216
+ - Thread archived!
217
+ - Request Message deleted!
261
218
- [2/2] Giving User role...
262
- - Found Author Role!
263
- - Applying role to user...
219
+ - Found Author Role!
220
+ - Applying role to user...
264
221
""" , userId
265
222
).queue ();
266
223
@@ -274,18 +231,16 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
274
231
.queue (v -> hook .editOriginalFormat (
275
232
"""
276
233
[5/5] Handling Join Request...
277
- - [<:like:935126958193405962>] Message retrieved!
278
- - [<:like:935126958193405962>] Message validated!
279
- - Embed found!
280
- - Found User ID `%s`.
281
- - User and Repository Link found and validated!
234
+ - [<:like:935126958193405962>] Request retrieved!
235
+ - Found User ID `%d`.
236
+ - User and Repository Link found and validated!
282
237
- [<:like:935126958193405962>] `accepted-requests` channel found!
283
238
- [<:like:935126958193405962>] Join Request removed!
284
- - Thread archived!
285
- - Request Message deleted!
239
+ - Thread archived!
240
+ - Request Message deleted!
286
241
- [<:like:935126958193405962>] Gave User Role!
287
- - Found Author Role!
288
- - Applied Author Role to User!
242
+ - Found Author Role!
243
+ - Applied Author Role to User!
289
244
290
245
**Successfully accepted Join Request of user %s!**
291
246
""" , userId , member .getUser ().getEffectiveName ()
0 commit comments