diff --git a/.gitignore b/.gitignore
index 87d4436..c9edc33 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,8 @@
+# Project-specific stuff
+
+src/main/resources/configuration.json
+
+
# User-specific stuff
.idea/
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..e9b77b7
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,11 @@
+# Contributing
+
+I'm more than happy for people to contribute.
+I'm following git-flow for the purposes of this project. If you have maintainer access please create a new branch with a name which indicates the purpose of the branch, i.e what it implements. Then proceed to create a pull request based on the develop branch, if it doesn't exist create the develop branch first.
+
+Delete your branches once they're merged into master.
+
+For external contributors, fork the repository and follow the same principals, create a new branch, new PR based on develop, etc etc. I'll get to it when I can.
+
+## Hacktoberfest 2020
+This project was developed during Hacktoberfest 2020. We welcome participants to contribute, as it will count towards for PR count.
\ No newline at end of file
diff --git a/README.md b/README.md
index b792bdb..ff9e4c0 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,9 @@
# TCD-Discord-Bot
+
+Hacktoberfest project 2020
+
+For the Trinity Class of '24' Discord.
+https://discord.gg/9PuBCaD
+
+In order to deploy this yourself, you have to rename `configuration.json.example` to `configuration.json` and add a token aquired from the [developers portal](https://discord.com/developers)
+
diff --git a/pom.xml b/pom.xml
index 36d8fc4..934ca6f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,6 +8,62 @@
tcd-bot
0.1.0-SNAPSHOT
+
+
+ jcenter
+ jcenter-bintray
+ https://jcenter.bintray.com
+
+
+
+ jitpack.io
+ https://jitpack.io
+
+
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+
+ com.google.code.gson
+ gson
+ 2.8.6
+
+
+
+ org.slf4j
+ slf4j-simple
+ 1.7.21
+ compile
+
+
+
+ net.dv8tion
+ JDA
+ 4.2.0_184
+
+
+ club.minnced
+ opus-java
+
+
+ compile
+
+
+
+ com.jagrosh
+ jda-utilities
+ 3.0.4
+ compile
+ pom
+
+
+
UTF-8
1.8
@@ -18,6 +74,7 @@
org.apache.maven.plugins
maven-compiler-plugin
+ 3.8.1
1.6
1.6
@@ -30,17 +87,21 @@
3.2.4
+ package
shade
- true
+ false
-
- io.paradaux.tcdbot.TCDBot
+
+
+ false
+ ${project.artifactId}
diff --git a/src/main/java/io/paradaux/tcdbot/TCDBot.java b/src/main/java/io/paradaux/tcdbot/TCDBot.java
index 51726ab..3048ab5 100644
--- a/src/main/java/io/paradaux/tcdbot/TCDBot.java
+++ b/src/main/java/io/paradaux/tcdbot/TCDBot.java
@@ -1,9 +1,97 @@
package io.paradaux.tcdbot;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.stream.JsonReader;
+import com.jagrosh.jdautilities.command.CommandClient;
+import com.jagrosh.jdautilities.command.CommandClientBuilder;
+import io.paradaux.tcdbot.api.ConfigurationCache;
+import io.paradaux.tcdbot.api.FileUtils;
+import io.paradaux.tcdbot.listeners.MessageReceivedListener;
+import io.paradaux.tcdbot.listeners.ReadyListener;
+
+import net.dv8tion.jda.api.JDA;
+import net.dv8tion.jda.api.JDABuilder;
+import net.dv8tion.jda.api.utils.cache.CacheFlag;
+import org.jetbrains.annotations.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import sun.security.krb5.Config;
+
+import javax.security.auth.login.LoginException;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+
public class TCDBot {
+ private static Logger logger;
+ public static Logger getLogger() { return logger; }
+
+ private static JDA client;
+
+ private static ConfigurationCache configurationCache;
+ public static ConfigurationCache getConfigurationCache() { return configurationCache; }
+
public static void main(String[] args) {
- System.out.println("Hi");
+ TCDBot bot = new TCDBot();
+ }
+
+ public TCDBot() {
+ logger = LoggerFactory.getLogger(getClass());
+ logger.info("TCDBot is starting.");
+
+ if (!new File("configuration.yml").exists()) {
+ try {
+ FileUtils.ExportResource("configuration.json");
+ } catch (Exception exception) {
+ logger.error("Failed to deploy configuration.\n" + exception.toString());
+ return;
+ }
+
+ }
+
+ try {
+ configurationCache = readConfigurationFile();
+ } catch (FileNotFoundException exception) {
+ logger.error("Cannot find the configuration file.");
+ return;
+ }
+
+ client = login(configurationCache.getToken());
+ }
+
+ @Nullable
+ public JDA login(String token) {
+ JDABuilder builder = JDABuilder.createDefault(token)
+ .disableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE)
+ .setBulkDeleteSplittingEnabled(false)
+ .addEventListeners(new ReadyListener(logger), new MessageReceivedListener(configurationCache));
+
+ if (token == null) {
+ logger.warn("You have not set the token for your discord bot for discord2mc functionality. This has been disabled.");
+ return null;
+ }
+
+ try {
+ return builder.build();
+ } catch(LoginException exception) {
+ logger.warn("TCDBot failed to login with the provided token.");
+ return null;
+ }
}
+ public ConfigurationCache readConfigurationFile() throws FileNotFoundException {
+ GsonBuilder builder = new GsonBuilder();
+ Gson gson = builder.create();
+
+ BufferedReader bufferedReader = new BufferedReader(new FileReader("configuration.json"));
+ return gson.fromJson(bufferedReader, ConfigurationCache.class);
+ }
+
+ public CommandClient createCommandClient() {
+ CommandClientBuilder builder = new CommandClientBuilder();
+ return null;
+ }
}
diff --git a/src/main/java/io/paradaux/tcdbot/api/ConfigurationCache.java b/src/main/java/io/paradaux/tcdbot/api/ConfigurationCache.java
new file mode 100644
index 0000000..5326525
--- /dev/null
+++ b/src/main/java/io/paradaux/tcdbot/api/ConfigurationCache.java
@@ -0,0 +1,47 @@
+package io.paradaux.tcdbot.api;
+
+import java.util.List;
+
+public class ConfigurationCache {
+
+ String token;
+ String prefix;
+ List courseSelectionChannels;
+
+ public ConfigurationCache(String token, String prefix, List courseSelectionChannels) {
+ this.token = token;
+ this.prefix = prefix;
+ this.courseSelectionChannels = courseSelectionChannels;
+ }
+
+ public ConfigurationCache() {}
+
+ public String getToken() {
+ return token;
+ }
+
+ public void setToken(String token) {
+ this.token = token;
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ public List getCourseSelectionChannels() {
+ return courseSelectionChannels;
+ }
+
+ public void setCourseSelectionChannels(List courseSelectionChannels) {
+ this.courseSelectionChannels = courseSelectionChannels;
+ }
+
+ @Override
+ public String toString() {
+ return "ConfigurationCache: [ token: " + token + "]";
+ }
+}
diff --git a/src/main/java/io/paradaux/tcdbot/api/FileUtils.java b/src/main/java/io/paradaux/tcdbot/api/FileUtils.java
new file mode 100644
index 0000000..f27ec77
--- /dev/null
+++ b/src/main/java/io/paradaux/tcdbot/api/FileUtils.java
@@ -0,0 +1,45 @@
+package io.paradaux.tcdbot.api;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class FileUtils {
+
+ /**
+ * Export a resource embedded into a Jar file to the local file path.
+ *
+ * @param resourceName ie.: "/SmartLibrary.dll"
+ * @return The path to the exported resource
+ * @throws Exception
+ */
+ public static String ExportResource(String resourceName) throws Exception {
+ InputStream stream = null;
+ OutputStream resStreamOut = null;
+ String jarFolder;
+ try {
+ stream = FileUtils.class.getResourceAsStream(resourceName);//note that each / is a directory down in the "jar tree" been the jar the root of the tree
+ if(stream == null) {
+ throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file.");
+ }
+
+ int readBytes;
+ byte[] buffer = new byte[4096];
+ jarFolder = new File(FileUtils.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getPath().replace('\\', '/');
+ resStreamOut = new FileOutputStream(jarFolder + resourceName);
+ while ((readBytes = stream.read(buffer)) > 0) {
+ resStreamOut.write(buffer, 0, readBytes);
+ }
+ } catch (Exception ex) {
+ throw ex;
+ } finally {
+ stream.close();
+ resStreamOut.close();
+ }
+
+ return jarFolder + resourceName;
+ }
+
+
+}
diff --git a/src/main/java/io/paradaux/tcdbot/commands/InviteCommand.java b/src/main/java/io/paradaux/tcdbot/commands/InviteCommand.java
new file mode 100644
index 0000000..f3c223d
--- /dev/null
+++ b/src/main/java/io/paradaux/tcdbot/commands/InviteCommand.java
@@ -0,0 +1,18 @@
+package io.paradaux.tcdbot.commands;
+
+import com.jagrosh.jdautilities.command.Command;
+import com.jagrosh.jdautilities.command.CommandEvent;
+
+public class InviteCommand extends Command {
+
+ public InviteCommand(String name, String[] aliases, String help) {
+ this.name = "invite";
+ this.aliases = new String[] {"inv", "i"};
+ this.help = "Gives an invite link.";
+ }
+
+ @Override
+ protected void execute(CommandEvent commandEvent) {
+
+ }
+}
diff --git a/src/main/java/io/paradaux/tcdbot/listeners/MessageReceivedListener.java b/src/main/java/io/paradaux/tcdbot/listeners/MessageReceivedListener.java
new file mode 100644
index 0000000..5cd3f41
--- /dev/null
+++ b/src/main/java/io/paradaux/tcdbot/listeners/MessageReceivedListener.java
@@ -0,0 +1,21 @@
+package io.paradaux.tcdbot.listeners;
+
+import io.paradaux.tcdbot.api.ConfigurationCache;
+import net.dv8tion.jda.api.entities.MessageChannel;
+import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
+import net.dv8tion.jda.api.hooks.ListenerAdapter;
+import org.jetbrains.annotations.NotNull;
+
+public class MessageReceivedListener extends ListenerAdapter {
+
+ ConfigurationCache configurationCache;
+
+ public MessageReceivedListener(ConfigurationCache configurationCache) {
+ this.configurationCache = configurationCache;
+ }
+
+ @Override
+ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
+ MessageChannel channel = event.getMessage().getChannel();
+ }
+}
diff --git a/src/main/java/io/paradaux/tcdbot/listeners/ReadyListener.java b/src/main/java/io/paradaux/tcdbot/listeners/ReadyListener.java
new file mode 100644
index 0000000..e374cb4
--- /dev/null
+++ b/src/main/java/io/paradaux/tcdbot/listeners/ReadyListener.java
@@ -0,0 +1,21 @@
+package io.paradaux.tcdbot.listeners;
+
+import net.dv8tion.jda.api.events.ReadyEvent;
+import net.dv8tion.jda.api.hooks.ListenerAdapter;
+import org.slf4j.Logger;
+
+public class ReadyListener extends ListenerAdapter {
+
+ Logger logger;
+
+ public ReadyListener(Logger logger) {
+ this.logger = logger;
+ }
+
+ @Override
+ public void onReady(ReadyEvent event) {
+ logger.info("TCDBot has logged in successfully.");
+ logger.info("Serving " + event.getGuildTotalCount() + " guilds.");
+ }
+
+}
diff --git a/src/main/resources/configuration.json.example b/src/main/resources/configuration.json.example
new file mode 100644
index 0000000..ff93a17
--- /dev/null
+++ b/src/main/resources/configuration.json.example
@@ -0,0 +1,5 @@
+{
+ "token": "NzYyMzrthMrthwMjQ2OTc1r0MjEz.X3nlXg.DtBrEKhXZ8nvV4rgego6c9VtEtUKw",
+ "prefix": ";",
+ "course-selection-channel": ["730441682817908797", "732213443104604251"]
+}
\ No newline at end of file