Skip to content

Commit

Permalink
refactor: Update config system and serialise the plugins into the db
Browse files Browse the repository at this point in the history
  • Loading branch information
bendavies99 committed Jun 6, 2023
1 parent 41fec25 commit 24b24aa
Show file tree
Hide file tree
Showing 41 changed files with 631 additions and 703 deletions.
4 changes: 2 additions & 2 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencyManagement {

dependencies {
api 'com.discord4j:discord4j-core:3.2.4'
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.projectlombok:lombok'
api 'org.springframework.boot:spring-boot-starter'
api 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
8 changes: 0 additions & 8 deletions api/src/main/java/net/bdavies/api/IApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package net.bdavies.api;

import net.bdavies.api.command.ICommandDispatcher;
import net.bdavies.api.config.IConfig;
import net.bdavies.api.plugins.IPluginContainer;
import net.bdavies.api.variables.IVariableContainer;
import org.springframework.stereotype.Component;
Expand All @@ -50,13 +49,6 @@ public interface IApplication
*/
<T> T get(Class<T> clazz);

/**
* This will return an instance of the application config from config.json file in your root directory.
*
* @return {@link IConfig}
*/
IConfig getConfig();

/**
* This will return an instance of the application command dispatcher.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
package net.bdavies.api.command;

import net.bdavies.api.IApplication;
import net.bdavies.api.plugins.IPlugin;
import net.bdavies.api.plugins.IPluginSettings;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -134,5 +134,5 @@ public interface ICommandDispatcher
* @param plugin the plugin object
* @param middleware {@link ICommandMiddleware} the middleware object that will be run
*/
void registerPluginMiddleware(IPlugin plugin, ICommandMiddleware middleware);
void registerPluginMiddleware(IPluginSettings plugin, ICommandMiddleware middleware);
}
10 changes: 0 additions & 10 deletions api/src/main/java/net/bdavies/api/config/IConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

package net.bdavies.api.config;

import java.util.List;

/**
* BabbleBot, open-source Discord Bot
* Author: Ben Davies
Expand All @@ -51,12 +49,4 @@ public interface IConfig
* @return {@link ISystemConfig}
*/
ISystemConfig getSystemConfig();

/**
* This will return the config for the plugins used in this bot.
*
* @return {@link List<IPluginConfig>}
*/
List<IPluginConfig> getPlugins();

}
9 changes: 0 additions & 9 deletions api/src/main/java/net/bdavies/api/config/ISystemConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@
*/
public interface ISystemConfig {

/**
* This will return if the server will auto-update based on github. If turned off the user will manually have to update.
* Default: On
*
* @return boolean
*/
boolean isAutoUpdateOn();


/**
* This will return if debug is on.
*
Expand Down
42 changes: 42 additions & 0 deletions api/src/main/java/net/bdavies/api/core/IAnnouncementService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* MIT License
*
* Copyright (c) 2020 Ben Davies
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package net.bdavies.api.core;

import org.springframework.stereotype.Service;

/**
* Announcement Service to send announcements through the announcement channel for important updates
*
* @author me@bdavies.net (Ben Davies)
* @since __RELEASE_VERSION__
*/
@Service
public interface IAnnouncementService
{
void sendMessage(String title, String message);

void sendMessage(String message);
}
21 changes: 2 additions & 19 deletions api/src/main/java/net/bdavies/api/plugins/IPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,15 @@
* @author ben.davies99@outlook.com (Ben Davies)
* @since 1.0.0
*/
public interface IPlugin {
public interface IPlugin
{
/**
* This is the name of the Plugin.
*
* @return String
*/
String getName();

/**
* This is the version of the Plugin.
*
* @return String
* @deprecated Not required for plugin processing
*/
String getVersion();

/**
* This is the author of the Plugin.
*
Expand All @@ -65,14 +58,4 @@ public interface IPlugin {
* @return String
*/
String getMaximumServerVersion();

/**
* This is the namespace for your commands
* Please don't use ""
* <p>
* Because if it clashes with any commands your commands will not be added to system.
*
* @return String
*/
String getNamespace();
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public interface IPluginContainer
* @param name - The name of the plugin.
* @param plugin - The plugin itself.
*/
void addPlugin(String name, Object plugin, List<EPluginPermission> pluginPermissions);
void addPlugin(String name, Object plugin, List<EPluginPermission> pluginPermissions, String namespace);

/**
* This method will allow you to add a plugin to the container.
*
* @param plugin - The plugin itself.
*/
void addPlugin(Object plugin, List<EPluginPermission> pluginPermissions);
void addPlugin(Object plugin, List<EPluginPermission> pluginPermissions, String namespace);


/**
Expand Down
12 changes: 4 additions & 8 deletions api/src/main/java/net/bdavies/api/plugins/IPluginEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,16 @@
* @author ben.davies99@outlook.com (Ben Davies)
* @since 1.2.7
*/
public interface IPluginEvents {
/**
* This will run on a Babblebot-Server Agent HotSwap.
*/
void onReload();

public interface IPluginEvents
{
/**
* This will run when the plugin is installed.
* Runs before the commands are installed, so you can do setup code here.
*/
void onBoot(IPluginSettings settings);
default void onBoot(IPluginSettings settings) {}

/**
* This will run the plugin is removed from the app or the application has shutdown.
*/
void onShutdown();
default void onShutdown() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@
* @author ben.davies99@outlook.com (Ben Davies)
* @since 1.2.7
*/
public interface IPluginSettings extends IPlugin {

public interface IPluginSettings extends IPlugin
{
/**
* This is the namespace for your commands
* Please don't use ""
* <p>
* Because if it clashes with any commands your commands will not be added to system.
*
* @param namespace - the new space you wish to use.
* @return String
*/
void setNamespace(String namespace);

String getNamespace();
}
23 changes: 12 additions & 11 deletions api/src/main/java/net/bdavies/api/plugins/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,23 @@
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Plugin {
// This is the name of the plugin
public @interface Plugin
{
/**
* The name of your plugin
*
* @return String
*/
String value() default "";

String author() default "babblebot-plugin-developer";

String minServerVersion() default "0";

String maxServerVersion() default "0";

/**
* Name space will be default to the value a.k.a name with a -.
* e.g. color-
* The author of the plugin
*
* @return String
*/
String namespace() default "<bb-def-uniq>";
String author() default "babblebot-plugin-developer";

String minServerVersion() default "0";

String maxServerVersion() default "0";
}
9 changes: 4 additions & 5 deletions api/src/main/java/net/bdavies/api/plugins/PluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@
*/
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface PluginConfig {
public @interface PluginConfig
{
Class<? extends ICustomPluginConfig> value() default ICustomPluginConfig.class;

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@interface Setup {
@interface Setup
{
boolean autoGenerate() default true;

String fileName() default "";
}

}
9 changes: 2 additions & 7 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,20 @@ dependencies {
implementation project(':api')
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-websocket'

implementation 'uk.org.lidalia:sysout-over-slf4j:1.0.2'
runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'com.oracle.database.jdbc:ojdbc8'
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
runtimeOnly 'org.postgresql:postgresql'
implementation 'io.lindstrom:m3u8-parser:0.24'
implementation 'org.apache.httpcomponents.client5:httpclient5:5.2'
implementation('fr.whimtrip:whimtrip-ext-htmltopojo:1.0.2') {
exclude group: "org.slf4j", module: 'slf4j-simple'
}
implementation 'commons-io:commons-io:2.11.0'
compileOnly 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'

Expand Down
Loading

0 comments on commit 24b24aa

Please sign in to comment.