Initial Commit
This commit is contained in:
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"
|
Reference in New Issue
Block a user