Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
17f9270
Bump org.jsoup:jsoup from 1.16.1 to 1.17.1 (#970)
dependabot[bot] Nov 28, 2023
a2adf32
Bump com.diffplug.spotless from 6.22.0 to 6.23.0 (#969)
dependabot[bot] Nov 28, 2023
59379e6
upgrade gradle wrapper to 8.5 (#971)
Taz03 Dec 1, 2023
90647f8
Bump name.remal.sonarlint from 3.3.17 to 3.4.0 (#978)
dependabot[bot] Dec 5, 2023
ee731ee
fixed thread transfers (#976)
Taz03 Dec 7, 2023
d189634
upgrade java to 21 (#972)
Taz03 Dec 10, 2023
c8fb530
Bump org.flywaydb:flyway-core from 10.1.0 to 10.2.0 (#984)
dependabot[bot] Dec 11, 2023
4daa26d
Integrade gradle toolchain to manage java versions (#985)
marko-radosavljevic Dec 11, 2023
f72f2e7
Bump org.flywaydb:flyway-core from 10.2.0 to 10.3.0 (#988)
dependabot[bot] Dec 15, 2023
0392b20
Bump gradle.plugin.org.flywaydb:gradle-plugin-publishing (#987)
dependabot[bot] Dec 15, 2023
2491099
Bump org.flywaydb:flyway-core from 10.3.0 to 10.4.0 (#995)
dependabot[bot] Dec 21, 2023
6c3a7ef
Bump gradle.plugin.org.flywaydb:gradle-plugin-publishing (#996)
dependabot[bot] Dec 21, 2023
d0ebea4
Bump org.jooq:jooq from 3.18.0 to 3.19.1 (#997)
dependabot[bot] Dec 21, 2023
8449810
Bump org.kohsuke:github-api from 1.317 to 1.318 (#965)
dependabot[bot] Dec 21, 2023
0b403ff
Bump nu.studer:gradle-jooq-plugin from 8.2 to 9.0 (#1000)
dependabot[bot] Dec 27, 2023
265d6a2
handling error when member left guild (#986)
ankitsmt211 Dec 27, 2023
7f33782
BugFix: Bot mentions itself in Help-Thread at Timeout (#975)
firasrg Jan 5, 2024
f6f4799
Bump org.flywaydb:flyway-core from 10.4.0 to 10.5.0 (#1003)
dependabot[bot] Jan 12, 2024
3921811
Bump gradle.plugin.org.flywaydb:gradle-plugin-publishing (#1004)
dependabot[bot] Jan 12, 2024
922109b
Bump org.gradle.toolchains.foojay-resolver-convention (#1005)
dependabot[bot] Jan 15, 2024
5941e5a
Bump com.diffplug.spotless from 6.23.2 to 6.24.0 (#1007)
dependabot[bot] Jan 16, 2024
c799127
Bump org.flywaydb:flyway-core from 10.5.0 to 10.6.0 (#1009)
dependabot[bot] Jan 17, 2024
62a4251
Bump gradle.plugin.org.flywaydb:gradle-plugin-publishing (#1008)
dependabot[bot] Jan 17, 2024
65007f2
Bump org.xerial:sqlite-jdbc from 3.44.0.0 to 3.45.0.0 (#1010)
dependabot[bot] Jan 22, 2024
c63add7
Continue/feature/reference gh (#981)
ankitsmt211 Jan 23, 2024
4d704bc
adds docs for public constructors to fix sonar issues (#1012)
ankitsmt211 Jan 23, 2024
59673da
Bump com.diffplug.spotless from 6.24.0 to 6.25.0 (#1014)
dependabot[bot] Jan 24, 2024
0110474
Fix encoding issues with intellij (#1022)
SquidXTV Feb 6, 2024
5c325d0
Bump org.flywaydb:flyway-core from 10.6.0 to 10.7.1 (#1017)
dependabot[bot] Feb 6, 2024
2148821
Bump org.flywaydb:flyway-core from 10.7.1 to 10.8.1 (#1025)
dependabot[bot] Feb 19, 2024
3334ba2
Bug/gpt response compact (#994)
ankitsmt211 Feb 23, 2024
8b07aa1
Bump org.apache.logging.log4j:log4j-core from 2.22.0 to 2.23.0 (#1033)
dependabot[bot] Feb 23, 2024
2c46e3e
Bump org.kohsuke:github-api from 1.318 to 1.319 (#1034)
dependabot[bot] Feb 23, 2024
e47a0ac
fix(GithubReference): log a warn if init goes wrong (#1030)
christolis Feb 29, 2024
3388c6d
add doc for param to fix sonar issue (#1036)
ankitsmt211 Feb 29, 2024
ce95332
Feature/jshell rework (#998)
Alathreon Feb 29, 2024
793e7c0
replace getAsTag() with getName() on user entity (#1016)
ankitsmt211 Feb 29, 2024
f809da4
ChatGPT Auto-Answer should not be posted when image (#1018)
SquidXTV Feb 29, 2024
5aecc78
Update CODEOWNERS
Zabuzard Mar 7, 2024
1c173bd
Set encoding to UTF-8 (#1045)
SquidXTV Mar 9, 2024
c264510
Bump org.flywaydb:flyway-core from 10.8.1 to 10.9.1 (#1047)
dependabot[bot] Mar 9, 2024
206f71c
modified discriminator (#1050)
vishv843 Mar 11, 2024
a6ac181
Bump org.mockito:mockito-core from 5.3.1 to 5.10.0 (#1015)
dependabot[bot] Mar 12, 2024
6dd670a
AI response should be in embed (#1046)
ankitsmt211 Mar 12, 2024
5ac1e07
Member Count Display (#1038)
devloves Mar 13, 2024
bbb3959
document public method (#1051)
ankitsmt211 Mar 13, 2024
21df080
formatted member count (#1055)
Taz03 Mar 16, 2024
4ff5966
upgrade jda (#1031)
Taz03 Mar 16, 2024
6c3cc81
Feature/logging-for-disabled-features (#1048)
Suleman70 Mar 16, 2024
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 .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @Together-Java/moderators @Together-Java/maintainers
* @Together-Java/maintainers
2 changes: 1 addition & 1 deletion .github/workflows/basic-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Basic checks
on: [pull_request]

env:
JAVA_VERSION: 20
JAVA_VERSION: 21

jobs:
spotless:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- cron: '0 20 * * 4'

env:
JAVA_VERSION: 20
JAVA_VERSION: 21

jobs:
sonar:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- 'master'

env:
JAVA_VERSION: 20
JAVA_VERSION: 21

jobs:
docker:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Docker Verify
on: [pull_request]

env:
JAVA_VERSION: 20
JAVA_VERSION: 21

jobs:
docker:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defaults:
shell: bash

env:
JAVA_VERSION: 20
JAVA_VERSION: 21

jobs:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TJ-Bot

[![codefactor](https://img.shields.io/codefactor/grade/github/together-java/tj-bot)](https://www.codefactor.io/repository/github/together-java/tj-bot)
![Java](https://img.shields.io/badge/Java-20-ff696c)
![Java](https://img.shields.io/badge/Java-21-ff696c)
[![license](https://img.shields.io/github/license/Together-Java/TJ-Bot)](https://github.com/Together-Java/TJ-Bot/blob/master/LICENSE)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/Together-Java/TJ-Bot?label=release)

Expand Down
18 changes: 10 additions & 8 deletions application/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
buildscript {
dependencies {
classpath 'org.xerial:sqlite-jdbc:3.44.0.0'
classpath 'org.xerial:sqlite-jdbc:3.45.0.0'
}
}

plugins {
id 'application'
id 'com.google.cloud.tools.jib' version '3.4.0'
id 'com.github.johnrengelman.shadow' version '8.1.0'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'database-settings'
}

Expand All @@ -18,7 +18,7 @@ repositories {
var outputImage = 'togetherjava.org:5001/togetherjava/tjbot:' + System.getenv('BRANCH_NAME') ?: 'latest'

jib {
from.image = 'eclipse-temurin:20'
from.image = 'eclipse-temurin:21'
to {
image = outputImage
auth {
Expand Down Expand Up @@ -46,9 +46,9 @@ dependencies {
implementation project(':utils')
implementation project(':formatter')

implementation 'net.dv8tion:JDA:5.0.0-alpha.20'
implementation 'net.dv8tion:JDA:5.0.0-beta.21'

implementation 'org.apache.logging.log4j:log4j-core:2.22.0'
implementation 'org.apache.logging.log4j:log4j-core:2.23.0'
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.18.0'

implementation 'club.minnced:discord-webhooks:0.8.2'
Expand All @@ -57,7 +57,7 @@ dependencies {

implementation 'io.mikael:urlbuilder:2.0.9'

implementation 'org.jsoup:jsoup:1.16.1'
implementation 'org.jsoup:jsoup:1.17.1'

implementation 'org.scilab.forge:jlatexmath:1.0.7'
implementation 'org.scilab.forge:jlatexmath-font-greek:1.0.7'
Expand All @@ -67,18 +67,20 @@ dependencies {
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion"
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jacksonVersion"
implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
implementation "com.sigpwned:jackson-modules-java17-sealed-classes:0.0.0"

implementation 'com.github.freva:ascii-table:1.8.0'

implementation 'io.github.url-detector:url-detector:0.1.23'

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

implementation 'org.kohsuke:github-api:1.317'
implementation 'org.kohsuke:github-api:1.319'

testImplementation 'org.mockito:mockito-core:5.3.1'
testImplementation 'org.mockito:mockito-core:5.10.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.0'

implementation "com.theokanning.openai-gpt3-java:api:$chatGPTVersion"
Expand Down
5 changes: 4 additions & 1 deletion application/config.json.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"token": "<put_your_token_here>",
"gistApiKey": "<your_gist_personal_access_token>",
"githubApiKey": "<your_github_personal_access_token>",
"databasePath": "local-database.db",
"projectWebsite": "https://github.com/Together-Java/TJ-Bot",
"discordGuildInvite": "https://discord.com/invite/XXFUXzK",
Expand Down Expand Up @@ -86,6 +86,8 @@
"wsf",
"wsh"
],
"githubReferencingEnabledChannelPattern": "server-suggestions|tjbot-discussion|modernjava-discussion",
"githubRepositories": [403389278,587644974,601602394],
"logInfoChannelWebhook": "<put_your_webhook_here>",
"logErrorChannelWebhook": "<put_your_webhook_here>",
"openaiApiKey": "<check pins in #tjbot_discussion for the key>",
Expand All @@ -108,5 +110,6 @@
"special": [
]
},
"memberCountCategoryPattern": "Info",
"selectRolesChannelPattern": "select-your-roles"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package org.togetherjava.tjbot.commands.github;

import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHIssueState;

import org.togetherjava.tjbot.features.CommandVisibility;
import org.togetherjava.tjbot.features.SlashCommandAdapter;
import org.togetherjava.tjbot.features.utils.StringDistances;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.function.ToIntFunction;
import java.util.regex.Matcher;
import java.util.stream.Stream;

/**
* Slash command (/github-search) used to search for an issue in one of the repositories listed in
* the config. It also auto suggests issues/PRs on trigger.
*/
public final class GitHubCommand extends SlashCommandAdapter {
private static final Duration CACHE_EXPIRES_AFTER = Duration.ofMinutes(1);

/**
* Compares two GitHub Issues ascending by the time they have been updated at.
*/
private static final Comparator<GHIssue> GITHUB_ISSUE_TIME_COMPARATOR = (i1, i2) -> {
try {
return i2.getUpdatedAt().compareTo(i1.getUpdatedAt());
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
};

private static final String TITLE_OPTION = "title";

private final GitHubReference reference;

private Instant lastCacheUpdate;
private List<String> autocompleteGHIssueCache;

/**
* Constructs an instance of GitHubCommand.
*
* This constructor initializes a new GitHubCommand with the specified GitHubReference. It also
* sets the command name to "github-search" and the command description to "Search configured
* GitHub repositories for an issue/pull request".
*
* @param reference The GitHubReference used for searching issue/pull request in configured
* repositories.
*/
public GitHubCommand(GitHubReference reference) {
super("github-search", "Search configured GitHub repositories for an issue/pull request",
CommandVisibility.GUILD);

this.reference = reference;

getData().addOption(OptionType.STRING, TITLE_OPTION,
"Title of the issue you're looking for", true, true);

updateCache();
}

@Override
public void onSlashCommand(SlashCommandInteractionEvent event) {
String titleOption = event.getOption(TITLE_OPTION).getAsString();
Matcher matcher = GitHubReference.ISSUE_REFERENCE_PATTERN.matcher(titleOption);

if (!matcher.find()) {
event.reply(
"Could not parse your query. Was not able to find an issue number in it (e.g. #207).")
.setEphemeral(true)
.queue();

return;
}

int issueId = Integer.parseInt(matcher.group(GitHubReference.ID_GROUP));
// extracting issue title from "[#10] add more stuff"
String[] issueData = titleOption.split(" ", 2);
String targetIssueTitle = issueData[1];

reference.findIssue(issueId, targetIssueTitle)
.ifPresentOrElse(issue -> event.replyEmbeds(reference.generateReply(issue)).queue(),
() -> event.reply("Could not find the issue you are looking for.")
.setEphemeral(true)
.queue());
}

@Override
public void onAutoComplete(CommandAutoCompleteInteractionEvent event) {
String title = event.getOption(TITLE_OPTION).getAsString();

if (title.isEmpty()) {
event.replyChoiceStrings(autocompleteGHIssueCache.stream().limit(25).toList()).queue();
} else {
Queue<String> closestSuggestions =
new PriorityQueue<>(Comparator.comparingInt(suggestionScorer(title)));

closestSuggestions.addAll(autocompleteGHIssueCache);

List<String> choices = Stream.generate(closestSuggestions::poll).limit(25).toList();
event.replyChoiceStrings(choices).queue();
}

if (lastCacheUpdate.isAfter(Instant.now().minus(CACHE_EXPIRES_AFTER))) {
updateCache();
}
}

private ToIntFunction<String> suggestionScorer(String title) {
// Remove the ID [#123] and then match
return s -> StringDistances.editDistance(title, s.replaceFirst("\\[#\\d+] ", ""));
}

private void updateCache() {
autocompleteGHIssueCache = reference.getRepositories().stream().map(repo -> {
try {
return repo.getIssues(GHIssueState.ALL);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
})
.flatMap(List::stream)
.sorted(GITHUB_ISSUE_TIME_COMPARATOR)
.map(issue -> "[#%d] %s".formatted(issue.getNumber(), issue.getTitle()))
.toList();

lastCacheUpdate = Instant.now();
}
}
Loading