Skip to content

Commit

Permalink
Merge pull request #223 from bendavies99/rewrite/using-spring
Browse files Browse the repository at this point in the history
Rewrite/using spring
  • Loading branch information
bendavies99 authored Jun 1, 2023
2 parents 6d79830 + efb5e55 commit e24abc5
Show file tree
Hide file tree
Showing 125 changed files with 4,194 additions and 5,587 deletions.
1,181 changes: 1,181 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repositories {
}
dependancies {
implementation 'uk.co.bjdavies:babblebot-server-api:1.0.0'
implementation 'net.bdavies:babblebot-server-api:1.0.0'
}
```

Expand All @@ -35,7 +35,7 @@ dependancies {

<dependencies>
<dependency>
<groupId>uk.co.bjdavies</groupId>
<groupId>net.bdavies</groupId>
<artifactId>babblebot-server-api</artifactId>
<version>1.0.0</version>
</dependency>
Expand Down
16 changes: 14 additions & 2 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
plugins {
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java-library'
}

sourceCompatibility = '17'
targetCompatibility = '17'

dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:3.1.0")
}
}

dependencies {
api 'com.google.inject:guice:4.2.2'
api 'com.discord4j:discord4j-core:3.1.3'
api 'com.discord4j:discord4j-core:3.2.4'
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
11 changes: 8 additions & 3 deletions api/src/main/java/net/bdavies/api/IApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@
import net.bdavies.api.config.IConfig;
import net.bdavies.api.plugins.IPluginContainer;
import net.bdavies.api.variables.IVariableContainer;
import org.springframework.stereotype.Component;

/**
* This is a interface for an application
*
* @author ben.davies99@outlook.com (Ben Davies)
* @since 1.0.0
*/
public interface IApplication {
@Component
public interface IApplication
{

/**
* This will return of a instance of a class and inject any dependencies that are inside the dependency injector.
* This will return of a instance of a class and inject any dependencies that are inside the dependency
* injector.
*
* @param clazz - this is the class to create
* @return {@link Object<T>} this is an object of type T
Expand Down Expand Up @@ -87,7 +91,8 @@ public interface IApplication {
void shutdown(int timeout);

/**
* This will return true if babblebot has a argument basic at the moment only supports empty arguments e.g. -restart
* This will return true if babblebot has a argument basic at the moment only supports empty arguments
* e.g. -restart
*
* @param argument - argument to test for
* @return boolean
Expand Down
22 changes: 3 additions & 19 deletions api/src/main/java/net/bdavies/api/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

package net.bdavies.api.command;

import javax.annotation.CheckReturnValue;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -44,8 +44,8 @@
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@CheckReturnValue
public @interface Command {
public @interface Command
{
/**
* The aliases of the command.
*
Expand All @@ -61,14 +61,6 @@
*/
String description() default "";

/**
* The Usage for the command.
*
* @return String
* @deprecated automatically generated
*/
String usage() default "";

/**
* This determines where the command requires a value or not
*
Expand All @@ -89,12 +81,4 @@
* @return String
*/
String type() default "Discord";

/**
* A list of required params for the command.
*
* @return String[]
* @deprecated please use {@link CommandParam}
*/
String[] requiredParams() default "";
}
11 changes: 0 additions & 11 deletions api/src/main/java/net/bdavies/api/command/ICommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ public interface ICommand {
*/
String getType();


/**
* This is the execution point for the command.
*
* @param application - The application instance.
* @param commandContext - The command context for all command parameters and values.
* @return String - This return method is deprecated. use {@link ICommandResponse}
* @deprecated - To be removed in 2.0.0
*/
String run(IApplication application, ICommandContext commandContext);

/**
* This is the execution point for the command.
*
Expand Down
12 changes: 0 additions & 12 deletions api/src/main/java/net/bdavies/api/command/ICommandContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@

package net.bdavies.api.command;

import discord4j.core.object.entity.Message;
import net.bdavies.api.discord.IDiscordCommandUtil;

/**
* @author ben.davies99@outlook.com (Ben Davies)
* @since 1.0.0
Expand Down Expand Up @@ -80,15 +77,6 @@ public interface ICommandContext {
*/
String getType();

IDiscordCommandUtil getCommandUtils();

/**
* This will return the message object.
*
* @return IMessage
*/
Message getMessage();

/**
* This will return a response instance so you can send responses to the discord client.
*
Expand Down
46 changes: 41 additions & 5 deletions api/src/main/java/net/bdavies/api/command/ICommandDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,35 @@

package net.bdavies.api.command;

import net.bdavies.api.IApplication;
import net.bdavies.api.plugins.IPlugin;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import net.bdavies.api.plugins.IPlugin;

import java.util.List;

/**
* @author ben.davies99@outlook.com (Ben Davies)
* @since 1.0.0
*/
public interface ICommandDispatcher {
@Component
public interface ICommandDispatcher
{

/**
* This is where you can a command to the command dispatcher.
*
* @param command - The command you wish to add.
*/
void addCommand(String namespace, ICommand command);
void addCommand(String namespace, ICommand command, IApplication application);

/**
* This is where you can a command to the command dispatcher.
*
* @param commands - The commands you wish to add.
*/
void addNamespace(String namespace, List<ICommand> commands);
void addNamespace(String namespace, List<ICommand> commands, IApplication application);


/**
Expand Down Expand Up @@ -90,13 +94,45 @@ public interface ICommandDispatcher {
*/
Flux<ICommand> getCommands(String type);

/**
* Get all the commands for a certain namespace
*
* @param namespace the namespace to lookup
* @return {@link Flux} of {@link ICommand}s
*/
Flux<ICommand> getCommandsFromNamespace(String namespace);

/**
* Get all the namespaces that are registered inside the command dispatcher
*
* @return {@link Flux} of {@link String}s
*/
Flux<String> getRegisteredNamespaces();

/**
* Get the namespace from a command
*
* @param commandName the whole command name
* @return {@link String}
*/
String getNamespaceFromCommandName(String commandName);

void registerGlobalMiddleware(ICommandMiddleware middleware);
/**
* Register Global middleware that will run before the execution of the command implementation for all
* commands regardless of the namespace it can stop execution of the command at this point
*
* @param middleware {@link ICommandMiddleware} the middleware object that will be run
* @param registrar the object that is registering the middleware
* @param application {@link IApplication} instance of the application
*/
void registerGlobalMiddleware(ICommandMiddleware middleware, Object registrar, IApplication application);

/**
* Register Plugin middleware that will run before the execution of the command implementation for all
* commands of the namespace of the plugin it can stop execution of the command at this point
*
* @param plugin the plugin object
* @param middleware {@link ICommandMiddleware} the middleware object that will be run
*/
void registerPluginMiddleware(IPlugin plugin, ICommandMiddleware middleware);
}
6 changes: 3 additions & 3 deletions api/src/main/java/net/bdavies/api/command/IResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

package net.bdavies.api.command;

import discord4j.core.spec.EmbedCreateSpec;
import net.bdavies.api.obj.message.discord.embed.EmbedMessage;

import java.util.function.Consumer;
import java.util.function.Supplier;

/**
* @author ben.davies99@outlook.com (Ben Davies)
Expand All @@ -37,7 +37,7 @@ public interface IResponse {

String getStringResponse();

Consumer<EmbedCreateSpec> getEmbedCreateSpecResponse();
Supplier<EmbedMessage> getEmbedCreateSpecResponse();

boolean isStringResponse();
}
20 changes: 2 additions & 18 deletions api/src/main/java/net/bdavies/api/config/IConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
* Date Created: 30/01/2018
*/

public interface IConfig {
public interface IConfig
{

/**
* This will return the config for the discord part of this bot.
Expand All @@ -44,30 +45,13 @@ public interface IConfig {
*/
IDiscordConfig getDiscordConfig();


/**
* This will return the config for the system part of this bot.
*
* @return {@link ISystemConfig}
*/
ISystemConfig getSystemConfig();

/**
* This will return the config for the HTTP Server.
*
* @return {@link IHttpConfig}
*/
IHttpConfig getHttpConfig();


/**
* This will return the config for the database part of the bot.
*
* @return {@link IDatabaseConfig}
*/
IDatabaseConfig getDatabaseConfig();


/**
* This will return the config for the plugins used in this bot.
*
Expand Down
12 changes: 10 additions & 2 deletions api/src/main/java/net/bdavies/api/config/IPluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@

package net.bdavies.api.config;

import java.util.List;

/**
* @author ben.davies99@outlook.com (Ben Davies)
* @since 1.0.0
*/
public interface IPluginConfig {
public interface IPluginConfig
{
/**
* This will return the plugin's location.
* e.g. audiobot -> plugins/audiobot/....
Expand All @@ -52,5 +55,10 @@ public interface IPluginConfig {
*/
String getPluginType();


/**
* This will return all the permissions registered for the plugin
*
* @return {@link EPluginPermission}
*/
List<EPluginPermission> getPluginPermissions();
}
14 changes: 10 additions & 4 deletions api/src/main/java/net/bdavies/api/discord/IDiscordFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,28 @@
import discord4j.core.object.entity.User;
import discord4j.core.object.presence.Activity;
import discord4j.core.object.presence.Presence;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.function.Consumer;

/**
* This is the Public API for the Discord4JWrapper of the Discord API this will be used for plugins
* <p>
* An example use case being calling {@link IDiscordFacade#getClient()} in a plugin will give you access to the
* An example use case being calling {@link IDiscordFacade#getClient()} in a plugin will give you access
* to the
* {@link DiscordClient}
* Use DiscordClient at your own risk it is subject to change, I would recommend just using the api given to you
* Use DiscordClient at your own risk it is subject to change, I would recommend just using the api given
* to you
* through the facade.
* </p>
*
* @author ben.davies99@outlook.com (Ben Davies)
* @since 1.0.0
*/
public interface IDiscordFacade {
@Component
public interface IDiscordFacade
{
/**
* This is available to the public through plugins and this will allow for a bot to be logged out
* I wouldn't recommend using this only if you would like to implement a logout command for the bot.
Expand All @@ -65,7 +70,8 @@ public interface IDiscordFacade {

/**
* This is available to the public through plugins and this will return the bot user.
* To use try doing {@code facade.getOurUser().subscribe(user -> System.out.println(user.getUsername()));} look
* To use try doing {@code facade.getOurUser().subscribe(user -> System.out.println(user.getUsername())
* );} look
* at {@link Mono#subscribe(java.util.function.Consumer)}
*
* @return {@link Mono} this is a Mono Stream of a User
Expand Down
Loading

0 comments on commit e24abc5

Please sign in to comment.