Skip to content

Commit

Permalink
2.4.5
Browse files Browse the repository at this point in the history
+ added 2 new DM commands: GetGuildList. GetGuildInfo
* changed how some things are validated.
* Toggles are now stored as classes.
* modules can now dynamically remove things assosiated with that module
* other fixes
  • Loading branch information
Vaerys-Dawn committed Feb 21, 2017
1 parent 3a629d1 commit f6e4461
Show file tree
Hide file tree
Showing 53 changed files with 1,543 additions and 1,455 deletions.
1,068 changes: 342 additions & 726 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.vaerys</groupId>
<artifactId>DiscordSAIL</artifactId>
<version>2.4.4</version>
<version>2.4.5</version>
<build>
<resources>
<resource>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.vaerys</groupId>
<artifactId>DiscordSAIL</artifactId>
<version>2.4.4</version>
<version>2.4.5</version>

<build>
<resources>
Expand Down
35 changes: 8 additions & 27 deletions src/main/java/Commands/Admin/ChannelHere.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Commands.Command;
import Commands.CommandObject;
import Main.Globals;
import Main.Utility;
import sx.blah.discord.handle.obj.Permissions;
import sx.blah.discord.util.EmbedBuilder;
Expand All @@ -18,38 +19,18 @@ public class ChannelHere implements Command {
public String execute(String args, CommandObject command) {
StringBuilder builder = new StringBuilder();
if (!args.isEmpty()) {
if (!(args.equalsIgnoreCase(Command.CHANNEL_SERVERS) && !command.guildConfig.doModuleServers())) {
builder.append("> Could not find channel type \"" + args + "\"\n");
} else {
try {
for (Field f : Command.class.getDeclaredFields()) {
if (f.getName().contains("CHANNEL_") && f.getType() == String.class) {
if (args.equalsIgnoreCase((String) f.get(null))) {
command.guildConfig.setUpChannel((String) f.get(null), command.channelID);
return "> This channel is now the Server's **" + f.get(null) + "** channel.";
}
}
}
builder.append("> Could not find channel type \"" + args + "\"\n");
} catch (IllegalAccessException e) {
e.printStackTrace();
for (String channelType : command.channelTypes) {
if (args.equalsIgnoreCase(channelType)) {
command.guildConfig.setUpChannel(channelType, command.channelID);
return "> This channel is now the Server's **" + channelType + "** channel.";
}

}
builder.append("> Could not find channel type \"" + args + "\"\n");
}
EmbedBuilder embedBuilder = new EmbedBuilder();
String title = "> Here is a list of available Channel Types:\n";
ArrayList<String> channels = new ArrayList<>();
try {
for (Field f : Command.class.getDeclaredFields()) {
if (f.getName().contains("CHANNEL_") && f.getType() == String.class) {
if (!(f.get(null).equals(Command.CHANNEL_SERVERS) && !command.guildConfig.doModuleServers())) {
channels.add((String) f.get(null));
}
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
ArrayList<String> channels = command.channelTypes;
Collections.sort(channels);
embedBuilder.withDesc(builder.toString());
Utility.listFormatterEmbed(title, embedBuilder, channels, true);
Expand Down
31 changes: 9 additions & 22 deletions src/main/java/Commands/Admin/Toggle.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Annotations.ToggleAnnotation;
import Commands.Command;
import Commands.CommandObject;
import GuildToggles.GuildToggle;
import Main.Utility;
import POGOs.GuildConfig;
import sx.blah.discord.handle.obj.Permissions;
Expand All @@ -12,6 +13,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Collectors;

/**
* Created by Vaerys on 31/01/2017.
Expand All @@ -21,36 +23,21 @@ public class Toggle implements Command {
public String execute(String args, CommandObject command) {
StringBuilder builder = new StringBuilder();
if (!args.isEmpty()) {
Method[] methods = GuildConfig.class.getMethods();
for (Method m : methods) {
if (m.isAnnotationPresent(ToggleAnnotation.class)) {
ToggleAnnotation toggleAnno = m.getAnnotation(ToggleAnnotation.class);
if (args.equalsIgnoreCase(toggleAnno.name())) {
try {
Boolean state = (Boolean) m.invoke(command.guildConfig);
return "> **" + toggleAnno.name() + " is now " + state + "**.";
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
for (GuildToggle t : command.guildToggles) {
if (args.equalsIgnoreCase(t.name())) {
t.toggle(command.guildConfig);
return "> **" + t.name() + " is now " + t.get(command.guildConfig) + "**.";
}
}
builder.append("> Could not find toggle \"" + args + "\".\n");
}
Method[] methods = GuildConfig.class.getMethods();
EmbedBuilder embedBuilder = new EmbedBuilder();
String title = "> Here is a list of available Guild Toggles:\n";
ArrayList<String> types = new ArrayList<>();
for (Method m : methods) {
if (m.isAnnotationPresent(ToggleAnnotation.class)) {
ToggleAnnotation toggleAnno = m.getAnnotation(ToggleAnnotation.class);
types.add(toggleAnno.name());
}
}
ArrayList<String> types = command.guildToggles.stream().map(GuildToggle::name).collect(Collectors.toCollection(ArrayList::new));
Collections.sort(types);
embedBuilder.withDesc(builder.toString());
Utility.listFormatterEmbed(title,embedBuilder,types,true);
embedBuilder.appendField(spacer,Utility.getCommandInfo(this,command),false);
Utility.listFormatterEmbed(title, embedBuilder, types, true);
embedBuilder.appendField(spacer, Utility.getCommandInfo(this, command), false);
embedBuilder.withColor(Utility.getUsersColour(command.client.getOurUser(), command.guild));
Utility.sendEmbededMessage("", embedBuilder.build(), command.channel);
return null;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface Command {
String TYPE_HELP = "Help";
String TYPE_COMPETITION = "Competition";
String TYPE_DM = "DM";
String TYPE_CREATOR = "Creator";

//Channel Constants
String CHANNEL_GENERAL = "General";
Expand Down
113 changes: 113 additions & 0 deletions src/main/java/Commands/CommandInit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package Commands;

import Commands.Admin.*;
import Commands.CC.*;
import Commands.Characters.DelChar;
import Commands.Characters.ListChars;
import Commands.Characters.SelectChar;
import Commands.Characters.UpdateChar;
import Commands.Competition.EnterComp;
import Commands.Competition.EnterVote;
import Commands.Competition.FinalTally;
import Commands.Competition.GetCompEntries;
import Commands.Creator.Shutdown;
import Commands.Creator.Sudo;
import Commands.Creator.UpdateAvatar;
import Commands.DMCommands.*;
import Commands.General.GetAvatar;
import Commands.General.Hello;
import Commands.General.RemindMe;
import Commands.General.Test;
import Commands.Help.*;
import Commands.Help.GetGuildInfo;
import Commands.RoleSelect.CosmeticRoles;
import Commands.RoleSelect.ListModifs;
import Commands.RoleSelect.ListRoles;
import Commands.RoleSelect.ModifierRoles;
import Commands.Servers.*;

import java.util.ArrayList;

/**
* Created by Vaerys on 20/02/2017.
*/
public class CommandInit {

public static ArrayList<Command> get() {
ArrayList<Command> commands = new ArrayList<>();

//Creator Commands
commands.add(new Shutdown());
commands.add(new Sudo());
commands.add(new UpdateAvatar());

//Admin commands
commands.add(new ChannelHere());
commands.add(new FinalTally());
commands.add(new GetCompEntries());
commands.add(new SetAdminRole());
commands.add(new SetMutedRole());
commands.add(new SetTrustedRoles());
commands.add(new Toggle());
commands.add(new UpdateInfo());
commands.add(new UpdateRolePerms());
//General commands
commands.add(new GetAvatar());
commands.add(new Hello());
commands.add(new RemindMe());
commands.add(new Test());
//Help commands
commands.add(new GetGuildInfo());
commands.add(new Help());
commands.add(new HelpTags());
commands.add(new Info());
commands.add(new Report());
commands.add(new SilentReport());
//RoleSelect commands
commands.add(new CosmeticRoles());
commands.add(new ModifierRoles());
commands.add(new ListRoles());
commands.add(new ListModifs());
//Server commands
commands.add(new AddServer());
commands.add(new DelServer());
commands.add(new EditServerDesc());
commands.add(new EditServerIP());
commands.add(new EditServerName());
commands.add(new ListServers());
commands.add(new Server());
//Character Commands
commands.add(new DelChar());
commands.add(new ListChars());
commands.add(new SelectChar());
commands.add(new UpdateChar());
//CC commands
commands.add(new DelCC());
commands.add(new EditCC());
commands.add(new GetCCData());
commands.add(new InfoCC());
commands.add(new ListCCs());
commands.add(new NewCC());
commands.add(new SearchCCs());
commands.add(new TransferCC());
//Competition commands
commands.add(new EnterComp());
commands.add(new EnterVote());

return commands;
}

public static ArrayList<DMCommand> getDM() {
ArrayList<DMCommand> commands = new ArrayList<>();

//DM commands
commands.add(new BlockUser());
commands.add(new GetGuildList());
commands.add(new Commands.DMCommands.GetGuildInfo());
commands.add(new Respond());
commands.add(new HelpDM());
commands.add(new InfoDM());

return commands;
}
}
77 changes: 74 additions & 3 deletions src/main/java/Commands/CommandObject.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package Commands;

import GuildToggles.GuildToggle;
import Main.Globals;
import Main.Utility;
import Objects.GuildContentObject;
import POGOs.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sx.blah.discord.api.IDiscordClient;
import sx.blah.discord.handle.obj.*;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;


Expand Down Expand Up @@ -35,16 +39,39 @@ public class CommandObject {
public Characters characters;
public Servers servers;
public Competition competition;

public ArrayList<Command> commands = new ArrayList<>();
public ArrayList<DMCommand> dmCommands = new ArrayList<>();
public ArrayList<String> channelTypes = new ArrayList<>();
public ArrayList<String> commandTypes = new ArrayList<>();
public ArrayList<GuildToggle> guildToggles = new ArrayList<>();

public IDiscordClient client;


final static Logger logger = LoggerFactory.getLogger(CommandObject.class);

public CommandObject(IMessage message) {
this.message = message;
messageID = message.getID();
guild = message.getGuild();
guildID = guild.getID();
channel = message.getChannel();
channelID = channel.getID();
author = message.getAuthor();
init();
}

public CommandObject(IMessage message, IGuild guild, IChannel channel, IUser author) {
this.message = message;
this.guild = guild;
this.channel = channel;
this.author = author;
validate();
init();
}

private void init() {
messageID = message.getID();
guildID = guild.getID();
channelID = channel.getID();
authorID = author.getID();
authorUserName = author.getName() + "#" + author.getDiscriminator();
authorDisplayName = author.getDisplayName(guild);
Expand All @@ -59,9 +86,30 @@ public CommandObject(IMessage message) {
competition = guildFiles.getCompetition();
client = Globals.getClient();

commands = Globals.getCommands();
commandTypes = Globals.getCommandTypes();
channelTypes = Globals.getChannelTypes();
guildToggles = Globals.getGuildGuildToggles();

for (GuildToggle t: guildToggles){
if (t.isModule()){
if (!t.get(guildConfig)){
t.execute(this);
}
}
}
dmCommands = Globals.getCommandsDM();

notAllowed = "> I'm sorry " + author.getDisplayName(guild) + ", I'm afraid I can't let you do that.";
}

private void validate() throws IllegalStateException {
if (message == null) throw new IllegalStateException("message can't be null");
if (guild == null) throw new IllegalStateException("guild can't be null");
if (channel == null) throw new IllegalStateException("channel can't be null");
if (author == null) throw new IllegalStateException("author can't be null");
}

public void setAuthor(IUser author) {
this.author = author;
authorID = author.getID();
Expand Down Expand Up @@ -98,4 +146,27 @@ public void setMessage(IMessage message) {
this.message = message;
messageID = message.getID();
}

public void removeCommandsByType(String type) {
for (int i = 0; i < commands.size(); i++){
if (commands.get(i).type().equalsIgnoreCase(type)){
logger.debug(type +" - "+ commands.get(i).names()[0] + " - removed");
commands.remove(i);
}
}
for (int i = 0;i < commandTypes.size(); i++){
if (commandTypes.get(i).equalsIgnoreCase(type)){
commandTypes.remove(i);
logger.debug(type + " - removed");
}
}
}

public void removeChannel(String channel){
for (int i = 0; i< channelTypes.size(); i++){
if (channelTypes.get(i).equalsIgnoreCase(channel)){
channelTypes.remove(i);
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/Commands/Competition/EnterComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public String execute(String args, CommandObject command) {
IMessage message = command.message;
IUser author = command.author;

if (guildConfig.doCompEntries()) {
if (guildConfig.compEntries) {
String fileName;
String fileUrl;
if (message.getAttachments().size() > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Commands/Competition/EnterVote.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class EnterVote implements Command {
@Override
public String execute(String args, CommandObject command) {
if (command.guildConfig.doCompVoting()) {
if (command.guildConfig.compVoting) {
return command.competition.addVote(command.authorID, args);
} else {
return "> Competition Voting is closed.";
Expand Down
Loading

0 comments on commit f6e4461

Please sign in to comment.