Initial Commit
This commit is contained in:
commit
4c67eff7ee
82
.gitignore
vendored
Normal file
82
.gitignore
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
# Created by https://www.gitignore.io/api/maven,intellij+iml
|
||||
|
||||
### Intellij+iml ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# CMake
|
||||
cmake-build-debug/
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
#dependencies
|
||||
/jars/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Ruby plugin and RubyMine
|
||||
/.rakeTasks
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
### Intellij+iml Patch ###
|
||||
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||
|
||||
*.iml
|
||||
modules.xml
|
||||
.idea/misc.xml
|
||||
*.ipr
|
||||
|
||||
### Maven ###
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
|
||||
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
|
||||
!/.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
# End of https://www.gitignore.io/api/maven,intellij+iml
|
16
.idea/compiler.xml
Normal file
16
.idea/compiler.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="Rixa" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel>
|
||||
<module name="Rixa" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
112
pom.xml
Normal file
112
pom.xml
Normal file
@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>io.rixa</groupId>
|
||||
<artifactId>Rixa</artifactId>
|
||||
<version>3.0-SNAPSHOT</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jcenter</id>
|
||||
<name>jcenter-bintray</name>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.18</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.name}-Build-${project.version}-SNAPSHOT</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>commons-logging:commons-logging</artifact>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<!-- utterly useless artifact from shade 2.x -->
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
<configuration>
|
||||
<skip>false</skip>
|
||||
<skipTests>false</skipTests>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
52
src/main/java/io/rixa/Rixa.java
Normal file
52
src/main/java/io/rixa/Rixa.java
Normal file
@ -0,0 +1,52 @@
|
||||
package io.rixa;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import io.rixa.data.config.Configuration;
|
||||
import io.rixa.utils.FileUtils;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Rixa {
|
||||
|
||||
private static Rixa instance;
|
||||
@Getter private Configuration configuration;
|
||||
@Getter private ObjectMapper objectMapper;
|
||||
@Getter private File defaultPath;
|
||||
@Getter private Logger logger;
|
||||
|
||||
private Rixa() {
|
||||
instance = this;
|
||||
logger = Logger.getLogger(Rixa.class.getCanonicalName());
|
||||
objectMapper = new ObjectMapper(new YAMLFactory());
|
||||
defaultPath = new File("Rixa");
|
||||
defaultPath.mkdirs();
|
||||
loadConfiguration();
|
||||
registerCommands();
|
||||
}
|
||||
|
||||
private void registerCommands() {}
|
||||
|
||||
private void loadConfiguration() {
|
||||
try {
|
||||
FileUtils.saveResource("config.yml", false);
|
||||
File file = new File(defaultPath.getPath() + "/config.yml");
|
||||
configuration = objectMapper.readValue(file, Configuration.class);
|
||||
logger.info("Configuration successfully loaded.");
|
||||
} catch (IOException e) {
|
||||
logger.severe("Could not properly load configuration file!.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Rixa getInstance() {
|
||||
return (instance == null) ? new Rixa() : instance;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Rixa.getInstance();
|
||||
}
|
||||
}
|
36
src/main/java/io/rixa/commands/Command.java
Normal file
36
src/main/java/io/rixa/commands/Command.java
Normal file
@ -0,0 +1,36 @@
|
||||
package io.rixa.commands;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Command {
|
||||
|
||||
@Getter @Setter private String command, description;
|
||||
@Getter @Setter private RixaPermission permission;
|
||||
@Getter @Setter private List<String> aliases;
|
||||
public Command(String command) {
|
||||
this(command, RixaPermission.NONE, "Undefined", Collections.emptyList());
|
||||
}
|
||||
|
||||
public Command(String command, RixaPermission rixaPermission) {
|
||||
this(command, rixaPermission, "Undefined", Collections.emptyList());
|
||||
}
|
||||
|
||||
public Command(String command, RixaPermission rixaPermission, String description) {
|
||||
this(command, rixaPermission, description, Collections.emptyList());
|
||||
}
|
||||
|
||||
public Command(String command, RixaPermission rixaPermission, String description, List<String> aliases) {
|
||||
setCommand(command);
|
||||
setPermission(rixaPermission);
|
||||
setDescription(description);
|
||||
setAliases(aliases);
|
||||
}
|
||||
|
||||
public abstract boolean execute(GuildMessageReceivedEvent event);
|
||||
}
|
5
src/main/java/io/rixa/commands/RixaPermission.java
Normal file
5
src/main/java/io/rixa/commands/RixaPermission.java
Normal file
@ -0,0 +1,5 @@
|
||||
package io.rixa.commands;
|
||||
|
||||
public enum RixaPermission {
|
||||
NONE;
|
||||
}
|
17
src/main/java/io/rixa/commands/cmds/HelpCommand.java
Normal file
17
src/main/java/io/rixa/commands/cmds/HelpCommand.java
Normal file
@ -0,0 +1,17 @@
|
||||
package io.rixa.commands.cmds;
|
||||
|
||||
import io.rixa.commands.Command;
|
||||
import io.rixa.commands.RixaPermission;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
|
||||
public class HelpCommand extends Command {
|
||||
|
||||
public HelpCommand(String command, RixaPermission rixaPermission, String description) {
|
||||
super(command, rixaPermission, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(GuildMessageReceivedEvent event) {
|
||||
return false;
|
||||
}
|
||||
}
|
4
src/main/java/io/rixa/data/DataStorage.java
Normal file
4
src/main/java/io/rixa/data/DataStorage.java
Normal file
@ -0,0 +1,4 @@
|
||||
package io.rixa.data;
|
||||
|
||||
public interface DataStorage {
|
||||
}
|
16
src/main/java/io/rixa/data/config/Configuration.java
Normal file
16
src/main/java/io/rixa/data/config/Configuration.java
Normal file
@ -0,0 +1,16 @@
|
||||
package io.rixa.data.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Configuration {
|
||||
|
||||
@Getter @Setter private String token, botGame;
|
||||
@Getter @Setter private List<String> botAdmins;
|
||||
@Getter @Setter private Map<String, String> sqlCredentials;
|
||||
|
||||
public Configuration() {}
|
||||
}
|
6
src/main/java/io/rixa/data/storage/MySQLStorage.java
Normal file
6
src/main/java/io/rixa/data/storage/MySQLStorage.java
Normal file
@ -0,0 +1,6 @@
|
||||
package io.rixa.data.storage;
|
||||
|
||||
import io.rixa.data.DataStorage;
|
||||
|
||||
public class MySQLStorage implements DataStorage {
|
||||
}
|
13
src/main/java/io/rixa/guild/IGuild.java
Normal file
13
src/main/java/io/rixa/guild/IGuild.java
Normal file
@ -0,0 +1,13 @@
|
||||
package io.rixa.guild;
|
||||
|
||||
import io.rixa.guild.modules.RixaModule;
|
||||
|
||||
public interface IGuild {
|
||||
|
||||
String getId();
|
||||
void load();
|
||||
void save();
|
||||
RixaModule getModule(String id);
|
||||
RixaModule registerModule(String id, RixaModule module);
|
||||
boolean isRegistered(String id);
|
||||
}
|
42
src/main/java/io/rixa/guild/RixaGuild.java
Normal file
42
src/main/java/io/rixa/guild/RixaGuild.java
Normal file
@ -0,0 +1,42 @@
|
||||
package io.rixa.guild;
|
||||
|
||||
import io.rixa.guild.modules.RixaModule;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class RixaGuild implements IGuild {
|
||||
|
||||
@Getter private final String id;
|
||||
@Getter private final Map<String, RixaModule> modules;
|
||||
|
||||
public RixaGuild(Guild guild) {
|
||||
id = guild.getId();
|
||||
modules = new HashMap<>();
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() { }
|
||||
|
||||
@Override
|
||||
public void save() { }
|
||||
|
||||
@Override
|
||||
public RixaModule getModule(String id) {
|
||||
return modules.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RixaModule registerModule(String id, RixaModule module) {
|
||||
if (!(isRegistered(id))) modules.put(id, module);
|
||||
return module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegistered(String id) {
|
||||
return modules.containsKey(id);
|
||||
}
|
||||
}
|
9
src/main/java/io/rixa/guild/modules/RixaModule.java
Normal file
9
src/main/java/io/rixa/guild/modules/RixaModule.java
Normal file
@ -0,0 +1,9 @@
|
||||
package io.rixa.guild.modules;
|
||||
|
||||
public interface RixaModule {
|
||||
|
||||
String getName();
|
||||
String getDescription();
|
||||
void load();
|
||||
void save();
|
||||
}
|
25
src/main/java/io/rixa/guild/modules/module/LevelsModule.java
Normal file
25
src/main/java/io/rixa/guild/modules/module/LevelsModule.java
Normal file
@ -0,0 +1,25 @@
|
||||
package io.rixa.guild.modules.module;
|
||||
|
||||
import io.rixa.guild.modules.RixaModule;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class LevelsModule implements RixaModule {
|
||||
|
||||
@Getter @Setter private String name, description;
|
||||
|
||||
public LevelsModule(String name, String description) {
|
||||
setName(name);
|
||||
setDescription(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
|
||||
}
|
||||
}
|
62
src/main/java/io/rixa/utils/FileUtils.java
Normal file
62
src/main/java/io/rixa/utils/FileUtils.java
Normal file
@ -0,0 +1,62 @@
|
||||
package io.rixa.utils;
|
||||
|
||||
import io.rixa.Rixa;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
/*
|
||||
Method borrowed from https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/plugin/java/JavaPlugin.java
|
||||
*/
|
||||
public static void saveResource(String resourcePath, boolean replace) throws IOException{
|
||||
if (resourcePath == null || resourcePath.equals("")) {
|
||||
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
|
||||
}
|
||||
|
||||
resourcePath = resourcePath.replace('\\', '/');
|
||||
InputStream in = getResource(resourcePath);
|
||||
if (in == null) {
|
||||
throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + "file");
|
||||
}
|
||||
|
||||
File outFile = new File(Rixa.getInstance().getDefaultPath(), resourcePath);
|
||||
int lastIndex = resourcePath.lastIndexOf('/');
|
||||
File outDir = new File(Rixa.getInstance().getDefaultPath(), resourcePath.substring(0, lastIndex >= 0 ? lastIndex : 0));
|
||||
|
||||
if (!outDir.exists()) {
|
||||
outDir.mkdirs();
|
||||
}
|
||||
|
||||
if (!outFile.exists() || replace) {
|
||||
OutputStream out = new FileOutputStream(outFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
} else {
|
||||
System.out.println("Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Method borrowed from https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/plugin/java/JavaPlugin.java
|
||||
*/
|
||||
public static InputStream getResource(String filename) throws IOException {
|
||||
if (filename == null) {
|
||||
throw new IllegalArgumentException("Filename cannot be null");
|
||||
}
|
||||
URL url = FileUtils.class.getClassLoader().getResource(filename);
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.setUseCaches(false);
|
||||
return connection.getInputStream();
|
||||
}
|
||||
}
|
12
src/main/resources/config.yml
Normal file
12
src/main/resources/config.yml
Normal file
@ -0,0 +1,12 @@
|
||||
token: "YOUR_TOKEN_HERE"
|
||||
botGame: "Rixa 2.0 | http://rixa.io/invite"
|
||||
botAdmins:
|
||||
- "YOUR_USER_ID_HERE"
|
||||
- "OTHER_ADMINS"
|
||||
- "REMOVE_IF_YOU_DONT_WANT"
|
||||
sqlCredentials:
|
||||
hostName: "localhost"
|
||||
databaseName: "rixa"
|
||||
userName: "rixa_users"
|
||||
password: "password"
|
||||
port: "3306"
|
Loading…
Reference in New Issue
Block a user