Skip to content

Commit

Permalink
2.8.2 Performance and optimisations
Browse files Browse the repository at this point in the history
[Commands]
+ PruneUserProfiles
+ GetGlobalStats
+ FixLevelErrors
+ setlevelUpReaction
+ dailymsg
+ denyxpprefix

[Changes]
* Some major and minor optimisations
* updated the format for storing roleIDs
* some changes to the role commands
* put a cap on the xp and level calculations.
+ you can now stop xp gain for the use of certain commands.

[New User Settings]
+ DenyMakeCC
+ DenyUseCCs
+ AutoShitpost

[New Toggles]
+ UserInfoShowsDate
+ SelfDestructLevelUps
+ reactOnLevelUp

[New Channel Setting]
+ DontLog (Finally omg)
  • Loading branch information
Vaerys-Dawn committed Aug 1, 2017
1 parent a89e2ff commit 596f97d
Show file tree
Hide file tree
Showing 108 changed files with 2,789 additions and 1,502 deletions.
926 changes: 511 additions & 415 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.8.1</version>
<version>2.8.2</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.8.1</version>
<version>2.8.2</version>

<build>
<resources>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ChannelSettings/InitChannels.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static ArrayList<ChannelSetting> get() {
channelSettings.add(new Groups());
channelSettings.add(new XpDenied());
channelSettings.add(new LevelUpDenied());
channelSettings.add(new DontLog());

return channelSettings;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/Commands/Admin/ChannelStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import Main.Globals;
import Main.Utility;
import Objects.ChannelSettingObject;
import Objects.UserTypeObject;
import Objects.XEmbedBuilder;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.Permissions;

import java.util.ArrayList;
Expand Down
110 changes: 110 additions & 0 deletions src/main/java/Commands/Admin/DenyXpPrefix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package Commands.Admin;

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

import java.util.ArrayList;
import java.util.ListIterator;

public class DenyXpPrefix implements Command {

@Override
public String execute(String args, CommandObject command) {
if (args.equalsIgnoreCase("list")) {
return "> Here are all of the prefixes that are registered.\n```" +
Utility.listFormatter(command.guildConfig.getXPDeniedPrefixes(), true) + "```";
}
boolean isAlphanumeric = args.matches("[A-Za-z0-9]+");
if (args.length() > 5) {
return "> Prefix cannot be longer than 5 chars.";
}
if (args.contains("\n")) {
return "> Prefix cannot contain newlines.";
}
if (args.contains(" ")) {
return "> Prefix cannot contain spaces";
}
if (isAlphanumeric) {
return "> Prefix cannot be alphanumeric.";
}
if (args.startsWith("#")) {
return "> Prefix cannot start with a `#`.";
}
if (args.startsWith("@")) {
return "> Prefix cannot start with a `@`.";
}
ArrayList<String> prefixes = command.guildConfig.getXPDeniedPrefixes();
ListIterator iterator = prefixes.listIterator();
while (iterator.hasNext()) {
String prefix = (String) iterator.next();
if (prefix.equals(args)) {
iterator.remove();
return "> Removed the **" + prefix + "** prefix from the xp denied prefixes.";
}
}
prefixes.add(args);
return "> Added the **" + args + "** prefix to the list of xp denied prefixes.";
}

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

@Override
public String description() {
return "prefixes added to this list will stop commands starting with the prefix to stop xp gain.";
}

@Override
public String usage() {
return "[Prefix]/List";
}

@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 true;
}

@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];
}
}
1 change: 0 additions & 1 deletion src/main/java/Commands/Admin/EditInfoFiles.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package Commands.Admin;

import Commands.CommandObject;
import Commands.Help.Info;
import Interfaces.Command;
import Main.Constants;
import Main.Utility;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/Commands/Admin/InfoEditModes.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import Objects.XEmbedBuilder;
import sx.blah.discord.handle.obj.IMessage;

