Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyMulley committed Jun 10, 2019
0 parents commit fe6760c
Show file tree
Hide file tree
Showing 28 changed files with 1,862 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
LyokoDB.db
58 changes: 58 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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>mulley.sky</groupId>
<artifactId>lyokobot</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<!-- Specify your own main class here: {package}.{class} -->
<mainClass>mulley.sky.lyokobot.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.discord4j</groupId>
<artifactId>Discord4J</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
</project>
44 changes: 44 additions & 0 deletions src/main/java/mulley/sky/lyokobot/Commands/CommandCore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package mulley.sky.lyokobot.Commands;

import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.util.EmbedBuilder;
import sx.blah.discord.util.RequestBuffer;

import java.util.ArrayList;
import java.util.List;

public abstract class CommandCore {
protected String commandName;
protected String helpMessage;
protected String Usage;
protected boolean helpViewable = true;
protected boolean adminOnly = false;
protected boolean serverOwner = false;
protected List<String> commandAliases = new ArrayList<>();

public String getCommandName() {return commandName;}
public String getHelpMessage() {return helpMessage;}
public String getUsage() {return Usage;}
public boolean isHelpViewable() {return helpViewable;}
public boolean isAdminOnly() {return adminOnly;}
public boolean isServerOwner() {return serverOwner;}
public List<String> getAliases() {return commandAliases;}

public void addAlias(String command) {commandAliases.add(command);}

public boolean isAlias(String command) {
if(commandAliases.contains(command)) {
return true;
}
return false;
}

public boolean executeCommand(MessageReceivedEvent event, String[] argArray) {return true;}

public void argsNotFound(MessageReceivedEvent event) {
EmbedBuilder builder = new EmbedBuilder();
builder.withDescription("You haven't supplied the right args in your request. Check with the help command if you are unsure of the usage of this command.");
builder.withFooterText("Not enough args");
RequestBuffer.request(() -> event.getMessage().getChannel().sendMessage(builder.build()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package mulley.sky.lyokobot.Commands.Commands.Administration;

import mulley.sky.lyokobot.Commands.CommandCore;
import mulley.sky.lyokobot.Logic.Objects.Guild;
import mulley.sky.lyokobot.ObjectManager;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IUser;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;

public class Admin extends CommandCore {
public Admin () {
commandName = "Admin";
helpMessage = "Allows Server Owners to change the bot prefix and blacklist users";
Usage = "admin <blacklist/prefix> <newprefix/taggedplayer>";
serverOwner = true;
}

@Override
public boolean executeCommand(MessageReceivedEvent event, String[] argArray) {
Guild guild = ObjectManager.getGuild(event.getGuild().getLongID());
if(argArray.length!=3) { argsNotFound(event);}
if(argArray[1].equalsIgnoreCase("blacklist") || argArray[1].equalsIgnoreCase("prefix")) {
if(argArray[1].equalsIgnoreCase("prefix")) {
if(argArray[2].length()>5) {
event.getChannel().sendMessage("Prefix is too long, please choose one shorter or equal to 5 characters");
return true;
}
guild.setPrefix(argArray[2]);
event.getChannel().sendMessage("Prefix set successfully");
} else {
IUser user = null;
try {
long id = Long.parseLong(argArray[2].replaceAll("\\D+",""));
user = event.getMessage().getClient().getUserByID(id);
} catch(Exception e) {
argsNotFound(event);
return false;
}
if(user.equals(event.getAuthor())) {
event.getChannel().sendMessage("You can't blacklist yourself! You're the Guild Owner!");
return true;
}
if(guild.getBlacklisted().contains(user)) {
guild.removeBlacklist(user);
event.getChannel().sendMessage("User has been removed from the blacklist");
} else {
guild.addBlacklist(user);
event.getChannel().sendMessage("User has been added to the blacklist");
}
}
} else {
argsNotFound(event);
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package mulley.sky.lyokobot.Commands.Commands.Administration;

import com.vdurmont.emoji.Emoji;
import com.vdurmont.emoji.EmojiManager;
import mulley.sky.lyokobot.Commands.CommandCore;
import mulley.sky.lyokobot.Logic.Objects.Guild;
import mulley.sky.lyokobot.Main;
import mulley.sky.lyokobot.ObjectManager;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.obj.IMessage;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;

public class Query extends CommandCore {
public Query () {
commandName = "Query";
helpMessage = "Run a query on the SQL database";
Usage = "query <string>";
adminOnly = true;
helpViewable = false;
}

@Override
public boolean executeCommand(MessageReceivedEvent event, String[] argArray) {
try {
Guild guild = ObjectManager.getGuild(event.getGuild().getLongID());
ResultSet rs = Main.getDbManager().runQuery(event.getMessage().getContent().substring(5 + guild.getPrefix().length()));
event.getMessage().addReaction(EmojiManager.getForAlias("ok"));
ResultSetMetaData rsmd = rs.getMetaData();
int columnsNumber = rsmd.getColumnCount();
String embed = "";
while (rs.next()) {
for (int i = 1; i <= columnsNumber; i++) {
if (i > 1) embed = embed + (", ");
String columnValue = rs.getString(i);
embed = embed + (columnValue + " " + rsmd.getColumnName(i) + "");
}
embed = embed + "\n\n";
}
event.getChannel().sendMessage("```"+embed+"```");
return true;
}catch (Exception e) {
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package mulley.sky.lyokobot.Commands.Commands.LWManagement;

import mulley.sky.lyokobot.Commands.CommandCore;
import mulley.sky.lyokobot.Logic.Runnables.CreateLyokoWarrior;
import mulley.sky.lyokobot.Main;
import mulley.sky.lyokobot.ObjectManager;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;

public class Register extends CommandCore {
public Register () {
commandName = "Register";
helpMessage = "Create your LyokoWarrior to start playing";
Usage = "register";
addAlias("create");
}

@Override
public boolean executeCommand(MessageReceivedEvent event, String[] argArray) {
if(ObjectManager.isLyokoWarrior(event.getAuthor())) {
event.getChannel().sendMessage("You already have an Avatar registered, you can't have multiple!");
return false;
}
if(Main.getObjectManager().isMakingLW(event.getAuthor())) {
event.getChannel().sendMessage("You're already in the process of registering an avatar, check your DM's to finish it off");
return false;
}
Main.getObjectManager().addCLW(new CreateLyokoWarrior(event.getAuthor(),event));
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package mulley.sky.lyokobot.Commands.Commands.LWManagement;

import mulley.sky.lyokobot.Commands.CommandCore;
import mulley.sky.lyokobot.Logic.Objects.LyokoWarrior;
import mulley.sky.lyokobot.Logic.Runnables.ResetLyokoWarrior;
import mulley.sky.lyokobot.Main;
import mulley.sky.lyokobot.ObjectManager;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.util.EmbedBuilder;

public class Reset extends CommandCore {
public Reset() {
commandName = "Reset";
helpMessage = "Reset your Lyoko Warrior so you can create a new one";
Usage = "reset";
addAlias("delete");
}

@Override
public boolean executeCommand(MessageReceivedEvent event, String[] argsArray) {
if(!ObjectManager.isLyokoWarrior(event.getAuthor())) {
event.getChannel().sendMessage("You do not have a LyokoWarrior created, so nothing will be reset!");
return false;
}
if(Main.getObjectManager().isResettingLW(event.getAuthor())) {
event.getChannel().sendMessage("You are already resetting your LyokoWarrior, finish that one first");
return false;
}
LyokoWarrior lyokoWarrior = ObjectManager.getLyokoWarrior(event.getAuthor());
if(lyokoWarrior.getVirtualized()) {
event.getChannel().sendMessage("You're currently virtualized, devirtualize first then run this command again");
return false;
}
EmbedBuilder builder = new EmbedBuilder();
builder.withColor(255,0,0);
builder.withAuthorName("Resetting LyokoWarrior");
builder.withDescription("You are about to reset your Lyoko Warrior, this is a destructive action and it can never be recovered after reset. Reply with the message `CONFIRM` to reset your LyokoWarrior");
builder.appendField("Class",lyokoWarrior.getLWClass().getName(),true);
builder.appendField("Level",""+lyokoWarrior.getLevel(),true);
IMessage message = event.getChannel().sendMessage(builder.build());
Main.getObjectManager().addRLW(new ResetLyokoWarrior(lyokoWarrior,event.getChannel(),event.getClient(),message));
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package mulley.sky.lyokobot.Commands.Commands.LWManagement;

import com.vdurmont.emoji.EmojiManager;
import mulley.sky.lyokobot.Commands.CommandCore;
import mulley.sky.lyokobot.Logic.Objects.LyokoWarrior;
import mulley.sky.lyokobot.ObjectManager;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.util.EmbedBuilder;

public class Upgrade extends CommandCore {
public Upgrade() {
commandName = "Upgrade";
helpMessage = "Use your earned skill points to upgrade your avatar";
Usage = "upgrade (primary/secondary/defense)";
addAlias("shop");
addAlias("buy");
}

@Override
public boolean executeCommand(MessageReceivedEvent event, String[] argsArray) {
if(!ObjectManager.isLyokoWarrior(event.getAuthor())) {
event.getChannel().sendMessage("You do not have a registered LyokoWarrior");
return false;
}
LyokoWarrior warrior = ObjectManager.getLyokoWarrior(event.getAuthor());
if(warrior.getVirtualized()) {
event.getChannel().sendMessage("You are currently virtualized, you cannot upgrade your Avatar while it is in use");
return false;
}
if(argsArray.length==2) {
if(warrior.getPoints()==0) {
event.getChannel().sendMessage("You do not have any points to use for upgrading, level up to gain them!");
return false;
}
if(argsArray[1].equalsIgnoreCase("primary")) {
warrior.upgradePrimary();
event.getChannel().sendMessage("Primary Points increased to "+warrior.getPrimaryAttack());
return true;
}
if(argsArray[1].equalsIgnoreCase("secondary")) {
warrior.upgradeSecondary();
event.getChannel().sendMessage("Secondary Points increased to "+warrior.getSecondaryAttack());
return true;
}
if(argsArray[1].equalsIgnoreCase("defense")) {
warrior.upgradeDefense();
event.getChannel().sendMessage("Defense Points increased to "+warrior.getDefense());
return true;
}
if(argsArray[1].equalsIgnoreCase("luck")) {
warrior.upgradeLuck();
event.getChannel().sendMessage("Luck Points increased to "+warrior.getLuck());
return true;
}
}else {
String prefix = ObjectManager.getGuild(event.getGuild().getLongID()).getPrefix();
EmbedBuilder builder = new EmbedBuilder();
builder.withAuthorIcon(event.getClient().getOurUser().getAvatarURL());
builder.withAuthorName("Upgrade Menu");
builder.appendField(prefix + "upgrade primary", "Upgrade your Primary Attacks to do more damage\n**Current Primary Points: **" + warrior.getPrimaryAttack(), false);
builder.appendField(prefix + "upgrade secondary", "Upgrade your Secondary Attacks to do more damage\n**Current Secondary Points: **" + warrior.getSecondaryAttack(), false);
builder.appendField(prefix + "upgrade defense", "Upgrade your Defense to take less damage\n**Current Defense Points: **" + warrior.getDefense(), false);
builder.appendField(prefix + "upgrade luck", "Upgrade your luck to increase your chances of landing attacks\n**Current Luck Points: **" + warrior.getLuck(), false);
builder.withFooterText("Avaliable Skill Points to use: " + warrior.getPoints());
event.getChannel().sendMessage(builder.build());
}
return true;
}
}
Loading

0 comments on commit fe6760c

Please sign in to comment.