Skip to content

Commit

Permalink
BREAKING_CHANGE: Merged v0.6.0 into main and there by releasing V1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Greazi-Times committed Jun 8, 2022
2 parents 1a11e36 + 29f5e9e commit 887ad72
Show file tree
Hide file tree
Showing 63 changed files with 3,609 additions and 554 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/todo-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "To Do to Issue"
on: ["push"]

jobs:
build:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@master"
- name: "TODO to Issue"
uses: "alstr/[email protected]"
id: "todoV100"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
.gradle/
*.iml
*.DS_Store
*.bin
*.lock

# IntelliJ
out/
Expand Down
Binary file not shown.
Empty file.
Binary file removed .gradle/7.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file removed .gradle/7.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file removed .gradle/7.1/fileChanges/last-build.bin
Binary file not shown.
Binary file removed .gradle/7.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file removed .gradle/7.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file removed .gradle/7.1/fileHashes/resourceHashesCache.bin
Binary file not shown.
Empty file removed .gradle/7.1/gc.properties
Empty file.
Binary file removed .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 0 additions & 2 deletions .gradle/buildOutputCleanup/cache.properties

This file was deleted.

Binary file removed .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file removed .gradle/checksums/checksums.lock
Binary file not shown.
Binary file removed .gradle/checksums/md5-checksums.bin
Binary file not shown.
Binary file removed .gradle/checksums/sha1-checksums.bin
Binary file not shown.
Empty file removed .gradle/vcs-1/gc.properties
Empty file.
23 changes: 23 additions & 0 deletions .run/Discord_Bot_Foundation [shadowJar].run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Discord_Bot_Foundation [shadowJar]" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="shadowJar" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package com.greazi.discordbotfoundation.command;
/*
* Copyright (c) 2021 - 2022. Greazi - All rights reservered
*
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
*/

package com.greazi.discordbotfoundation.modal;


import com.greazi.discordbotfoundation.SimpleBot;
import com.greazi.discordbotfoundation.command.SimpleSlashCommand;
import com.greazi.discordbotfoundation.command.SlashCommandHandler;
import com.greazi.discordbotfoundation.debug.Debugger;
import com.greazi.discordbotfoundation.settings.SimpleSettings;
import com.greazi.discordbotfoundation.utils.SimpleEmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.hooks.SubscribeEvent;
import net.dv8tion.jda.api.interactions.commands.build.*;
import net.dv8tion.jda.api.interactions.commands.privileges.CommandPrivilege;
Expand All @@ -16,70 +25,69 @@
import java.util.List;
import java.util.Objects;

