Skip to content

Commit

Permalink
2.5.2 More Modules.
Browse files Browse the repository at this point in the history
* Seperated the Module and Toggle commands
+ added Module RoleSelect
+ added Module CC
+ added Module UserInfo
  • Loading branch information
Vaerys-Dawn committed Mar 1, 2017
1 parent d3aa5ba commit a7c8da4
Show file tree
Hide file tree
Showing 22 changed files with 616 additions and 619 deletions.
883 changes: 328 additions & 555 deletions .idea/workspace.xml

Large diffs are not rendered by default.

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.1</version>
<version>2.5.2</version>

<build>
<resources>
Expand Down
103 changes: 103 additions & 0 deletions src/main/java/Commands/Admin/Module.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package Commands.Admin;

import Commands.Command;
import Commands.CommandObject;
import GuildToggles.GuildToggle;
import Main.Utility;
import sx.blah.discord.handle.obj.Permissions;
import sx.blah.discord.util.EmbedBuilder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Collectors;

/**
* Created by Vaerys on 31/01/2017.
*/
public class Module implements Command {
@Override
public String execute(String args, CommandObject command) {
StringBuilder builder = new StringBuilder();
if (!args.isEmpty()) {
for (GuildToggle t : command.guildToggles) {
if (t.isModule()) {
if (args.equalsIgnoreCase(t.name())) {
t.toggle(command.guildConfig);
return "> **" + t.name() + " is now " + t.get(command.guildConfig) + "**.";
}
}
}
builder.append("> Could not find Module \"" + args + "\".\n");
}
EmbedBuilder embedBuilder = new EmbedBuilder();
String title = "> Here is a list of available Guild Modules:\n";
ArrayList<String> types = command.guildToggles.stream().filter(t -> t.isModule()).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);
embedBuilder.withColor(Utility.getUsersColour(command.client.getOurUser(), command.guild));
Utility.sendEmbededMessage("", embedBuilder.build(), command.channel);
return null;
}

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

@Override
public String description() {
return "Allows for the toggle of certain commands.";
}

@Override
public String usage() {
return "(Module Type)";
}

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

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

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

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

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

