Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
ecdc856
Error reporting if bot added with wrong scope
Zabuzard Oct 8, 2021
b4e971e
Bump JDA from 4.3.0_331 to 4.3.0_333
dependabot[bot] Oct 7, 2021
e71af63
Multithreading for command system
Zabuzard Oct 8, 2021
ddf6875
Bump jackson-dataformat-csv from 2.12.5 to 2.13.0
dependabot[bot] Oct 8, 2021
509d47e
Bump com.diffplug.spotless from 5.15.2 to 5.16.0
dependabot[bot] Oct 4, 2021
ebf44fb
Added Logviewer project
krankkkk Oct 11, 2021
1945757
Fixes HTTPS Redirects on the VPS
krankkkk Oct 11, 2021
e77c3fd
Bump JDA from 4.3.0_333 to 4.3.0_334
dependabot[bot] Oct 11, 2021
638f957
Deactivate reload buttons after usage, reload message to other users
talentedasian Oct 11, 2021
a833f88
Added pic where bot says hello to readme
Zabuzard Oct 11, 2021
4e253fa
Bump a-vaadin-helper from 1.7.1 to 1.7.2
dependabot[bot] Oct 12, 2021
f40caa0
Application does not create necessary Directories for the DB
krankkkk Oct 11, 2021
d72da74
Do not create the file as directory
krankkkk Oct 12, 2021
8fc569e
Gitignore Databases
Zabuzard Oct 12, 2021
b149f77
Add a Boostrap launcher without dependencies to initialize the system
I-Al-Istannen Oct 11, 2021
2eb711a
Skip sonarcloud analysis if secrets are not available
I-Al-Istannen Oct 12, 2021
f8331cc
Improve available commands log
Zabuzard Oct 13, 2021
529e2ed
Fixes a bug with DB paths that have no parents
Zabuzard Oct 13, 2021
db153d5
Less spammy dependabot updates
Zabuzard Oct 13, 2021
14b73c4
gitignore generated vaadin files
RandomGHAcct Oct 13, 2021
82e5609
Change org.togetherjava.formatter to org.togetherjava.tjbot.formatter…
illuminator3 Oct 15, 2021
37e54e5
Propogated onReady event from CommandSystem to SlashCommand
borgrel Oct 19, 2021
4bb7ee4
Adding a `/tex` command for LaTeX support, based on the lib jlatexmath
java-coding-prodigy Oct 19, 2021
32e46b4
Fix #208, #206 (tex background color, tex error message UX)
java-coding-prodigy Oct 19, 2021
58afeb7
Tag system (#135)
illuminator3 Oct 20, 2021
672608c
Added JDA mock and tests
Zabuzard Oct 21, 2021
95d7f32
Fix Javadoc code example for commands (#199)
illuminator3 Oct 21, 2021
ec2469d
Add log severity highlighting to Logviewer #186 (#191)
krankkkk Oct 23, 2021
281dba5
Update JDA application module
Tais993 Oct 25, 2021
a217bc4
staff-helper renamed to staff-assistants
Zabuzard Oct 26, 2021
8150859
Implements the vc-activity command (#228)
Tais993 Oct 29, 2021
783afc2
Bump mockito-core from 3.12.4 to 4.0.0
dependabot[bot] Nov 1, 2021
3f1dbe1
Added .DS_STORE to gitignore (mac users)
Zabuzard Nov 4, 2021
6a70dfd
Fix broken mockito bump (3.12.4 -> 4.0.0)
Zabuzard Nov 4, 2021
f48ea28
UX - add application name to VC acitivity command
Tais993 Nov 6, 2021
73fa578
Added component id storage (without DB)
Zabuzard Oct 15, 2021
d648e14
Force jOOQ to use Instant for TIMESTAMP
Zabuzard Oct 16, 2021
9c2a8d9
Added database component id storage
Zabuzard Oct 16, 2021
37c4aeb
Javadoc
Zabuzard Oct 16, 2021
13f014b
Linter
Zabuzard Oct 16, 2021
94d60ee
Fix logviewer using Instant with TIMESTAMP
Zabuzard Oct 17, 2021
b3d81ec
Removed try-with-resources (CR Istannen)
Zabuzard Oct 17, 2021
ef9ad9c
Some fixes after messed up rebase
Zabuzard Oct 20, 2021
a02a7c6
more fixes for rebase
Zabuzard Oct 20, 2021
da6b950
<strong> instead of **
Zabuzard Oct 20, 2021
6407246
Moved parse/generate ID responsibility out of store
Zabuzard Oct 20, 2021
b10daab
Clarified cache usage benefit
Zabuzard Oct 20, 2021
9dcb2e0
added FIXME to the tests that are still TODO
Zabuzard Oct 20, 2021
05f26d7
Fixed bug with overwriting existing records
Zabuzard Oct 20, 2021
71e5f58
Store synchronization, bugfix
Zabuzard Oct 27, 2021
a5ae52e
Using `Optional#ifPresent` instead of `isPresent` + `orElseThrow`
Zabuzard Oct 27, 2021
4553531
Swapped LRU cache against Caffeine cache
Zabuzard Oct 27, 2021
7bffc75
Adjusted unit tests
Zabuzard Oct 28, 2021
b60dcd8
Fixed typos (CR marko)
Zabuzard Nov 4, 2021
eebeee1
Added wiki link for component IDs (CR marko)
Zabuzard Nov 4, 2021
a0b3735
Empty line for visibility (CR marko)
Zabuzard Nov 4, 2021
b120a85
Removed obsolete note (CR marko)
Zabuzard Nov 4, 2021
abbe154
Update gradle to 7.3 to support Java 17
RealYusufIsmail Nov 10, 2021
47a1c15
Added string distance utilities (+tests)
Zabuzard Nov 8, 2021
79daa48
use string distance utility for tag suggestions
Zabuzard Nov 8, 2021
b5ee3bb
Subst List.of against List#add to simplify merge conflicts
Zabuzard Nov 12, 2021
039a0b2
Added CLA
Zabuzard Nov 15, 2021
7c53618
Added ModAuditLogRoutine
Zabuzard Nov 5, 2021
535dcb4
V3 -> V4 for mod audit table (after rebase)
Zabuzard Nov 6, 2021
425436f
Made majority of handle methods static
Zabuzard Nov 7, 2021
3df3968
NotNull for enum (CR by Tais)
Zabuzard Nov 7, 2021
4acd949
Added moderation commands (Ban, Kick, Unban)
RealYusufIsmail Nov 4, 2021
b2280e7
Fixed code flaws
Zabuzard Nov 3, 2021
6942294
Linter issues
Zabuzard Nov 3, 2021
28c0d1c
Readability fix (CR yusuf)
Zabuzard Nov 3, 2021
5dd3d2a
Moved several handle methods into helper
Zabuzard Nov 3, 2021
927cc59
Fixed some typos
Zabuzard Nov 5, 2021
7fb990c
Not banning already banned users
Zabuzard Nov 5, 2021
3a969c0
Added "unable to send DM" notice
Zabuzard Nov 5, 2021
86ac7b7
Fixed bug with unbanning non-banned users
Zabuzard Nov 5, 2021
cf2b91c
Fixed some typos
Zabuzard Nov 5, 2021
f3c2738
Using embed instead of plain messages
Zabuzard Nov 5, 2021
d2916ea
using constants to separate magic strings
Zabuzard Nov 6, 2021
d17d766
Readability cleanup on the "checks"
Zabuzard Nov 6, 2021
ea3196a
NotNull for enum (CR by Tais)
Zabuzard Nov 7, 2021
fc38c77
Making moderation commands role based instead of perms
Zabuzard Nov 8, 2021
235b984
Added back permission based system, additionally as secondary layer
Zabuzard Nov 12, 2021
c04956b
Spotless after rebase
Zabuzard Nov 15, 2021
a6ca390
empty line for readability (CR Tais)
Zabuzard Nov 15, 2021
4ea1de0
Simplified ban/kick flow using individual methods (CR Tais)
Zabuzard Nov 15, 2021
1ae5273
Moved failure handling for unban into method (CR Tais)
Zabuzard Nov 15, 2021
036b893
Missing imports after rebase
Zabuzard Nov 15, 2021
f4593eb
Some adjustments, shared the wrong CLA
Zabuzard Nov 16, 2021
d1fba01
Make Tag-Manage based on roles
Zabuzard Nov 9, 2021
224d3fe
using helper for role check (CR illu)
Zabuzard Nov 15, 2021
a96f447
Renamed database methods
Zabuzard Nov 17, 2021
2087bfd
Removed now obsolete curlies and java:S1602
Zabuzard Nov 17, 2021
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/staff-helpers
* @Together-Java/moderators @Together-Java/staff-assistants
6 changes: 5 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ updates:
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "daily"
interval: "monthly"
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-patch", "version-update:semver-minor"]
open-pull-requests-limit: 10
4 changes: 2 additions & 2 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ jobs:
sonar:
name: SonarCloud
runs-on: ubuntu-latest
# Skip this on PRs from forks as it will fail anyways as it needs secrets
if: ${{ !github.event.pull_request.head.repo.fork }}
steps:
- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -43,6 +41,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Sonar login token with 'Execute Analysis' privileges
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# this this on forks or dependabot PRs
if: env.SONAR_TOKEN != null
run: ./gradlew build sonarqube --info

codeql:
Expand Down
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,17 @@ gradle-app.setting
# End of https://www.toptal.com/developers/gitignore/api/netbeans,intellij,java,gradle,eclipse
application/db/
config.json
*.db
*.db-shm
*.db-wal
logviewer/frontend/generated
logviewer/node_modules
logviewer/.npmrc
logviewer/package.json
logviewer/pnpmfile.js
logviewer/tsconfig.json
logviewer/types.d.ts
logviewer/pnpm-lock.yaml
logviewer/webpack.config.js
logviewer/webpack.generated.js
.DS_Store
126 changes: 126 additions & 0 deletions CLA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
## Contributor Agreement

## Individual Contributor Exclusive License Agreement

## (including the Traditional Patent License OPTION)

Thank you for your interest in contributing to Together Java's TJ-Bot ("We" or "Us").

The purpose of this contributor agreement ("Agreement") is to clarify and document the rights granted by contributors to Us. To make this document effective, please follow the instructions given by the CLA-assistant bot in your Pull-Request.

### How to use this Contributor Agreement

If You are an employee and have created the Contribution as part of your employment, You need to have Your employer approve this Agreement or sign the Entity version of this document. If You do not own the Copyright in the entire work of authorship, any other author of the Contribution should also sign this – in any event, please contact Us at [email protected]

### 1\. Definitions

**"You"** means the individual Copyright owner who Submits a Contribution to Us.

**"Legal Entity"** means an entity that is not a natural person.

**"Affiliate"** means any other Legal Entity that controls, is controlled by, or under common control with that Legal Entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such Legal Entity, whether by contract or otherwise, (ii) ownership of fifty percent (50%) or more of the outstanding shares or securities that vote to elect the management or other persons who direct such Legal Entity or (iii) beneficial ownership of such entity.

**"Contribution"** means any original work of authorship, including any original modifications or additions to an existing work of authorship, Submitted by You to Us, in which You own the Copyright.

**"Copyright"** means all rights protecting works of authorship, including copyright, moral and neighboring rights, as appropriate, for the full term of their existence.

**"Material"** means the software or documentation made available by Us to third parties. When this Agreement covers more than one software project, the Material means the software or documentation to which the Contribution was Submitted. After You Submit the Contribution, it may be included in the Material.

**"Submit"** means any act by which a Contribution is transferred to Us by You by means of tangible or intangible media, including but not limited to electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, Us, but excluding any transfer that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution."

**"Documentation"** means any non-software portion of a Contribution.

### 2\. License grant

#### 2.1 Copyright license to Us

Subject to the terms and conditions of this Agreement, You hereby grant to Us a worldwide, royalty-free, Exclusive, perpetual and irrevocable (except as stated in Section 8.2) license, with the right to transfer an unlimited number of non-exclusive licenses or to grant sublicenses to third parties, under the Copyright covering the Contribution to use the Contribution by all means, including, but not limited to:

* publish the Contribution,
* modify the Contribution,
* prepare derivative works based upon or containing the Contribution and/or to combine the Contribution with other Materials,
* reproduce the Contribution in original or modified form,
* distribute, to make the Contribution available to the public, display and publicly perform the Contribution in original or modified form.

#### 2.2 Moral rights

Moral Rights remain unaffected to the extent they are recognized and not waivable by applicable law. Notwithstanding, You may add your name to the attribution mechanism customary used in the Materials you Contribute to, such as the header of the source code files of Your Contribution, and We will respect this attribution when using Your Contribution.

#### 2.3 Copyright license back to You

Upon such grant of rights to Us, We immediately grant to You a worldwide, royalty-free, non-exclusive, perpetual and irrevocable license, with the right to transfer an unlimited number of non-exclusive licenses or to grant sublicenses to third parties, under the Copyright covering the Contribution to use the Contribution by all means, including, but not limited to:

* publish the Contribution,
* modify the Contribution,
* prepare derivative works based upon or containing the Contribution and/or to combine the Contribution with other Materials,
* reproduce the Contribution in original or modified form,
* distribute, to make the Contribution available to the public, display and publicly perform the Contribution in original or modified form.

This license back is limited to the Contribution and does not provide any rights to the Material.

### 3\. Patents

#### 3.1 Patent license

Subject to the terms and conditions of this Agreement You hereby grant to Us and to recipients of Materials distributed by Us a worldwide, royalty-free, non-exclusive, perpetual and irrevocable (except as stated in Section 3.2) patent license, with the right to transfer an unlimited number of non-exclusive licenses or to grant sublicenses to third parties, to make, have made, use, sell, offer for sale, import and otherwise transfer the Contribution and the Contribution in combination with any Material (and portions of such combination). This license applies to all patents owned or controlled by You, whether already acquired or hereafter acquired, that would be infringed by making, having made, using, selling, offering for sale, importing or otherwise transferring of Your Contribution(s) alone or by combination of Your Contribution(s) with any Material.

#### 3.2 Revocation of patent license

You reserve the right to revoke the patent license stated in section 3.1 if We make any infringement claim that is targeted at your Contribution and not asserted for a Defensive Purpose. An assertion of claims of the Patents shall be considered for a "Defensive Purpose" if the claims are asserted against an entity that has filed, maintained, threatened, or voluntarily participated in a patent infringement lawsuit against Us or any of Our licensees.

### 4\. License obligations by Us

We agree to license the Contribution only under the terms of the license or licenses that We are using on the Submission Date for the Material (including any rights to adopt any future version of a license).

In addition, We may use the following licenses for Documentation in the Contribution: CC-BY-SA-4.0 (including any right to adopt any future version of a license).

We agree to license patents owned or controlled by You only to the extent necessary to (sub)license Your Contribution(s) and the combination of Your Contribution(s) with the Material under the terms of the license or licenses that We are using on the Submission Date.

### 5. Disclaimer

THE CONTRIBUTION IS PROVIDED "AS IS". MORE PARTICULARLY, ALL EXPRESS OR IMPLIED WARRANTIES INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTY OF SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY DISCLAIMED BY YOU TO US AND BY US TO YOU. TO THE EXTENT THAT ANY SUCH WARRANTIES CANNOT BE DISCLAIMED, SUCH WARRANTY IS LIMITED IN DURATION AND EXTENT TO THE MINIMUM PERIOD AND EXTENT PERMITTED BY LAW.

### 6. Consequential damage waiver

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT WILL YOU OR WE BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF ANTICIPATED SAVINGS, LOSS OF DATA, INDIRECT, SPECIAL, INCIDENTAL, CONSEQUENTIAL AND EXEMPLARY DAMAGES ARISING OUT OF THIS AGREEMENT REGARDLESS OF THE LEGAL OR EQUITABLE THEORY (CONTRACT, TORT OR OTHERWISE) UPON WHICH THE CLAIM IS BASED.

### 7. Approximation of disclaimer and damage waiver

IF THE DISCLAIMER AND DAMAGE WAIVER MENTIONED IN SECTION 5. AND SECTION 6. CANNOT BE GIVEN LEGAL EFFECT UNDER APPLICABLE LOCAL LAW, REVIEWING COURTS SHALL APPLY LOCAL LAW THAT MOST CLOSELY APPROXIMATES AN ABSOLUTE WAIVER OF ALL CIVIL OR CONTRACTUAL LIABILITY IN CONNECTION WITH THE CONTRIBUTION.

### 8. Term

8.1 This Agreement shall come into effect upon Your acceptance of the terms and conditions.

8.2 This Agreement shall apply for the term of the copyright and patents licensed here. However, You shall have the right to terminate the Agreement if We do not fulfill the obligations as set forth in Section 4. Such termination must be made in writing.

8.3 In the event of a termination of this Agreement Sections 5, 6, 7, 8 and 9 shall survive such termination and shall remain in full force thereafter. For the avoidance of doubt, Free and Open Source Software (sub)licenses that have already been granted for Contributions at the date of the termination shall remain in full force after the termination of this Agreement.

### 9 Miscellaneous

9.1 This Agreement and all disputes, claims, actions, suits or other proceedings arising out of this agreement or relating in any way to it shall be governed by the laws of Germany excluding its private international law provisions.

9.2 This Agreement sets out the entire agreement between You and Us for Your Contributions to Us and overrides all other agreements or understandings.

9.3 In case of Your death, this agreement shall continue with Your heirs. In case of more than one heir, all heirs must exercise their rights through a commonly authorized person.

9.4 If any provision of this Agreement is found void and unenforceable, such provision will be replaced to the extent possible with a provision that comes closest to the meaning of the original provision and that is enforceable. The terms and conditions set forth in this Agreement shall apply notwithstanding any failure of essential purpose of this Agreement or any limited remedy to the maximum extent possible under law.

9.5 You agree to notify Us of any facts or circumstances of which you become aware that would make this Agreement inaccurate in any respect.


### You

(sign this document digitally with your GitHub account)

### Us

Name: Daniel Tischner (aka Zabuzard, acting on behalf of Together Java)

Organization: https://github.com/Together-Java

Contact: https://discord.com/invite/XXFUXzK

#### Note

This document can be recreated or adjusted [here](https://contributoragreements.org/ca-cla-chooser/?beneficiary-name=Together+Java&project-name=TJ-Bot&project-website=https%3A%2F%2Fgithub.202132.xyz%2FTogether-Java%2FTJ-Bot&project-email=together.java.tjbot%40gmail.com&process-url=&project-jurisdiction=Germany&agreement-exclusivity=exclusive&fsfe-compliance=&fsfe-fla=&outbound-option=same&outboundlist=GPL-3.0&outboundlist-custom=&medialist=CC-BY-SA-4.0&patent-option=Traditional&your-date=&your-name=&your-title=&your-address=&your-patents=&pos=apply&action=).
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

TJ-Bot is a Discord Bot used on the [Together Java](https://discord.com/invite/XXFUXzK) server. It is maintained by the community, anyone can contribute.

![bot says hello](https://i.imgur.com/FE1MJTV.png)

# Getting started

Please read [Contributing](https://github.com/Together-Java/TJ-Bot/wiki/Contributing) if you want to propose ideas and changes or even implement some yourself.
Expand Down
19 changes: 16 additions & 3 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
id 'application'
id 'com.google.cloud.tools.jib' version '3.1.4'
id 'com.github.johnrengelman.shadow' version '7.1.0'
id 'database-settings'
}

repositories {
Expand All @@ -29,6 +30,10 @@ jib {
password = System.getenv('REGISTRY_PASSWORD') ?: ''
}
}
container {
mainClass = 'org.togetherjava.tjbot.BootstrapLauncher'
setCreationTime(java.time.Instant.now().toString())
}
}

shadowJar {
Expand All @@ -40,23 +45,31 @@ shadowJar {
dependencies {
implementation project(':database')

implementation 'net.dv8tion:JDA:4.3.0_331'
implementation 'net.dv8tion:JDA:4.3.0_339'

implementation 'org.apache.logging.log4j:log4j-api:2.14.1'
implementation 'org.apache.logging.log4j:log4j-core:2.14.1'
implementation 'org.apache.logging.log4j:log4j-slf4j18-impl:2.14.1'

implementation 'org.jooq:jooq:3.15.3'

implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.12.5'
implementation 'org.scilab.forge:jlatexmath:1.0.7'
implementation 'org.scilab.forge:jlatexmath-font-greek:1.0.7'
implementation 'org.scilab.forge:jlatexmath-font-cyrillic:1.0.7'

implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.13.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'

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

testImplementation 'org.mockito:mockito-core:4.0.0'
testRuntimeOnly 'org.mockito:mockito-core:4.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

application {
mainClass = 'org.togetherjava.tjbot.Application'
mainClass = 'org.togetherjava.tjbot.BootstrapLauncher'
}

test {
Expand Down
34 changes: 14 additions & 20 deletions application/src/main/java/org/togetherjava/tjbot/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import org.togetherjava.tjbot.commands.system.CommandSystem;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.db.Database;
import org.togetherjava.tjbot.routines.ModAuditLogRoutine;

import javax.security.auth.login.LoginException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.SQLException;

Expand Down Expand Up @@ -41,8 +43,6 @@ public static void main(final String[] args) {
+ DEFAULT_CONFIG_PATH + "' will be assumed.");
}

setSystemProperties();

Path configPath = Path.of(args.length == 1 ? args[0] : DEFAULT_CONFIG_PATH);
try {
Config.load(configPath);
Expand All @@ -66,9 +66,14 @@ public static void main(final String[] args) {
* @param token the Discord Bot token to connect with
* @param databasePath the path to the database to use
*/
@SuppressWarnings("WeakerAccess")
public static void runBot(String token, Path databasePath) {
logger.info("Starting bot...");
try {
Path parentDatabasePath = databasePath.toAbsolutePath().getParent();
if (parentDatabasePath != null) {
Files.createDirectories(parentDatabasePath);
}
Database database = new Database("jdbc:sqlite:" + databasePath.toAbsolutePath());

JDA jda = JDABuilder.createDefault(token)
Expand All @@ -77,6 +82,10 @@ public static void runBot(String token, Path databasePath) {
jda.awaitReady();
logger.info("Bot is ready");

// TODO This should be moved into some proper command system instead (see GH issue #235
// which adds support for routines)
new ModAuditLogRoutine(jda, database).start();

Runtime.getRuntime().addShutdownHook(new Thread(Application::onShutdown));
} catch (LoginException e) {
logger.error("Failed to login", e);
Expand All @@ -85,6 +94,9 @@ public static void runBot(String token, Path databasePath) {
Thread.currentThread().interrupt();
} catch (SQLException e) {
logger.error("Failed to create database", e);
} catch (IOException e) {
logger.error("Failed to create path to the database at: {}",
databasePath.toAbsolutePath(), e);
}
}

Expand All @@ -96,22 +108,4 @@ private static void onShutdown() {
logger.info("Bot has been stopped");
}

/**
* Sets any system-properties before anything else is touched.
*/
private static void setSystemProperties() {
final int cores = Runtime.getRuntime().availableProcessors();
if (cores <= 1) {
// If we are in a docker container, we officially might just have 1 core
// and Java would then set the parallelism of the common ForkJoinPool to 0.
// And 0 means no workers, so JDA cannot function, no Callback's on REST-Requests
// are executed
// NOTE This will likely be fixed with Java 18 or newer, remove afterwards (see
// https://bugs.openjdk.java.net/browse/JDK-8274349 and
// https://github.com/openjdk/jdk/pull/5784)
logger.debug("Available Cores \"{}\", setting Parallelism Flag", cores);
// noinspection AccessOfSystemProperties
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "1");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.togetherjava.tjbot;

/**
* A bootstrap launcher with minimal dependencies that sets up needed parts and workarounds for the
* main logic to take over.
*/
public enum BootstrapLauncher {
;

/**
* Starts the main application.
*
* @param args arguments are forwarded, see {@link Application#main(String[])}
*/
public static void main(String[] args) {
setSystemProperties();

Application.main(args);
}


/**
* Sets any system-properties before anything else is touched.
*/
@SuppressWarnings("squid:S106") // we can not afford any dependencies, even on a logger
private static void setSystemProperties() {
final int cores = Runtime.getRuntime().availableProcessors();
if (cores <= 1) {
// If we are in a docker container, we officially might just have 1 core
// and Java would then set the parallelism of the common ForkJoinPool to 0.
// And 0 means no workers, so JDA cannot function, no Callback's on REST-Requests
// are executed
// NOTE This will likely be fixed with Java 18 or newer, remove afterwards (see
// https://bugs.openjdk.java.net/browse/JDK-8274349 and
// https://github.com/openjdk/jdk/pull/5784)
// noinspection UseOfSystemOutOrSystemErr
System.out.println("Available Cores \"" + cores + "\", setting Parallelism Flag");
// noinspection AccessOfSystemProperties
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "1");
}
}
}
Loading