public class SlashCommandHandler extends ListenerAdapter {
public class ModalHandler {

private final HashMap<String, SimpleSlashCommand> cmdList = new HashMap<>();
private final List<SlashCommandData> slashCommands = new ArrayList<>();

public SlashCommandHandler(){
Debugger.debug("SlashCommandHandler", "SlashCommandHandler main method");
public SlashCommandHandler() {
Debugger.debug("ModalHandler", "ModalHandler main method");
SimpleBot.getJDA().addEventListener(this);
}

public SlashCommandHandler addCommand(SimpleSlashCommand module) {
Debugger.debug("SlashCommandHandler", "Start of addCommand(...);27");
Debugger.debug("ModalHandler", "Start of addCommand(...);27");

SlashCommandData command = Commands.slash(module.getCommand(), module.getDescription());
Debugger.debug("SlashCommandHandler", "Retrieved SlashCommandData; " + module.getCommand() + ", " + module.getDescription());
Debugger.debug("ModalHandler", "Retrieved SlashCommandData; " + module.getCommand() + ", " + module.getDescription());

Debugger.debug("SlashCommandHandler", " Retrieving subcommands for; " + module.getCommand());
Debugger.debug("ModalHandler", " Retrieving subcommands for; " + module.getCommand());
List<SubcommandData> moduleSubcommands = module.getSubCommands();
for (SubcommandData var : moduleSubcommands) {
command.addSubcommands(var);
Debugger.debug("SlashCommandHandler", " - " + var);
Debugger.debug("ModalHandler", " - " + var);
}

Debugger.debug("SlashCommandHandler", " Retrieving subcommand groups for; " + module.getCommand());
Debugger.debug("ModalHandler", " Retrieving subcommand groups for; " + module.getCommand());
List<SubcommandGroupData> moduleSubcommandGroup = module.getSubcommandGroup();
for (SubcommandGroupData var : moduleSubcommandGroup) {
command.addSubcommandGroups(var);
Debugger.debug("SlashCommandHandler", " - " + var);
Debugger.debug("ModalHandler", " - " + var);
}

Debugger.debug("SlashCommandHandler", " Checking if subcommands exists for; " + module.getCommand());
if (!module.getSubCommands().isEmpty() || !module.getSubcommandGroup().isEmpty()){
Debugger.debug("SlashCommandHandler", " No subcommands getting options;");
Debugger.debug("ModalHandler", " Checking if subcommands exists for; " + module.getCommand());
if (module.getSubCommands().isEmpty() && module.getSubcommandGroup().isEmpty() && !module.getOptions().isEmpty()) {
Debugger.debug("ModalHandler", " No subcommands getting options;");
List<OptionData> moduleOptions = module.getOptions();
for (OptionData var : moduleOptions) {
command.addOptions(var);
Debugger.debug("SlashCommandHandler", " - " + var);
Debugger.debug("ModalHandler", " - " + var);
}
}
Debugger.debug("SlashCommandHandler", " Setting other info;",
Debugger.debug("ModalHandler", " Setting other info;",
" Default enabled; " + module.getDefaultEnabled(),
" Description; " + module.getDescription());
command.setDefaultEnabled(module.getDefaultEnabled());
command.setDescription(module.getDescription());

Debugger.debug("SlashCommandHandler", " Adding the whole command; " + command.getName());
Debugger.debug("ModalHandler", " Adding the whole command; " + command.getName());
slashCommands.add(command);
cmdList.put(module.getCommand(), module);

return this;
}

public void registerCommands() {
Debugger.debug("SlashCommandHandler", "Start of registerCommands()");
Debugger.debug("ModalHandler", "Start of registerCommands()");
if (slashCommands.isEmpty()) return;

SimpleBot.getGuild().updateCommands()
.addCommands(slashCommands)
.queue(commands -> {
commands.forEach(cmd -> {
Debugger.debug("SlashCommandHandler", " Getting command from cmdList " + cmd.getName());
Debugger.debug("ModalHandler", " Getting command from cmdList " + cmd.getName());
SimpleSlashCommand module = cmdList.get(cmd.getName());

Debugger.debug("SlashCommandHandler", " Adding privilages to " + cmd.getName());
Debugger.debug("ModalHandler", " Adding privilages to " + cmd.getName());
List<CommandPrivilege> commandPrivileges = new ArrayList<>();
module.getDisabledRoles().forEach(role -> commandPrivileges.add(CommandPrivilege.disableRole(role.getId())));
module.getDisabledUsers().forEach(user -> commandPrivileges.add(CommandPrivilege.disableUser(user.getId())));
Expand All @@ -95,7 +103,7 @@ public void registerCommands() {
@Override
@SubscribeEvent
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
Debugger.debug("SlashCommandHandler", "A slash command event has been triggered onSlashCommandInteraction(...);96");
Debugger.debug("ModalHandler", "A slash command event has been triggered onSlashCommandInteraction(...);96");
// Retrieve the command class from the command that has been run
SimpleSlashCommand module = cmdList.get(event.getName());

Expand All @@ -109,17 +117,17 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent even
return;
}

Debugger.debug("SlashCommandHandler", " Found event; " + module);
Debugger.debug("ModalHandler", " Found event; " + module);

if (module.getGuildOnly() && !Objects.requireNonNull(event.getGuild()).getId().equals(SimpleSettings.getInstance().getMainGuild())){
if (module.getGuildOnly() && !Objects.requireNonNull(event.getGuild()).getId().equals(SimpleSettings.getInstance().getMainGuild())) {
return;
}

if (event.getTextChannel().isNSFW() && !module.getNsfwOnly()){
if (event.getTextChannel().isNSFW() && !module.getNsfwOnly()) {
return;
}

Debugger.debug("SlashCommandHandler", " Executing command logic");
Debugger.debug("ModalHandler", " Executing command logic");
module.execute(event);
}
}
}
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apply plugin: 'com.github.johnrengelman.shadow'
compileJava.options.encoding = 'UTF-8'

assemble.dependsOn shadowJar
version '2.0.0'

repositories {
mavenLocal()
Expand All @@ -15,7 +16,7 @@ repositories {
}

dependencies {
implementation ('net.dv8tion:JDA:5.0.0-alpha.9') { exclude module: 'opus-java' }
implementation ('net.dv8tion:JDA:5.0.0-alpha.11') { exclude module: 'opus-java' }

implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'org.apache.commons:commons-text:1.9'
Expand Down
4 changes: 2 additions & 2 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ set JAVA_EXE=java.exe
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' simpleCommand could be found in your PATH.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
Expand All @@ -65,7 +65,7 @@ echo location of your Java installation.
goto fail

:execute
@rem Setup the simpleCommand line
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

Expand Down
41 changes: 25 additions & 16 deletions src/main/java/com/greazi/discordbotfoundation/Common.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.greazi.discordbotfoundation;

import com.greazi.discordbotfoundation.debug.FoException;
import com.greazi.discordbotfoundation.utils.color.ConsoleColor;
import com.greazi.discordbotfoundation.utils.time.TimeUtil;
import com.greazi.discordbotfoundation.utils.color.Color;
import lombok.Getter;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.List;

/**
* This class holds some pre-made log and message send modules
Expand Down Expand Up @@ -35,7 +38,7 @@ public final class Common {
* The log prefix applied on log() methods
*/
@Getter
private static String logPrefix = "[" + SimpleBot.getName() + "]";
private static String logPrefix = "[INFO]";

/**
* Set the log prefix applied for messages in the console from log() methods.
Expand Down Expand Up @@ -112,7 +115,7 @@ public static void logTimed(final int delaySec, final String msg) {
* @param message
*/
public static void success(String message) {
log(Color.GREEN + "Success: " + message);
logNoPrefix(ConsoleColor.GREEN + "[SUCCESS] " + message);
}

/**
Expand All @@ -122,7 +125,7 @@ public static void success(String message) {
* @param message
*/
public static void warning(String message) {
log(Color.YELLOW + "Warning: " + message);
logNoPrefix(ConsoleColor.RED + "[WARNING] " + message);
}

/**
Expand Down Expand Up @@ -166,9 +169,15 @@ private static void log(final boolean addLogPrefix, final String... messages) {
continue;

for (final String part : splitNewline(message)) {
final String log = ((addLogPrefix && ADD_LOG_PREFIX ? logPrefix + " " : "") + part.replace("\n", "\n&r")).trim();

System.out.println(log);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalTime localTime = LocalTime.now();

if(addLogPrefix && ADD_LOG_PREFIX){
System.out.println(ConsoleColor.BLACK_BRIGHT + dtf.format(localTime) + ConsoleColor.BLACK_BRIGHT + " " + ConsoleColor.GREEN + logPrefix + ConsoleColor.RESET + " " + part + ConsoleColor.RESET);
} else {
System.out.println(ConsoleColor.BLACK_BRIGHT + dtf.format(localTime) + ConsoleColor.BLACK_BRIGHT + " " + ConsoleColor.RESET + part + ConsoleColor.RESET);
}
}
}
}
Expand All @@ -185,18 +194,18 @@ public static void logFramed(final String... messages) {
/**
* Logs a bunch of messages to the console in a {@link #consoleLine()} frame.
* <p>
* Used when an error occurs, can also disable the plugin
* Used when an error occurs, can also disable the bot
*
* @param disablePlugin
* @param disableBot
* @param messages
*/
public static void logFramed(final boolean disablePlugin, final String... messages) {
public static void logFramed(final boolean disableBot, final String... messages) {
if (messages != null && !Valid.isNullOrEmpty(messages)) {
log("&7" + consoleLine());
logNoPrefix(ConsoleColor.BLACK_BRIGHT + consoleLine());
for (final String msg : messages)
log(" &c" + msg);
logNoPrefix(msg + ConsoleColor.RESET);

log("&7" + consoleLine());
logNoPrefix(ConsoleColor.BLACK_BRIGHT + consoleLine());
}
}

Expand All @@ -207,7 +216,7 @@ public static void logFramed(final boolean disablePlugin, final String... messag
* @param messages
*/
public static void error(final String... messages) {
logFramed(Color.RED + messages);
logFramed(ConsoleColor.RED + Arrays.toString(messages) + ConsoleColor.RESET);
}

/**
Expand Down Expand Up @@ -244,8 +253,8 @@ private static String[] replaceErrorVariable(Throwable throwable, final String..
while (throwable.getCause() != null)
throwable = throwable.getCause();

final String throwableName = throwable == null ? "Unknown error." : throwable.getClass().getSimpleName();
final String throwableMessage = throwable == null || throwable.getMessage() == null || throwable.getMessage().isEmpty() ? "" : ": " + throwable.getMessage();
final String throwableName = throwable.getClass().getSimpleName();
final String throwableMessage = throwable.getMessage() == null || throwable.getMessage().isEmpty() ? "" : ": " + throwable.getMessage();

for (int i = 0; i < msgs.length; i++) {
final String error = throwableName + throwableMessage;
Expand Down Expand Up @@ -395,7 +404,7 @@ public static String[] splitNewline(final String message) {
}

/**
* A wrapper for Spigot
* A wrapper for sneaky error's
*/
class SneakyThrow {

Expand Down
Loading

0 comments on commit 887ad72

Please sign in to comment.