This commit is contained in:
Paldiu 2021-03-01 08:56:06 -06:00
parent 30f8c558d2
commit 99d55f36da
21 changed files with 141 additions and 24 deletions

3
.gitignore vendored
View File

@ -21,3 +21,6 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.gradle/*
build/*
.idea/*

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -11,10 +11,10 @@ repositories {
}
dependencies {
implementation 'org.jetbrains:annotations:20.1.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
compile 'com.discord4j:discord4j-core:3.1.3'
compile 'org.slf4j:slf4j-api:1.7.25'
}
shadowJar {

View File

@ -1,11 +1,16 @@
package io.github.paldiu.obsidian;
import io.github.paldiu.obsidian.utils.Constants;
import io.github.paldiu.obsidian.utils.Bot;
public final class Obsidian {
// This class only initializes the bot.
// Using utility classes to manage instances.
private static Bot bot;
public static void main(String[] args) {
Constants.getRegistry().verify();
bot = new Bot();
getBot().verify();
}
public static Bot getBot() {
return bot;
}
}

View File

@ -10,12 +10,4 @@ public class Commands {
};
}
private Command coloredRank(User user, Message message) {
return () -> {
message.getGuild().
};
}
}

View File

@ -0,0 +1,4 @@
package io.github.paldiu.obsidian.embed;
public class Embedder {
}

View File

@ -0,0 +1,19 @@
package io.github.paldiu.obsidian.listener;
import discord4j.core.event.domain.Event;
import reactor.core.publisher.Mono;
import java.util.logging.Logger;
public interface EventListener<T extends Event> {
Logger LOG = Logger.getLogger(EventListener.class.getSimpleName());
Class<T> getEventType();
Mono<Void> execute(T event);
default Mono<Void> handleError(Throwable error) {
LOG.severe("Unable to process " + getEventType().getSimpleName() + "\n" + error.getMessage());
return Mono.empty();
}
}

View File

@ -27,7 +27,7 @@ public class PropertiesManager {
properties.setProperty("author", "Predicate<? super T>#0001");
properties.setProperty("version", "1.0.0");
properties.setProperty("encoding", "UTF_8");
properties.setProperty("token", "REPLACEME");
properties.setProperty("token", "BOT_TOKEN");
return this;
}
@ -47,7 +47,7 @@ public class PropertiesManager {
try (OutputStream stream = new FileOutputStream(child)) {
properties.store(stream, null);
} catch (IOException e) {
Constants.getLogger().error(e.getMessage());
Constants.getLogger().severe(e.getMessage());
}
}

View File

@ -0,0 +1,17 @@
package io.github.paldiu.obsidian.ticketer;
import discord4j.core.object.entity.User;
import java.util.function.Supplier;
public interface Ticket {
User getUserCreated();
User getAssignedUser();
Supplier<String> getCommissionSpecifications();
Supplier<Integer> getCommissionPrice();
TicketStatus getTicketStatus();
}

View File

@ -0,0 +1,51 @@
package io.github.paldiu.obsidian.ticketer;
import discord4j.core.object.entity.User;
import java.util.function.Supplier;
public class TicketModule {
private volatile Ticket ticket;
public TicketModule(Ticket ticket) {
this.ticket = ticket;
}
public TicketModule() {
ticket = null;
}
public TicketModule createNewTicket(User userCreated, User assigned, Supplier<String> commissionSpecifications, Supplier<Integer> commissionPrice, TicketStatus type) {
ticket = new Ticket() {
@Override
public User getUserCreated() {
return assigned;
}
@Override
public User getAssignedUser() {
return userCreated;
}
@Override
public Supplier<String> getCommissionSpecifications() {
return commissionSpecifications;
}
@Override
public Supplier<Integer> getCommissionPrice() {
return commissionPrice;
}
@Override
public TicketStatus getTicketStatus() {
return type;
}
};
return this;
}
public Ticket getTicket() {
return ticket;
}
}

View File

@ -0,0 +1,19 @@
package io.github.paldiu.obsidian.ticketer;
public enum TicketStatus {
OPEN("The ticket has been marked as open."),
PENDING("The ticket is now pending approval."),
IN_PROGRESS("The ticket is now in progress."),
COMPLETED("The ticket has been marked as completed."),
CLOSED("The ticket has been marked as closed.");
private final String message;
TicketStatus(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}

View File

@ -2,7 +2,6 @@ package io.github.paldiu.obsidian.utils;
import discord4j.common.util.Snowflake;
import discord4j.core.DiscordClient;
import discord4j.core.DiscordClientBuilder;
import discord4j.core.GatewayDiscordClient;
import discord4j.core.event.domain.lifecycle.ReadyEvent;
import discord4j.core.object.entity.User;
@ -11,12 +10,12 @@ import discord4j.discordjson.json.UserData;
import discord4j.rest.response.ResponseFunction;
import io.github.paldiu.obsidian.props.PropertiesManager;
public final class Registry {
public final class Bot {
private final GatewayDiscordClient gateway;
private final DiscordClient client;
private final String token;
public Registry() {
public Bot() {
PropertiesManager.getInstance().load();
token = PropertiesManager.getInstance().getToken();
client = DiscordClient.builder(token)

View File

@ -1,17 +1,19 @@
package io.github.paldiu.obsidian.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.function.Consumer;
import java.util.logging.Logger;
// Utility Class
public final class Constants {
private static final Logger logger = LoggerFactory.getLogger("obsidian");
private static final Registry registry = new Registry();
private static final Logger logger = Logger.getLogger("obsidian");
public static Logger getLogger() {
return logger;
}
public static Registry getRegistry() {
return registry;
public static <T> void forEach(T[] array, Consumer<T> action) {
for (T obj : array) {
action.accept(obj);
}
}
}