diff --git a/src/main/java/github/io/koala3353/Config.java b/src/main/java/github/io/koala3353/Config.java new file mode 100644 index 0000000..4b39b28 --- /dev/null +++ b/src/main/java/github/io/koala3353/Config.java @@ -0,0 +1,17 @@ +package github.io.koala3353; + +import io.github.cdimascio.dotenv.Dotenv; + +public class Config { + // Simple Config getter (.env file) + private static final Dotenv dotenv = Dotenv.load(); + + public static String get(String key) { + return dotenv.get(key.toUpperCase()); + } + public static long getLong(String key) { + String config = dotenv.get(key.toUpperCase()); + if (config == null) return 0L; + return Long.parseLong(config); + } +} \ No newline at end of file diff --git a/src/main/java/github/io/koala3353/Main.java b/src/main/java/github/io/koala3353/Main.java new file mode 100644 index 0000000..1af31c6 --- /dev/null +++ b/src/main/java/github/io/koala3353/Main.java @@ -0,0 +1,19 @@ +package github.io.koala3353; + +import github.io.koala3353.bot.Bot; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Main { + private static final Logger LOGGER = LoggerFactory.getLogger(Bot.class); + + public static void main(String[] args) { + LOGGER.info("Starting program...."); + try { + new Bot(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + LOGGER.info("Program started successfully!"); + } +} \ No newline at end of file diff --git a/src/main/java/github/io/koala3353/bot/Bot.java b/src/main/java/github/io/koala3353/bot/Bot.java new file mode 100644 index 0000000..a4a44b9 --- /dev/null +++ b/src/main/java/github/io/koala3353/bot/Bot.java @@ -0,0 +1,57 @@ +package github.io.koala3353.bot; + +import com.jagrosh.jdautilities.command.CommandClient; +import com.jagrosh.jdautilities.command.CommandClientBuilder; +import com.jagrosh.jdautilities.command.SlashCommand; +import com.jagrosh.jdautilities.commons.waiter.EventWaiter; +import github.io.koala3353.Config; +import github.io.koala3353.bot.commands.AboutCommand; +import github.io.koala3353.bot.commands.TradeCommand; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.JDABuilder; +import net.dv8tion.jda.api.OnlineStatus; +import net.dv8tion.jda.api.entities.Activity; +import net.dv8tion.jda.api.requests.GatewayIntent; +import net.dv8tion.jda.api.utils.ChunkingFilter; +import net.dv8tion.jda.api.utils.MemberCachePolicy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Bot { + private static final Logger LOGGER = LoggerFactory.getLogger(Bot.class); + + public Bot() throws InterruptedException { + // Initialize the waiter and client + CommandClientBuilder client = new CommandClientBuilder(); + // Set the client settings + client.setOwnerId(Config.get("owner_id")); + client.setStatus(OnlineStatus.ONLINE); + client.setActivity(Activity.listening("for loopholes")); + addCommands(client); + EventWaiter eventWaiter = new EventWaiter(); + // Finalize the command client + CommandClient commandClient = client.build(); + + JDABuilder.createDefault(Config.get("token"), + GatewayIntent.GUILD_MEMBERS, + GatewayIntent.GUILD_MESSAGES, + GatewayIntent.GUILD_MESSAGE_REACTIONS, + GatewayIntent.DIRECT_MESSAGES, + GatewayIntent.MESSAGE_CONTENT, + GatewayIntent.GUILD_PRESENCES, + GatewayIntent.GUILD_EMOJIS_AND_STICKERS, + GatewayIntent.SCHEDULED_EVENTS, + GatewayIntent.GUILD_VOICE_STATES) + .addEventListeners(eventWaiter, commandClient) + .setChunkingFilter(ChunkingFilter.ALL) // enable member chunking for all guilds + .setMemberCachePolicy(MemberCachePolicy.ALL) + .build().awaitReady(); + } + private static void addCommands(CommandClientBuilder clientBuilder) { + // Initialize the commands of the bot + clientBuilder.addSlashCommands(new TradeCommand(), new AboutCommand()); + LOGGER.info("Added the slash commands"); + clientBuilder.addContextMenus(); + LOGGER.info("Added the context menus"); + } +} diff --git a/src/main/java/github/io/koala3353/bot/commands/AboutCommand.java b/src/main/java/github/io/koala3353/bot/commands/AboutCommand.java new file mode 100644 index 0000000..5bf8467 --- /dev/null +++ b/src/main/java/github/io/koala3353/bot/commands/AboutCommand.java @@ -0,0 +1,24 @@ +package github.io.koala3353.bot.commands; + +import com.jagrosh.jdautilities.command.SlashCommand; +import com.jagrosh.jdautilities.command.SlashCommandEvent; +import net.dv8tion.jda.api.EmbedBuilder; + +import java.awt.*; + +public class AboutCommand extends SlashCommand { + public AboutCommand() { + this.name = "about"; + this.help = "Get information about the bot"; + } + + @Override + protected void execute(SlashCommandEvent event) { + EmbedBuilder aboutEmbed = new EmbedBuilder(); + aboutEmbed.setTitle("About the bot"); + aboutEmbed.setDescription("This bot is a simple bot created by Koala3353"); + aboutEmbed.setColor(Color.decode("#2A2E75")); + + event.reply("This bot is a simple bot created by Koala3353").queue(); + } +} diff --git a/src/main/java/github/io/koala3353/bot/commands/HelpCommand.java b/src/main/java/github/io/koala3353/bot/commands/HelpCommand.java new file mode 100644 index 0000000..8b4ad24 --- /dev/null +++ b/src/main/java/github/io/koala3353/bot/commands/HelpCommand.java @@ -0,0 +1,4 @@ +package github.io.koala3353.bot.commands; + +public class HelpCommand { +} diff --git a/src/main/java/github/io/koala3353/bot/commands/ProfileCommand.java b/src/main/java/github/io/koala3353/bot/commands/ProfileCommand.java new file mode 100644 index 0000000..eaf2e27 --- /dev/null +++ b/src/main/java/github/io/koala3353/bot/commands/ProfileCommand.java @@ -0,0 +1,4 @@ +package github.io.koala3353.bot.commands; + +public class ProfileCommand { +} diff --git a/src/main/java/github/io/koala3353/bot/commands/ShopCommand.java b/src/main/java/github/io/koala3353/bot/commands/ShopCommand.java new file mode 100644 index 0000000..1c43a58 --- /dev/null +++ b/src/main/java/github/io/koala3353/bot/commands/ShopCommand.java @@ -0,0 +1,4 @@ +package github.io.koala3353.bot.commands; + +public class ShopCommand { +} diff --git a/src/main/java/github/io/koala3353/bot/commands/StartAdventureCommand.java b/src/main/java/github/io/koala3353/bot/commands/StartAdventureCommand.java new file mode 100644 index 0000000..8cd5578 --- /dev/null +++ b/src/main/java/github/io/koala3353/bot/commands/StartAdventureCommand.java @@ -0,0 +1,4 @@ +package github.io.koala3353.bot.commands; + +public class StartAdventureCommand { +} diff --git a/src/main/java/github/io/koala3353/bot/commands/TradeCommand.java b/src/main/java/github/io/koala3353/bot/commands/TradeCommand.java new file mode 100644 index 0000000..4b6089e --- /dev/null +++ b/src/main/java/github/io/koala3353/bot/commands/TradeCommand.java @@ -0,0 +1,16 @@ +package github.io.koala3353.bot.commands; + +import com.jagrosh.jdautilities.command.SlashCommand; +import com.jagrosh.jdautilities.command.SlashCommandEvent; + +public class TradeCommand extends SlashCommand { + public TradeCommand() { + this.name = "trade"; + this.help = "Trade with another player"; + } + + @Override + protected void execute(SlashCommandEvent event) { + event.reply("Trade command is not implemented yet!").queue(); + } +} diff --git a/src/main/java/github/io/koala3353/bot/commands/ViewInventoryCommand.java b/src/main/java/github/io/koala3353/bot/commands/ViewInventoryCommand.java new file mode 100644 index 0000000..99cf102 --- /dev/null +++ b/src/main/java/github/io/koala3353/bot/commands/ViewInventoryCommand.java @@ -0,0 +1,4 @@ +package github.io.koala3353.bot.commands; + +public class ViewInventoryCommand { +} diff --git a/src/main/java/github/io/koala3353/bot/events/ButtonEvent.java b/src/main/java/github/io/koala3353/bot/events/ButtonEvent.java new file mode 100644 index 0000000..8237309 --- /dev/null +++ b/src/main/java/github/io/koala3353/bot/events/ButtonEvent.java @@ -0,0 +1,11 @@ +package github.io.koala3353.bot.events; + +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; + +public class ButtonEvent extends ListenerAdapter { + @Override + public void onButtonInteraction(ButtonInteractionEvent event) { + //code + } +} diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..19781cf --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} %boldCyan(%-34.-34thread) %red(%10.10X{jda.shard}) %boldGreen(%-15.-15logger{0}) %highlight(%-6level) %msg%n + + + + + + + + \ No newline at end of file