import java.awt.*;
import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down
23 changes: 1 addition & 22 deletions src/main/java/Commands/Admin/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,7 @@
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");
}
XEmbedBuilder embedBuilder = new XEmbedBuilder();
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.sendEmbedMessage("", embedBuilder, command.channel);
return null;
return new Toggle().getContent(args, command, true, this);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Commands/Admin/Mute.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Mute implements Command {
@Override
public String execute(String args, CommandObject command) {
SplitFirstObject userCall = new SplitFirstObject(args);
IRole mutedRole = command.client.getRoleByID(command.guildConfig.getMutedRole().getRoleID());
IRole mutedRole = command.client.getRoleByID(command.guildConfig.getMutedRoleID());
if (mutedRole == null) {
return "> Cannot Mute/UnMute user. No mute role exists.";
}
Expand Down
94 changes: 94 additions & 0 deletions src/main/java/Commands/Admin/PruneEmptyProfiles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package Commands.Admin;

import Commands.CommandObject;
import Interfaces.Command;
import Objects.UserTypeObject;
import sx.blah.discord.handle.obj.Permissions;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.ListIterator;

public class PruneEmptyProfiles implements Command {

@Override
public String execute(String args, CommandObject command) {
ArrayList<UserTypeObject> profiles = command.guildUsers.getUsers();
UserTypeObject defaultProfile = new UserTypeObject(null);
long profileCount = 0;
ListIterator listIterator = profiles.listIterator();
while (listIterator.hasNext()) {
UserTypeObject profile = (UserTypeObject) listIterator.next();
boolean noXP = profile.getXP() == 0;
boolean noGender = defaultProfile.getGender().equals(profile.getGender());
boolean noQuote = defaultProfile.getQuote().equals(profile.getQuote());
boolean noSettings = profile.getSettings().size() == 0;
boolean noLinks = profile.getLinks().size() == 0;
if (noXP && noGender && noQuote && noSettings && noLinks) {
listIterator.remove();
profileCount++;
}
}
return "> " + NumberFormat.getInstance().format(profileCount) + " empty profiles pruned.";
}

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

@Override
public String description() {
return "Prunes all of the empty users on the server.";
}

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

@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];
}
}
18 changes: 10 additions & 8 deletions src/main/java/Commands/Admin/SetAdminRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@
import Interfaces.Command;
import Main.Constants;
import Main.Utility;
import sx.blah.discord.handle.obj.IRole;
import sx.blah.discord.handle.obj.Permissions;

/**
* Created by Vaerys on 31/01/2017.
*/
public class SetAdminRole implements Command{
public class SetAdminRole implements Command {
@Override
public String execute(String args, CommandObject command) {
if (args.equalsIgnoreCase("Remove")){
command.guildConfig.setRoleToMention("NoRoleSetUp","null");
if (args.equalsIgnoreCase("Remove")) {
command.guildConfig.setRoleToMentionID(-1);
return "> Admin Role Removed.";
}
String roleID = Utility.getRoleIDFromName(args, command.guild);
if (roleID == null) {
IRole role = Utility.getRoleFromName(args, command.guild);
if (role == null) {
return Constants.ERROR_ROLE_NOT_FOUND;
} else {
return command.guildConfig.setRoleToMention(command.guild.getRoleByID(roleID).getName(), roleID);
command.guildConfig.setRoleToMentionID(role.getLongID());
return "> The role **" + role.getName() + "** Is now set as the admin role.";
}
}

@Override
public String[] names() {
return new String[]{"SetAdminRole","SetRoleToMention","AdminRole"};
return new String[]{"SetAdminRole", "SetRoleToMention", "AdminRole"};
}

@Override
Expand All @@ -51,7 +53,7 @@ public String channel() {

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

@Override
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/Commands/Admin/SetMutedRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Interfaces.Command;
import Main.Constants;
import Main.Utility;
import Objects.RoleTypeObject;
import sx.blah.discord.handle.obj.IRole;
import sx.blah.discord.handle.obj.Permissions;

/**
Expand All @@ -13,16 +13,16 @@
public class SetMutedRole implements Command{
@Override
public String execute(String args, CommandObject command) {
if (args.equalsIgnoreCase("Remove")){
command.guildConfig.setMutedRole(new RoleTypeObject("NoRoleSetUp","null"));
if (args.equalsIgnoreCase("Remove")) {
command.guildConfig.setRoleToMentionID(-1);
return "> Muted Role Removed.";
}
String roleID = Utility.getRoleIDFromName(args, command.guild);
if (roleID == null) {
IRole role = Utility.getRoleFromName(args, command.guild);
if (role == null) {
return Constants.ERROR_ROLE_NOT_FOUND;
} else {
command.guildConfig.setMutedRole(new RoleTypeObject(command.guild.getRoleByID(roleID).getName(), roleID));
return "> Role: " + command.guild.getRoleByID(roleID).getName() + " Has been set as the Muted Role.";
command.guildConfig.setMutedRoleID(role.getLongID());
return "> The role **" + role.getName() + "** Is now set as the mute role.";
}
}

Expand Down
Loading

0 comments on commit 596f97d

Please sign in to comment.