Skip to content

Commit

Permalink
chore: Bump push with some minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Greazi-Times committed Jan 24, 2024
1 parent 8770035 commit ad01fdf
Show file tree
Hide file tree
Showing 69 changed files with 328 additions and 6,189 deletions.
Binary file modified Document (4).docx
Binary file not shown.
10 changes: 8 additions & 2 deletions src/main/java/com/greazi/discordbotfoundation/Common.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.greazi.discordbotfoundation;

import com.greazi.discordbotfoundation.debug.BotException;
import com.greazi.discordbotfoundation.settings.SimpleSettings;
import com.greazi.discordbotfoundation.utils.ConsoleColor;
import com.greazi.discordbotfoundation.utils.SimpleEmbedBuilder;
import com.greazi.discordbotfoundation.utils.Valid;
import com.greazi.discordbotfoundation.utils.time.TimeUtil;
import lombok.Getter;
import net.dv8tion.jda.api.entities.User;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -394,7 +400,7 @@ public static void sneaky(final Throwable throwable) {
*/
@Deprecated
public static String[] splitNewline(final String message) {
if (!com.greazi.old.SimpleBot.getInstance().enforceNewLine())
if (!SimpleBot.getInstance().enforceNewLine())
return message.split("\n");

final String delimiter = "GREAZIWASHERE";
Expand Down Expand Up @@ -432,7 +438,7 @@ public static void saveToFile(final String message) {
final LocalDateTime now = LocalDateTime.now();
final String currentDate = dtf.format(now);

final String location = new File(com.greazi.old.SimpleBot.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getPath();
final String location = new File(SimpleBot.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getPath();


// Get the location of the .jar file
Expand Down
56 changes: 50 additions & 6 deletions src/main/java/com/greazi/discordbotfoundation/SimpleBot.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,62 @@
package com.greazi.discordbotfoundation;

import com.greazi.discordbotfoundation.command.PingCommand;
import com.greazi.discordbotfoundation.command.SimpleCommand;
import com.greazi.discordbotfoundation.command.SlashCommandHandler;
import com.greazi.discordbotfoundation.constants.Constants;
import com.greazi.discordbotfoundation.debug.BotException;
import com.greazi.discordbotfoundation.mysql.SqlManager;
import com.greazi.discordbotfoundation.settings.SimpleSettings;
import com.greazi.old.mysql.SqlManager;
import lombok.Getter;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.SelfUser;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.hooks.AnnotatedEventManager;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.ChunkingFilter;
import net.dv8tion.jda.api.utils.MemberCachePolicy;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import org.jetbrains.annotations.NotNull;

public abstract class SimpleBot {

/**
* The JDA instance
*/
@Getter
private static JDA jda;

/**
* The instance of the bot
*/
@Getter
private static volatile SimpleBot instance;

/**
* The main guild of the bot
*/
@Getter
private static Guild mainGuild;

/**
* The bot itself as a user
*/
@Getter
private static SelfUser selfUser;

/**
* If the bot is enabled or not
*/
@Getter
private boolean enabled;

/**
* The SQL manager
*/
@Getter
private static SqlManager sqlManager;

// ----------------------------------------------------------------------------------------
Expand All @@ -65,12 +77,20 @@ public static boolean hasInstance() {
// Main methods
// ----------------------------------------------------------------------------------------

public static void main(final String[] args) {
new SimpleBot() {
@Override
protected void onBotStart() {

}
};
}

/**
* The main method that starts the bot
* <p>
* A Discord bot needs the {@link #registerJda(String, Activity)} method to register.
* Before the bot registers it will set some things up and than register the bot to ensure
* a function Discord bot.
* Registering the discord bot to Discord and starting up all
* managers.
*/
public SimpleBot() {
this.enabled = false;
Expand Down Expand Up @@ -124,7 +144,7 @@ public SimpleBot() {
// Registering the bot to Discord using JDA
log("Registering the bot to Discord");
try {
jda = JDABuilder.createDefault("SETTINGS TOKEN HERE")
jda = JDABuilder.createDefault(SimpleSettings.Bot.Token())
.setEnabledIntents(GatewayIntent.getIntents(GatewayIntent.DEFAULT | GatewayIntent.GUILD_MEMBERS.getRawValue() | GatewayIntent.GUILD_BANS.getRawValue()))
.setDisabledIntents(GatewayIntent.DIRECT_MESSAGE_TYPING, GatewayIntent.GUILD_MESSAGE_TYPING)
.disableCache(CacheFlag.ACTIVITY, CacheFlag.VOICE_STATE, CacheFlag.ONLINE_STATUS)
Expand All @@ -140,7 +160,7 @@ public SimpleBot() {
}

// Setting the selfUser
this.selfUser = jda.getSelfUser();
selfUser = jda.getSelfUser();

// Set the main guild
setMainGuild();
Expand All @@ -151,12 +171,26 @@ public SimpleBot() {
// Call the onBotLoad method
onBotLoad();

// Register the ping command
SimpleCommand.register(new PingCommand());

// Call the onBotStart method
onBotStart();

// Call the onReloadableStart method
onReloadableStart();

SimpleCommand.registerAll();

getJda().addEventListener(new SlashCommandHandler() {
@Override
protected void execute(@NotNull final SlashCommandInteractionEvent event) {

}
});

getJda().addEventListener(new PingCommand());

// Set the enabled to true
this.enabled = true;

Expand Down Expand Up @@ -220,6 +254,16 @@ private static void error(final String... messages) {
Common.error(messages);
}

/**
* Should every message be divided by \n by an own method (tends to work more
* than split("\n"))
*
* @return If the system need to force a new line with \n
*/
public boolean enforceNewLine() {
return false;
}

// ----------------------------------------------------------------------------------------
// Delegate methods
// ----------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit ad01fdf

Please sign in to comment.