@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];
}
}
10 changes: 6 additions & 4 deletions src/main/java/Commands/Admin/Toggle.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ public String execute(String args, CommandObject command) {
StringBuilder builder = new StringBuilder();
if (!args.isEmpty()) {
for (GuildToggle t : command.guildToggles) {
if (args.equalsIgnoreCase(t.name())) {
t.toggle(command.guildConfig);
return "> **" + t.name() + " is now " + t.get(command.guildConfig) + "**.";
if (!t.isModule()) {
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");
}
EmbedBuilder embedBuilder = new EmbedBuilder();
String title = "> Here is a list of available Guild Toggles:\n";
ArrayList<String> types = command.guildToggles.stream().map(GuildToggle::name).collect(Collectors.toCollection(ArrayList::new));
ArrayList<String> types = command.guildToggles.stream().filter(t -> !t.isModule()).map(GuildToggle::name).collect(Collectors.toCollection(ArrayList::new));
Collections.sort(types);
embedBuilder.withDesc(builder.toString());
Utility.listFormatterEmbed(title, embedBuilder, types, true);
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 @@ -41,6 +41,7 @@ public static ArrayList<Command> get() {
//Admin commands
commands.add(new ChannelHere());
commands.add(new MaxMessages());
commands.add(new Module());
commands.add(new FinalTally());
commands.add(new GetCompEntries());
commands.add(new SetAdminRole());
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/Commands/CommandObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ private void init() {
commands = (ArrayList<Command>) Globals.getCommands().clone();
commandTypes = (ArrayList<String>) Globals.getCommandTypes().clone();
channelTypes = (ArrayList<String>) Globals.getChannelTypes().clone();
guildToggles = Globals.getGuildGuildToggles();
guildToggles = (ArrayList<GuildToggle>) Globals.getGuildGuildToggles().clone();

for (GuildToggle t : guildToggles) {
if (t.isModule()) {
if (!t.get(guildConfig)) {
logger.trace(t.name() + " - " + t.get(guildConfig) + "");
t.execute(this);
for (int i = 0; i < guildToggles.size();i++) {
if (guildToggles.get(i).isModule()) {
if (!guildToggles.get(i).get(guildConfig)) {
logger.trace(guildToggles.get(i).name() + " - " + guildToggles.get(i).get(guildConfig) + "");
guildToggles.get(i).execute(this);
}
}
}
Expand Down Expand Up @@ -174,4 +174,20 @@ public void removeChannel(String channel) {
}
}
}

public void removeCommand(String[] names) {
for (int i = 0;i < commands.size(); i++){
if (commands.get(i).names()[0].equals(names[0])){
commands.remove(i);
}
}
}

public void removeToggle(String name) {
for (int i = 0; i < guildToggles.size();i++){
if (guildToggles.get(i).name().equals(name)){
guildToggles.remove(i);
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/Commands/General/SetGender.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public String type() {

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

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Commands/General/SetQuote.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public String execute(String args, CommandObject command) {
adminEdit = true;
}
}

for (UserTypeObject u : command.guildUsers.getUsers()) {
args = Utility.removeFun(args);
if (args.length() > 140) {
return "> Your Quote is too long...\n(must be under 140 chars)";
}
Expand Down Expand Up @@ -66,7 +66,7 @@ public String type() {

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

@Override
Expand Down
41 changes: 1 addition & 40 deletions src/main/java/Commands/General/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,7 @@ public class Test implements Command {

@Override
public String execute(String args, CommandObject command) {
for (UserTypeObject u : command.guildUsers.getUsers()) {
if (u.getID().equals(command.authorID)) {

EmbedBuilder builder = new EmbedBuilder();
List<IRole> roles = command.authorRoles;
ArrayList<String> roleNames = new ArrayList<>();

//sets title to user Display Name;
builder.withTitle(command.authorDisplayName);

//sets thumbnail to user Avatar.
builder.withThumbnail(command.author.getAvatarURL());

//gets the age of the account.
long difference = ZonedDateTime.now(ZoneOffset.UTC).toEpochSecond() - command.author.getCreationDate().atZone(ZoneOffset.UTC).toEpochSecond();


//sets sidebar colour
builder.withColor(command.authorColour);

//collect role names;
roleNames.addAll(roles.stream().filter(role -> !role.isEveryoneRole()).map(IRole::getName).collect(Collectors.toList()));

//builds desc
builder.withDesc("Account Created: " + Utility.formatTimeDifference(difference) +
"\nGender: " + u.getGender() +
"\nRoles : " + Utility.listFormatter(roleNames, true) +
"\n\n*" + u.getQuote() + "*");

// TODO: 27/02/2017 when xp system is implemented put xp and rank on the user card.

//adds ID
builder.withFooterText("User ID: " + u.getID());

//sends Message
Utility.sendEmbededMessage("", builder.build(), command.channel);
return null;
}
}
return "> An Error occurred.";
return "> Nothing to test right now come back later.";
}

@Override
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/GuildToggles/Modules/ModuleCC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package GuildToggles.Modules;

import Commands.Command;
import Commands.CommandObject;
import GuildToggles.GuildToggle;
import GuildToggles.Toggles.ShitpostFiltering;
import POGOs.GuildConfig;

/**
* Created by Vaerys on 02/03/2017.
*/
public class ModuleCC implements GuildToggle {

@Override
public String name() {
return "CC";
}

@Override
public boolean toggle(GuildConfig config) {
return config.moduleCC = !config.moduleCC;
}

@Override
public boolean get(GuildConfig config) {
return config.moduleCC;
}

@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());
}
}

@Override
public boolean isModule() {
return true;
}
}
2 changes: 1 addition & 1 deletion src/main/java/GuildToggles/Modules/ModuleChars.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ModuleChars implements GuildToggle {

@Override
public String name() {
return "ModuleChars";
return "Chars";
}

@Override
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/GuildToggles/Modules/ModuleComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import Commands.Command;
import Commands.CommandObject;
import GuildToggles.GuildToggle;
import GuildToggles.Toggles.CompEntries;
import GuildToggles.Toggles.Voting;
import POGOs.GuildConfig;

/**
Expand All @@ -14,7 +16,7 @@ public class ModuleComp implements GuildToggle {

@Override
public String name() {
return "ModuleComp";
return "Comp";
}

@Override
Expand All @@ -33,6 +35,8 @@ public void execute(CommandObject command) {
return;
}else {
command.removeCommandsByType(Command.TYPE_COMPETITION);
command.removeToggle(new Voting().name());
command.removeToggle(new CompEntries().name());
}
}

Expand Down
46 changes: 46 additions & 0 deletions src/main/java/GuildToggles/Modules/ModuleMe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package GuildToggles.Modules;

import Commands.Command;
import Commands.CommandObject;
import Commands.General.SetGender;
import Commands.General.SetQuote;
import Commands.General.UserInfo;
import GuildToggles.GuildToggle;
import POGOs.GuildConfig;

/**
* Created by Vaerys on 02/03/2017.
*/
public class ModuleMe implements GuildToggle{

@Override
public String name() {
return "UserInfo";
}

@Override
public boolean toggle(GuildConfig config) {
return config.moduleMe = !config.moduleMe;
}

@Override
public boolean get(GuildConfig config) {
return config.moduleMe;
}

@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());
}
}

@Override
public boolean isModule() {
return true;
}
}
Loading

0 comments on commit a7c8da4

Please sign in to comment.