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
2 changes: 1 addition & 1 deletion application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ dependencies {

implementation 'com.github.ben-manes.caffeine:caffeine:3.1.1'

testImplementation 'org.mockito:mockito-core:4.10.0'
testImplementation 'org.mockito:mockito-core:4.11.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
Expand Down
79 changes: 40 additions & 39 deletions application/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,43 @@
"heavyModerationRolePattern": "Moderator",
"softModerationRolePattern": "Moderator|Community Ambassador",
"tagManageRolePattern": "Moderator|Community Ambassador|Top Helpers .+",
"suggestions": {
"channelPattern": "tj_suggestions",
"upVoteEmoteName": "peepo_yes",
"downVoteEmoteName": "peepo_no"
},
"quarantinedRolePattern": "Quarantined",
"scamBlocker": {
"mode": "AUTO_DELETE_BUT_APPROVE_QUARANTINE",
"reportChannelPattern": "commands",
"suspiciousKeywords": ["nitro", "boob", "sexy", "sexi", "esex"],
"hostWhitelist": ["discord.com", "discord.gg", "discord.media", "discordapp.com", "discordapp.net", "discordstatus.com"],
"hostBlacklist": ["bit.ly"],
"suspiciousHostKeywords": ["discord", "nitro", "premium"],
"isHostSimilarToKeywordDistanceThreshold": 2
},
"wolframAlphaAppId": "79J52T-6239TVXHR7",
"helpSystem": {
"helpForumPattern": "questions",
"categories": [
"Java",
"Frameworks",
"JavaFX|Swing",
"IDE",
"Build Tools",
"Database",
"Android",
"C|C++",
"Algorithms",
"Math",
"Architecture",
"Code Review",
"Together Java Bot",
"Other"
],
"categoryRoleSuffix": " - Helper"
},
"excludeCodeAutoDetectionRolePattern": "Top Helpers .+|Moderator|Community Ambassador|Expert",
"suggestions": {
"channelPattern": "tj_suggestions",
"upVoteEmoteName": "peepo_yes",
"downVoteEmoteName": "peepo_no"
},
"quarantinedRolePattern": "Quarantined",
"scamBlocker": {
"mode": "AUTO_DELETE_BUT_APPROVE_QUARANTINE",
"reportChannelPattern": "commands",
"suspiciousKeywords": ["nitro", "boob", "sexy", "sexi", "esex"],
"hostWhitelist": ["discord.com", "discord.gg", "discord.media", "discordapp.com", "discordapp.net", "discordstatus.com"],
"hostBlacklist": ["bit.ly"],
"suspiciousHostKeywords": ["discord", "nitro", "premium"],
"isHostSimilarToKeywordDistanceThreshold": 2
},
"wolframAlphaAppId": "79J52T-6239TVXHR7",
"helpSystem": {
"helpForumPattern": "questions",
"categories": [
"Java",
"Frameworks",
"JavaFX|Swing",
"IDE",
"Build Tools",
"Database",
"Android",
"C|C++",
"Algorithms",
"Math",
"Architecture",
"Code Review",
"Together Java Bot",
"Other"
],
"categoryRoleSuffix": " - Helper"
},
"mediaOnlyChannelPattern": "memes",
"blacklistedFileExtension": [
"application",
Expand Down Expand Up @@ -84,7 +85,7 @@
"wsc",
"wsf",
"wsh"
],
"logInfoChannelWebhook": "<put_your_webhook_here>",
"logErrorChannelWebhook": "<put_your_webhook_here>"
],
"logInfoChannelWebhook": "<put_your_webhook_here>",
"logErrorChannelWebhook": "<put_your_webhook_here>"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.togetherjava.tjbot.commands.code;

import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
Expand All @@ -10,6 +11,7 @@
import org.togetherjava.tjbot.commands.utils.MessageUtils;
import org.togetherjava.tjbot.config.Config;

