Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,8 @@ jobs:
run: |
rm -rf /tmp/admin.password

docker stop jenkins-rest
docker rm jenkins-rest

docker stop nexus-rest
docker rm nexus-rest

docker stop mariadb
docker rm mariadb

docker stop jenkins-rest nexus-rest mariadb
docker rm jenkins-rest nexus-rest mariadb
docker network rm codemc
- name: Archive Test Reports
uses: actions/upload-artifact@v4
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ plugins {
}

group 'io.codemc'
version '2.1.0'
version '2.1.1'

compileJava.options.encoding('UTF-8')

Expand All @@ -47,7 +47,7 @@ dependencies {
implementation group: 'pw.chew', name: 'jda-chewtils-command', version: '2.1'
implementation group: 'org.spongepowered', name: 'configurate-gson', version: '4.1.2'

implementation group: 'io.codemc.api', name: 'codemc-api', version: '1.2.1'
implementation group: 'io.codemc.api', name: 'codemc-api', version: '1.2.2'
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.10.1'
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-serialization-json', version: '1.8.0'
implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '3.5.2'
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/io/codemc/bot/listeners/ModalListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package io.codemc.bot.listeners;

import io.codemc.api.database.DatabaseAPI;
import io.codemc.api.jenkins.JenkinsAPI;
import io.codemc.bot.CodeMCBot;
import io.codemc.bot.utils.ApplicationHandler;
Expand Down Expand Up @@ -100,7 +101,7 @@ public void onModalInteraction(@NotNull ModalInteractionEvent event){
String repoLink = MarkdownUtil.maskedLink(repo, repoLinkValue);
String submitter = String.format("`%s` (%s)", event.getUser().getEffectiveName(), event.getUser().getAsMention());

MessageEmbed embed = CommandUtil.requestEmbed(userLink, repoLink, submitter, description, event.getUser().getId());
MessageEmbed embed = CommandUtil.requestEmbed(userLink, repoLink, submitter, description);

requestChannel.sendMessageEmbeds(embed)
.setActionRow(
Expand All @@ -116,6 +117,8 @@ public void onModalInteraction(@NotNull ModalInteractionEvent event){
message.addReaction(Emoji.fromCustom("like", 935126958193405962L, false)).queue();
message.addReaction(Emoji.fromCustom("dislike", 935126958235344927L, false)).queue();

DatabaseAPI.createRequest(message.getIdLong(), event.getUser().getIdLong(), user, repo);

logger.info("[Access Request] User {} requested access to the CI.", event.getUser().getEffectiveName());
},
e -> {
Expand Down
165 changes: 60 additions & 105 deletions src/main/java/io/codemc/bot/utils/ApplicationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import io.codemc.bot.CodeMCBot;
import io.codemc.api.database.DatabaseAPI;
import io.codemc.api.database.Request;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
Expand All @@ -34,8 +35,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class ApplicationHandler{

private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationHandler.class);
Expand All @@ -49,89 +48,57 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long

hook.editOriginal(
"[1/5] Handling Join Request...\n" +
"- [1/1] Retrieving Request Message..."
"- [1/1] Retrieving Request..."
).queue();

requestChannel.retrieveMessageById(messageId).queue(message -> {
hook.editOriginal(
"""
[2/5] Handling Join Request...
- [<:like:935126958193405962>] Message retrieved!
- [1/3] Validating Message...
- Retrieving Embed...
"""
).queue();
List<MessageEmbed> embeds = message.getEmbeds();
if(embeds.isEmpty()){
CommandUtil.EmbedReply.from(hook).error("Provided Message does not have any embeds.").send();
Request req = DatabaseAPI.getRequest(messageId);
if(req == null){
CommandUtil.EmbedReply.from(hook).error("Request not found in Database.").send();
return;
}

MessageEmbed embed = embeds.get(0);
if(embed.getFooter() == null || embed.getFields().isEmpty()){
CommandUtil.EmbedReply.from(hook).error("Embed does not have a Footer or any Embed Fields").send();
return;
}

hook.editOriginal(
"""
[2/5] Handling Join Request...
- [<:like:935126958193405962>] Message retrieved!
- [2/3] Validating Message...
- Embed found!
- Retrieving User ID...
- [<:like:935126958193405962>] Request retrieved!
- [1/2] Validating Request...
"""
).queue();

String userId = embed.getFooter().getText() == null ? null : embed.getFooter().getText().trim();
if(userId == null || userId.isEmpty()){
CommandUtil.EmbedReply.from(hook).error("Embed does not have a valid footer.").send();
long userId = req.getUserId();
if(userId <= 0){
CommandUtil.EmbedReply.from(hook).error("Request does not have a valid user.").send();
return;
}

hook.editOriginalFormat(
"""
[2/5] Handling Join Request...
- [<:like:935126958193405962>] Message retrieved!
- [3/3] Validating Message...
- Embed found!
- Found User ID `%s`.
- Find and validate User and Repository link...
- [<:like:935126958193405962>] Request retrieved!
- [2/2] Validating Request...
- Found User ID `%d`.
- Find and validate User and Repository link...
""", userId
).queue();

if (embed.getFields().size() < 2) {
CommandUtil.EmbedReply.from(hook).error("Embed does not have all valid Fields.").send();
return;
}

MessageEmbed.Field userField = embed.getFields().get(0);
MessageEmbed.Field repoField = embed.getFields().get(1);
if(userField == null || repoField == null){
CommandUtil.EmbedReply.from(hook).error("Embed does not have all valid Fields.").send();
return;
}

String user = userField.getValue();
String repo = repoField.getValue();

String username = user.substring(1, user.indexOf("]"));
String userLink = user.substring(user.indexOf("(") + 1, user.length() - 1);
String repoName = repo.substring(1, repo.indexOf("]"));
String repoLink = repo.substring(repo.indexOf("(") + 1, repo.length() - 1);
String username = req.getGithubName();
String repoName = req.getRepoName();

if(username == null || userLink == null || repoName == null || repoLink == null){
CommandUtil.EmbedReply.from(hook).error("Embed does not have any valid Fields.").send();
if(username.isEmpty() || repoName.isEmpty()){
CommandUtil.EmbedReply.from(hook).error("Database Request is missing values.").send();
return;
}

String userLink = "https://github.com/" + username;
String repoLink = userLink + "/" + repoName;

hook.editOriginalFormat(
"""
[3/5] Handling Join Request...
- [<:like:935126958193405962>] Message retrieved!
- [<:like:935126958193405962>] Message validated!
- Embed found!
- Found User ID `%s`.
- User and Repository Link found and validated!
- [<:like:935126958193405962>] Request retrieved!
- Found User ID `%s`.
- User and Repository found and validated!
- [1/1] Finding `%s-requests` channel...
""", userId, (accepted ? "accepted" : "rejected")
).queue();
Expand All @@ -150,14 +117,12 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
hook.editOriginalFormat(
"""
[4/5] Handling Join Request...
- [<:like:935126958193405962>] Message retrieved!
- [<:like:935126958193405962>] Message validated!
- Embed found!
- Found User ID `%s`.
- User and Repository Link found and validated!
- [<:like:935126958193405962>] Request retrieved!
- Found User ID `%d`.
- User and Repository Link found and validated!
- [<:like:935126958193405962>] `%s-requests` channel found!
- [1/2] Removing Join Request...
- Archive Thread...
- Archive Thread...
""", userId, (accepted ? "accepted" : "rejected")
).queue();

Expand All @@ -179,8 +144,8 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
DatabaseAPI.addUser(username, member.getIdLong());
}
}
channel.sendMessage(getMessage(bot, userId, userLink, repoLink, str == null ? jenkinsUrl : str, hook.getInteraction().getUser(), accepted)).queue(m -> {

channel.sendMessage(getMessage(bot, String.valueOf(userId), userLink, repoLink, str == null ? jenkinsUrl : str, hook.getInteraction().getUser(), accepted)).queue(m -> {
ThreadChannel thread = message.getStartedThread();
if(thread != null && !thread.isArchived()){
thread.getManager().setArchived(true)
Expand All @@ -191,15 +156,13 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
hook.editOriginalFormat(
"""
[4/5] Handling Join Request...
- [<:like:935126958193405962>] Message retrieved!
- [<:like:935126958193405962>] Message validated!
- Embed found!
- Found User ID `%s`.
- User and Repository Link found and validated!
- [<:like:935126958193405962>] Request retrieved!
- Found User ID `%d`.
- User and Repository found and validated!
- [<:like:935126958193405962>] `%s-requests` channel found!
- [2/2] Removing Join Request...
- Thread archived!
- Delete Request Message...
- Thread archived!
- Delete Request Message...
""", userId, (accepted ? "accepted" : "rejected")
).queue();

Expand All @@ -208,15 +171,13 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
hook.editOriginalFormat(
"""
[5/5] Handling Join Request...
- [<:like:935126958193405962>] Message retrieved!
- [<:like:935126958193405962>] Message validated!
- Embed found!
- Found User ID `%s`.
- User and Repository Link found and validated!
- [<:like:935126958193405962>] Request retrieved!
- Found User ID `%d`.
- User and Repository Link found and validated!
- [<:like:935126958193405962>] `%s-requests` channel found!
- [<:like:935126958193405962>] Join Request removed!
- Thread archived!
- Request Message deleted!
- Thread archived!
- Request Message deleted!
- %s
""", userId, (accepted ? "accepted" : "rejected"), (accepted ? "[1/2] Giving User role...\n - Finding Author role..." : "[1/1] Finishing...")
).queue();
Expand All @@ -225,15 +186,13 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
hook.editOriginalFormat(
"""
[<:like:935126958193405962>] Handling of Join Request complete!
- [<:like:935126958193405962>] Message retrieved!
- [<:like:935126958193405962>] Message validated!
- Embed found!
- Found User ID `%s`.
- User and Repository Link found and validated!
- [<:like:935126958193405962>] Request retrieved!
- Found User ID `%d`.
- User and Repository found and validated!
- [<:like:935126958193405962>] `rejected-requests` channel found!
- [<:like:935126958193405962>] Join Request removed!
- Thread archived!
- Request Message deleted!
- Thread archived!
- Request Message deleted!
- [<:like:935126958193405962>] Finished rejecting join request of %s!
""", userId, (member == null ? "*Unknown*" : member.getUser().getEffectiveName())
).queue();
Expand All @@ -249,18 +208,16 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
hook.editOriginalFormat(
"""
[5/5] Handling Join Request...
- [<:like:935126958193405962>] Message retrieved!
- [<:like:935126958193405962>] Message validated!
- Embed found!
- Found User ID `%s`.
- User and Repository Link found and validated!
- [<:like:935126958193405962>] Request retrieved!
- Found User ID `%d`.
- User and Repository found and validated!
- [<:like:935126958193405962>] `accepted-requests` channel found!
- [<:like:935126958193405962>] Join Request removed!
- Thread archived!
- Request Message deleted!
- Thread archived!
- Request Message deleted!
- [2/2] Giving User role...
- Found Author Role!
- Applying role to user...
- Found Author Role!
- Applying role to user...
""", userId
).queue();

Expand All @@ -274,18 +231,16 @@ public static void handle(CodeMCBot bot, InteractionHook hook, Guild guild, long
.queue(v -> hook.editOriginalFormat(
"""
[5/5] Handling Join Request...
- [<:like:935126958193405962>] Message retrieved!
- [<:like:935126958193405962>] Message validated!
- Embed found!
- Found User ID `%s`.
- User and Repository Link found and validated!
- [<:like:935126958193405962>] Request retrieved!
- Found User ID `%d`.
- User and Repository Link found and validated!
- [<:like:935126958193405962>] `accepted-requests` channel found!
- [<:like:935126958193405962>] Join Request removed!
- Thread archived!
- Request Message deleted!
- Thread archived!
- Request Message deleted!
- [<:like:935126958193405962>] Gave User Role!
- Found Author Role!
- Applied Author Role to User!
- Found Author Role!
- Applied Author Role to User!

**Successfully accepted Join Request of user %s!**
""", userId, member.getUser().getEffectiveName()
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/codemc/bot/utils/CommandUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ public static MessageEmbed embedSuccess(String... lines){
return EmbedReply.empty().success(lines).build();
}

public static MessageEmbed requestEmbed(String userLink, String repoLink, String submitter, String description, String id) {
public static MessageEmbed requestEmbed(String userLink, String repoLink, String submitter, String description) {
return getEmbed()
.addField("User/Organisation:", userLink, true)
.addField("Repository:", repoLink, true)
.addField("Submitted by:", submitter, true)
.addField("Description", description, false)
.setFooter(id)
.setTimestamp(Instant.now())
.build();
}
Expand Down
Loading
Loading