Skip to content

Commit

Permalink
2.5.5 - Quality of life fixes
Browse files Browse the repository at this point in the history
* slash commands now only need to start with the command in orver to
activate.
+ new toggle added, roleIsToggle converts Role command to a role toggle
command.
* changed how getCCdata works, it now lists all data in a .txt file and
then sends that, this is better than the old system as sends it in
plaintext
* edit and deletion logs now remove role mentoions.
* fixed modules not properly being disabled.
+ resetPlayingStatus command added
  • Loading branch information
Vaerys-Dawn committed Mar 28, 2017
1 parent 931b5cf commit ec844a1
Show file tree
Hide file tree
Showing 33 changed files with 334 additions and 78 deletions.
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.5.4</version>
<version>2.5.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.5.4</version>
<version>2.5.5</version>

<build>
<resources>
Expand Down
29 changes: 27 additions & 2 deletions src/main/java/Commands/CC/GetCCData.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
package Commands.CC;

import Commands.CommandObject;
import Handlers.FileHandler;
import Interfaces.Command;
import Main.Constants;
import Main.Utility;
import Objects.CCommandObject;
import sx.blah.discord.handle.obj.Permissions;

import java.io.File;

/**
* Created by Vaerys on 01/02/2017.
*/
public class GetCCData implements Command {
@Override
public String execute(String args, CommandObject command) {
return command.customCommands.sendCCasJSON(command.channelID, args);
for (CCommandObject c : command.customCommands.getCommandList()) {
if (c.getName().equalsIgnoreCase(args)) {
String content = "Command Name: \"" + c.getName() + "\"";
content += "\nCreated by: \"" + command.client.getUserByID(c.getUserID()).getDisplayName(command.guild) + "\"";
content += "\nTimes run: \"" + c.getTimesRun() + "\"";
content += "\nContents: \"" + c.getContents(false) + "\"";
String filePath = Constants.DIRECTORY_TEMP + command.messageID + ".txt";
FileHandler.writeToFile(filePath, content);
Utility.sendFile("> Here is the raw data for Custom Command: **" + c.getName() + "**", new File(filePath), command.channel);
try {
Thread.sleep(4000);
new File(filePath).delete();
} catch (InterruptedException e) {
e.printStackTrace();
}
return "";
}
}
return "> Custom command " + args + " could not be found.";
// return command.customCommands.sendCCasJSON(command.channelID, args);
}

@Override
public String[] names() {
return new String[]{"GetCCData"};
return new String[]{"GetCCdata"};
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Commands/CommandInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static ArrayList<Command> get() {
commands.add(new UpdateAvatar());
commands.add(new GetMessageData());
commands.add(new TempCommand());
commands.add(new ResetPlayingStatus());

//Admin commands
commands.add(new ChannelHere());
Expand Down
32 changes: 29 additions & 3 deletions src/main/java/Commands/CommandObject.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Commands;

import GuildToggles.Modules.ModuleServers;
import Interfaces.Command;
import Interfaces.DMCommand;
import Interfaces.GuildToggle;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class CommandObject {
public ArrayList<String> channelTypes = new ArrayList<>();
public ArrayList<String> commandTypes = new ArrayList<>();
public ArrayList<GuildToggle> guildToggles = new ArrayList<>();
private ArrayList<GuildToggle> toRemove = new ArrayList<>();

public IDiscordClient client;

Expand Down Expand Up @@ -97,14 +99,38 @@ private void init() {
channelTypes = (ArrayList<String>) Globals.getChannelTypes().clone();
guildToggles = (ArrayList<GuildToggle>) Globals.getGuildGuildToggles().clone();

logger.trace("Nodules:" + (" CC = " + guildConfig.moduleCC +
", ROLES = " + guildConfig.moduleRoles +
", COMP = " + guildConfig.moduleComp +
", SERVERS = " + guildConfig.moduleServers +
", CHARS = " + guildConfig.moduleChars +
", ME = " + guildConfig.moduleMe +
", MODMUTE = " + guildConfig.moduleModMute + ".").toUpperCase());
String testToggles = "";
for (GuildToggle g : guildToggles) {
testToggles += g.name() + ", ";
}
if (testToggles.contains(new ModuleServers().name())) {
logger.debug("Module Servers found.");
}
for (int i = 0; i < guildToggles.size(); i++) {
logger.info("this - " + guildToggles.get(i).name());
if (!guildToggles.get(i).get(guildConfig)) {
if (guildToggles.get(i).isModule()) {
logger.trace(guildToggles.get(i).name() + " - " + guildToggles.get(i).get(guildConfig) + "");
logger.trace(guildToggles.get(i).name() + " - " + guildToggles.get(i).get(guildConfig));
}
guildToggles.get(i).execute(this);
}
}
//well this works I guess.
for (GuildToggle t : toRemove) {
for (int i = 0; i < guildToggles.size(); i++) {
if (t.name().equalsIgnoreCase(guildToggles.get(i).name())){
guildToggles.remove(i);
}
}
}

dmCommands = Globals.getCommandsDM();

notAllowed = "> I'm sorry " + author.getDisplayName(guild) + ", I'm afraid I can't let you do that.";
Expand Down Expand Up @@ -164,8 +190,8 @@ public void removeCommandsByType(String type) {
}
for (int i = 0; i < commandTypes.size(); i++) {
if (commandTypes.get(i).equalsIgnoreCase(type)) {
logger.trace("Type - " + commandTypes.get(i) + " - removed");
commandTypes.remove(i);
logger.trace(type + " - removed");
}
}
}
Expand All @@ -189,7 +215,7 @@ public void removeCommand(String[] names) {
public void removeToggle(String name) {
for (int i = 0; i < guildToggles.size(); i++) {
if (guildToggles.get(i).name().equals(name)) {
guildToggles.remove(i);
toRemove.add(guildToggles.get(i));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Commands/Competition/EnterComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Commands.CommandObject;
import Interfaces.Command;
import Objects.PollObject;
import Objects.CompObject;
import POGOs.GuildConfig;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IUser;
Expand Down Expand Up @@ -39,7 +39,7 @@ public String execute(String args, CommandObject command) {
}
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy - HH:mm:ss");
Calendar cal = Calendar.getInstance();
command.competition.newEntry(new PollObject(author.getDisplayName(command.guild), author.getID(), fileName, fileUrl, dateFormat.format(cal.getTime())));
command.competition.newEntry(new CompObject(author.getDisplayName(command.guild), author.getID(), fileName, fileUrl, dateFormat.format(cal.getTime())));
return "> Thank you " + author.getDisplayName(command.guild) + " For entering the Competition.";
} else {
return "> Competition Entries are closed.";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Commands/Competition/GetCompEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Commands.CommandObject;
import Interfaces.Command;
import Main.Utility;
import Objects.PollObject;
import Objects.CompObject;
import sx.blah.discord.handle.obj.Permissions;

/**
Expand All @@ -13,7 +13,7 @@ public class GetCompEntries implements Command {
@Override
public String execute(String args, CommandObject command) {
int i = 1;
for (PollObject p : command.competition.getEntries()) {
for (CompObject p : command.competition.getEntries()) {
Utility.sendMessage("Entry " + i + " : " + command.guild.getUserByID(p.getUserID()).mention() + "\n" +
p.getFileUrl(), command.channel);
try {
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/Commands/Creator/ResetPlayingStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package Commands.Creator;

import Commands.CommandObject;
import Interfaces.Command;
import Main.Globals;
import sx.blah.discord.handle.obj.Permissions;

/**
* Created by Vaerys on 21/03/2017.
*/
public class ResetPlayingStatus implements Command{
@Override
public String execute(String args, CommandObject command) {
command.client.changePlayingText(Globals.playing);
return "> Status reset.";
}

@Override
public String[] names() {
return new String[]{"ResetPlayingStatus"};
}

@Override
public String description() {
return "Resets the playing status.";
}

@Override
public String usage() {
return null;
}

@Override
public String type() {
return TYPE_CREATOR;
}

@Override
public String channel() {
return null;
}

@Override
public Permissions[] perms() {
return new Permissions[0];
}

@Override
public boolean requiresArgs() {
return false;
}

@Override
public boolean doAdminLogging() {
return false;
}

@Override
public String dualDescription() {
return null;
}

@Override
public String dualUsage() {
return null;
}

@Override
public String dualType() {
return null;
}

@Override
public Permissions[] dualPerms() {
return new Permissions[0];
}
}
1 change: 1 addition & 0 deletions src/main/java/Commands/Help/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public String execute(String args, CommandObject command) {
for (Permissions p : c.perms()) {
permList.add(p.toString());
}
builder.append("**");
builder.append(Utility.listFormatter(permList, true));
}
//dual command info
Expand Down
28 changes: 23 additions & 5 deletions src/main/java/Commands/RoleSelect/CosmeticRoles.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,23 @@ public String execute(String args, CommandObject command) {
ArrayList<RoleTypeObject> roles = guildConfig.getCosmeticRoles();
String newRoleId = null;
List<IRole> userRoles = guild.getRolesForUser(author);
boolean toggle = false;
for (RoleTypeObject role : roles) {
for (int i = 0; userRoles.size() > i; i++) {
if (role.getRoleID().equals(userRoles.get(i).getID())) {
userRoles.remove(i);
if (command.guildConfig.roleIsToggle) {
if (userRoles.get(i).getName().equalsIgnoreCase(args)){
userRoles.remove(i);
toggle = true;
}
} else {
if (role.getRoleID().equals(userRoles.get(i).getID())) {
userRoles.remove(i);
}
}
if (args.equalsIgnoreCase(guild.getRoleByID(role.getRoleID()).getName())) {
newRoleId = role.getRoleID();
}

}
}
if (splitFirst.getFirstWord().equalsIgnoreCase("remove")) {
Expand All @@ -68,11 +77,20 @@ public String execute(String args, CommandObject command) {
}
return "> Role with name: **" + args + "** not found in **Cosmetic Role** list.";
} else {
userRoles.add(guild.getRoleByID(newRoleId));
response = "> You have selected the cosmetic role: **" + guild.getRoleByID(newRoleId).getName() + "**.";
if (!toggle) {
userRoles.add(guild.getRoleByID(newRoleId));
if (command.guildConfig.roleIsToggle){
response = "> You have enabled the cosmetic role: **" + guild.getRoleByID(newRoleId).getName() + "**.";
}else {
response = "> You have selected the cosmetic role: **" + guild.getRoleByID(newRoleId).getName() + "**.";
}
}else {
response = "> You have disabled the cosmetic role: **" + guild.getRoleByID(newRoleId).getName() + "**.";
}

}
}
command.client.getDispatcher().dispatch(new UserRoleUpdateEvent(guild,author,oldRoles,userRoles));
command.client.getDispatcher().dispatch(new UserRoleUpdateEvent(guild, author, oldRoles, userRoles));
if (Utility.roleManagement(author, guild, userRoles).get()) {
return Constants.ERROR_UPDATING_ROLE;
} else {
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/GuildToggles/Modules/ModuleCC.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ public boolean get(GuildConfig config) {

@Override
public void execute(CommandObject command) {
if (command.guildConfig.moduleCC) {
return;
} else {
command.removeCommandsByType(Command.TYPE_CC);
command.removeChannel(Command.CHANNEL_SHITPOST);
command.removeToggle(new ShitpostFiltering().name());
}
command.removeCommandsByType(Command.TYPE_CC);
command.removeChannel(Command.CHANNEL_SHITPOST);
command.removeToggle(new ShitpostFiltering().name());
}

@Override
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/GuildToggles/Modules/ModuleChars.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ public boolean get(GuildConfig config) {

@Override
public void execute(CommandObject command) {
if (command.guildConfig.moduleChars){
return;
}else {
command.removeCommandsByType(Command.TYPE_CHARACTER);
}
command.removeCommandsByType(Command.TYPE_CHARACTER);
}

@Override
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/GuildToggles/Modules/ModuleComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ public boolean get(GuildConfig config) {

@Override
public void execute(CommandObject command) {
if (command.guildConfig.moduleComp){
return;
}else {
command.removeCommandsByType(Command.TYPE_COMPETITION);
command.removeToggle(new Voting().name());
command.removeToggle(new CompEntries().name());
}
command.removeCommandsByType(Command.TYPE_COMPETITION);
command.removeToggle(new Voting().name());
command.removeToggle(new CompEntries().name());
}

@Override
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/GuildToggles/Modules/ModuleMe.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Created by Vaerys on 02/03/2017.
*/
public class ModuleMe implements GuildToggle{
public class ModuleMe implements GuildToggle {

@Override
public String name() {
Expand All @@ -29,13 +29,9 @@ public boolean get(GuildConfig config) {

@Override
public void execute(CommandObject command) {
if (command.guildConfig.moduleMe) {
return;
} else {
command.removeCommand(new UserInfo().names());
command.removeCommand(new SetGender().names());
command.removeCommand(new SetQuote().names());
}
command.removeCommand(new UserInfo().names());
command.removeCommand(new SetGender().names());
command.removeCommand(new SetQuote().names());
}

@Override
Expand Down
Loading

0 comments on commit ec844a1

Please sign in to comment.