import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;
Expand All @@ -22,12 +24,12 @@ public final class CodeMessageAutoDetection extends MessageReceiverAdapter {
private static final long MINIMUM_LINES_OF_CODE = 3;

private final CodeMessageHandler codeMessageHandler;

private final Predicate<String> isHelpForumName;
private final Predicate<String> isExcludedRole;

/**
* Creates a new instance.
*
*
* @param config to figure out whether a message is from a help thread
* @param codeMessageHandler to register detected code messages at for further handling
*/
Expand All @@ -38,11 +40,15 @@ public CodeMessageAutoDetection(Config config, CodeMessageHandler codeMessageHan

isHelpForumName =
Pattern.compile(config.getHelpSystem().getHelpForumPattern()).asMatchPredicate();

isExcludedRole =
Pattern.compile(config.getExcludeCodeAutoDetectionRolePattern()).asMatchPredicate();
}

@Override
public void onMessageReceived(MessageReceivedEvent event) {
if (event.isWebhookMessage() || event.getAuthor().isBot() || !isHelpThread(event)) {
if (event.isWebhookMessage() || event.getAuthor().isBot() || !isHelpThread(event)
|| isSentByExcludedRole(event.getMember().getRoles())) {
return;
}

Expand All @@ -63,6 +69,10 @@ public void onMessageReceived(MessageReceivedEvent event) {
codeMessageHandler.addAndHandleCodeMessage(originalMessage, true);
}

private boolean isSentByExcludedRole(List<Role> roles) {
return roles.stream().map(Role::getName).anyMatch(isExcludedRole);
}

private boolean isHelpThread(MessageReceivedEvent event) {
if (event.getChannelType() != ChannelType.GUILD_PUBLIC_THREAD) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
*/

public final class ModMailCommand extends SlashCommandAdapter {

private static final Logger logger = LoggerFactory.getLogger(ModMailCommand.class);
public static final String COMMAND_NAME = "modmail";
private static final String OPTION_MESSAGE = "message";
Expand Down Expand Up @@ -154,7 +153,7 @@ private MessageCreateAction createModMessage(SlashCommandInteractionEvent event,
String.valueOf(userId)));
}

Optional<Role> moderatorRole = event.getGuild()
Optional<Role> moderatorRole = modMailAuditLog.getGuild()
.getRoles()
.stream()
.filter(role -> configModGroupPattern.test(role.getName()))
Expand Down Expand Up @@ -193,5 +192,4 @@ private boolean isChannelOnCooldown(long userId) {
.filter(Instant.now()::isBefore)
.isPresent();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public final class Config {
private final String heavyModerationRolePattern;
private final String softModerationRolePattern;
private final String tagManageRolePattern;
private final String excludeCodeAutoDetectionRolePattern;
private final SuggestionsConfig suggestions;
private final String quarantinedRolePattern;
private final ScamBlockerConfig scamBlocker;
Expand Down Expand Up @@ -54,6 +55,8 @@ private Config(@JsonProperty(value = "token", required = true) String token,
required = true) String softModerationRolePattern,
@JsonProperty(value = "tagManageRolePattern",
required = true) String tagManageRolePattern,
@JsonProperty(value = "excludeCodeAutoDetectionRolePattern",
required = true) String excludeCodeAutoDetectionRolePattern,
@JsonProperty(value = "suggestions", required = true) SuggestionsConfig suggestions,
@JsonProperty(value = "quarantinedRolePattern",
required = true) String quarantinedRolePattern,
Expand All @@ -79,6 +82,8 @@ private Config(@JsonProperty(value = "token", required = true) String token,
this.heavyModerationRolePattern = Objects.requireNonNull(heavyModerationRolePattern);
this.softModerationRolePattern = Objects.requireNonNull(softModerationRolePattern);
this.tagManageRolePattern = Objects.requireNonNull(tagManageRolePattern);
this.excludeCodeAutoDetectionRolePattern =
Objects.requireNonNull(excludeCodeAutoDetectionRolePattern);
this.suggestions = Objects.requireNonNull(suggestions);
this.quarantinedRolePattern = Objects.requireNonNull(quarantinedRolePattern);
this.scamBlocker = Objects.requireNonNull(scamBlocker);
Expand Down Expand Up @@ -209,6 +214,16 @@ public String getTagManageRolePattern() {
return tagManageRolePattern;
}

/**
* Gets the REGEX pattern used to identify roles that will be ignored for code actions
* auto-detection
*
* @return the REGEX pattern
*/
public String getExcludeCodeAutoDetectionRolePattern() {
return excludeCodeAutoDetectionRolePattern;
}

/**
* Gets the config for the suggestion system.
*
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ repositories {
}

dependencies {
implementation "gradle.plugin.org.flywaydb:gradle-plugin-publishing:9.10.0"
implementation 'nu.studer:gradle-jooq-plugin:8.0'
implementation "gradle.plugin.org.flywaydb:gradle-plugin-publishing:9.11.0"
implementation 'nu.studer:gradle-jooq-plugin:8.1'
}
2 changes: 1 addition & 1 deletion database/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var sqliteVersion = "3.40.0.0"
dependencies {
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation "org.xerial:sqlite-jdbc:${sqliteVersion}"
implementation 'org.flywaydb:flyway-core:9.10.0'
implementation 'org.flywaydb:flyway-core:9.11.0'
implementation "org.jooq:jooq:$jooqVersion"

implementation project(':utils')
Expand Down
11 changes: 5 additions & 6 deletions website/src/main/resources/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ <h2>We help you land a job! <img src="images/peepo_heart.png" alt=""
<div class="content">
<div class="inner">
<h2>Code together <img src="images/peepo_fancy.png" alt="" width="70"/></h2>
<p>Collaborate to our community bot and gain practice experience on a real
<p>Collaborate on our community bot and gain practice experience on a real
project.</p>
<p>The project is big, sophisticated and most importantly beginner-friendly with
<p>The project is big, sophisticated, and most importantly beginner-friendly with
lots of guides.
</p>
<ul class="actions">
Expand Down Expand Up @@ -158,7 +158,7 @@ <h2>Our partnerships</h2>
width="70"/></span>
<h3><a href="https://www.jetbrains.com">JetBrains</a></h3>
<p>We will frequently <strong>give away licenses</strong> to their products,
such as <strong>Intellij
such as <strong>IntelliJ
IDEA
Ultimate</strong> <img src="images/intellij.png" alt="" width="30"/> on
special
Expand All @@ -175,8 +175,7 @@ <h3><a href="https://www.cloud-builders.tech">Cloud Builders</a></h3>
<p>Hosting free Java conferences with expert speakers and many exciting
talks.</p>
<p>All profits go to Ukrainian charity funds
<span style="white-space: nowrap;">💙💛</span>
.
<span style="white-space: nowrap;">💙💛</span>.
</p>
</section>
<section>
Expand All @@ -196,7 +195,7 @@ <h3><a href="https://adventofcode.com/">Advent of Code</a></h3>
<h3><a href="https://java-programming.mooc.fi/">MOOC: Java Programming</a></h3>
<p>Hands down the best complete and free resource to learn Java.</p>
<p>The University of Helsinki created this course, and they use it to teach
their Students programming. It comes with 14 weekly parts and exercises.</p>
their students programming. It comes with 14 weekly parts and exercises.</p>
</section>
</div>
</div>
Expand Down