Skip to content

Commit

Permalink
Merge pull request #69 from FoxGenesis/plugin-intents
Browse files Browse the repository at this point in the history
New plugin intents system
  • Loading branch information
AshlyneS authored Nov 22, 2023
2 parents b9ca656 + 0dd4677 commit bbc0784
Show file tree
Hide file tree
Showing 61 changed files with 2,404 additions and 742 deletions.
3 changes: 1 addition & 2 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="assets">
<classpathentry excluding="**" kind="src" output="target/classes" path="assets">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="maven.pomderived" value="true"/>
Expand All @@ -16,7 +16,6 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ assets/resources/database.properties
/logs/
/config/
/lib/
sysinfo.txt
24 changes: 12 additions & 12 deletions assets/META-INF/defaults/watamebot.ini
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[Token]
# Path to login token file
tokenFile = config/token.txt
[WatameBot.Token]
# Relative path to discord bot token file
tokenFile = token.txt

[WatameBot.Status]
[Startup.Status]
# Startup activity status
startup = Initalizing...
# Activity status after startup
online = https://github.com/FoxGenesis/Watamebot

[SingleInstance]
[Startup.SingleInstance]
# Allow only one instance to run at a time
enabled = true
# Amount of times to attempt to obtain instance lock
retries = 5

[Runtime]
#
ansiConsole = true
[PushBullet]
# Pushbullet token
token =

[Logging]
# Logging level (info | debug | trace)
logLevel = info

[PushBullet]
# Pushbullet token
token =
# Display ANSI colors in console
ansiConsole = true
7 changes: 7 additions & 0 deletions assets/META-INF/integrated.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[IntegratedPlugin]
# Enable/Disable the '/options configuration' command
enableOptionsCommand = false
# Enable/Disable the '/ping' command
enablePingCommand = true
# Enable/Disable the '/uptime' command
enableUptimeCommand = true
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>5.0.0-beta.12</version>
<version>5.0.0-beta.18</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -97,7 +97,6 @@
<artifactId>annotations</artifactId>
<version>24.0.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
Expand Down
3 changes: 3 additions & 0 deletions src/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
requires java.sql;
requires com.fasterxml.jackson.databind;
requires okhttp3;
requires java.management;

exports net.foxgenesis.config;
exports net.foxgenesis.database;
exports net.foxgenesis.executor;
exports net.foxgenesis.http;
exports net.foxgenesis.property;
exports net.foxgenesis.property.lck;
exports net.foxgenesis.log;
exports net.foxgenesis.watame;
exports net.foxgenesis.watame.plugin;
exports net.foxgenesis.watame.plugin.require;
exports net.foxgenesis.util;
exports net.foxgenesis.util.resource;
exports net.foxgenesis.util.function;
Expand Down
12 changes: 7 additions & 5 deletions src/net/foxgenesis/database/AConnectionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class AConnectionProvider implements AutoCloseable {
private final String name;
private final String database;

public AConnectionProvider( @NotNull String name, @NotNull Properties properties) {
public AConnectionProvider(@NotNull String name, @NotNull Properties properties) {
this.name = Objects.requireNonNull(name);
logger = LoggerFactory.getLogger(name);
this.properties = Objects.requireNonNull(properties);
Expand All @@ -43,16 +43,17 @@ public AConnectionProvider( @NotNull String name, @NotNull Properties properties

@NotNull
protected abstract Connection openConnection() throws SQLException;

@NotNull
protected <U> Optional<U> openAutoClosedConnection(@NotNull ConnectionConsumer<U> consumer) throws SQLException {
try(Connection conn = openConnection()) {
try (Connection conn = openConnection()) {
return Optional.ofNullable(consumer.applyConnection(conn));
}
}

@NotNull
protected <U> Optional<U> openAutoClosedConnection(@NotNull ConnectionConsumer<U> consumer, Consumer<Throwable> error) {
protected <U> Optional<U> openAutoClosedConnection(@NotNull ConnectionConsumer<U> consumer,
Consumer<Throwable> error) {
try (Connection conn = openConnection()) {
return Optional.ofNullable(consumer.applyConnection(conn));
} catch (Exception e) {
Expand All @@ -78,6 +79,7 @@ public void close() throws Exception {

@FunctionalInterface
public interface ConnectionConsumer<U> {
@SuppressWarnings("exports") U applyConnection(@NotNull Connection connection) throws SQLException;
@SuppressWarnings("exports")
U applyConnection(@NotNull Connection connection) throws SQLException;
}
}
6 changes: 3 additions & 3 deletions src/net/foxgenesis/database/DatabaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public DatabaseManager(@NotNull String name) {
public boolean register(@NotNull Plugin plugin, @NotNull AbstractDatabase database) throws IOException {
Objects.requireNonNull(database);

if (!plugin.needsDatabase)
if (!plugin.getInfo().requiresDatabase())
throw new IllegalArgumentException("Plugin does not declare that it needs database connection!");

if (isDatabaseRegistered(database))
Expand Down Expand Up @@ -95,13 +95,13 @@ public boolean register(@NotNull Plugin plugin, @NotNull AbstractDatabase databa
* been unloaded. {@code false} otherwise
*/
public boolean unload(Plugin owner) {
if (!owner.needsDatabase)
if (!owner.getInfo().requiresDatabase())
return false;

if (databases.containsKey(owner)) {
synchronized (databases) {
if (databases.containsKey(owner)) {
logger.info("Unloading databases from {}", owner.friendlyName);
logger.info("Unloading databases from {}", owner.getInfo().getDisplayName());
Set<AbstractDatabase> databases = this.databases.remove(owner);

for (AbstractDatabase database : databases)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ public MySQLConnectionProvider(Properties properties) throws ConnectException {

try {
source = new HikariDataSource(new HikariConfig(properties));
} catch(Exception e) {
} catch (Exception e) {
throw new ConnectException("Failed to connect to database");
}
}

@Override
protected Connection openConnection() throws SQLException { return source.getConnection(); }
protected Connection openConnection() throws SQLException {
return source.getConnection();
}
}
12 changes: 9 additions & 3 deletions src/net/foxgenesis/executor/PrefixedThreadFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public class PrefixedThreadFactory implements ThreadFactory {

private final boolean daemon;

public PrefixedThreadFactory(@NotNull String prefix) { this(prefix, true); }
public PrefixedThreadFactory(@NotNull String prefix) {
this(prefix, true);
}

@SuppressWarnings("null")
public PrefixedThreadFactory(@NotNull String prefix, boolean daemon) {
Expand All @@ -30,7 +32,11 @@ public Thread newThread(Runnable r) {
}

@NotNull
public String getPrefix() { return prefix; }
public String getPrefix() {
return prefix;
}

public boolean isDaemon() { return daemon; }
public boolean isDaemon() {
return daemon;
}
}
10 changes: 10 additions & 0 deletions src/net/foxgenesis/http/ApiKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.foxgenesis.http;

import org.jetbrains.annotations.NotNull;

public record ApiKey(@NotNull KeyType type, @NotNull String name, @NotNull String token) {

public static enum KeyType {
HEADER, PARAMETER
}
}
Loading

0 comments on commit bbc0784

Please sign in to comment.