Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

June 25 Commit. #1

Merged
merged 16 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ Global_Data.json
*.ttf
CC templates/
Storage/
wiki/
/modules/

### Build Artifacts ###
Expand Down
1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

<groupId>com.github.vaerys</groupId>
<artifactId>DiscordSAIL</artifactId>
<version>2.10.6</version>
<version>2.10.7 pre-Release 3</version>

<properties>
<discord4j.version>fe1cdae</discord4j.version>
<patreonAPI.version>0.3.0</patreonAPI.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
Expand Down Expand Up @@ -39,10 +40,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
</configuration>
</plugin>

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/github/vaerys/commands/CommandList.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class CommandList {
add(new ClearReminder());
add(new EditLinks());
add(new GetAvatar());
add(new GetReminders());
add(new Hello());
add(new LastDailyMessage());
add(new NewDailyMessage());
Expand Down Expand Up @@ -135,6 +136,7 @@ public class CommandList {
add(new SelectChar());
add(new SetBioRolePrefix());
add(new UpdateChar());
add(new EditDungeonChar());

//CC commands
add(new DelCC());
Expand Down Expand Up @@ -179,6 +181,7 @@ public class CommandList {
//Dm commands
add(new BotInfoDm());
add(new ClearReminderDM());
add(new GetRemindersDM());
add(new HelpDM());
add(new InfoDM());
add(new ReminderDM());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.github.vaerys.main.Globals;
import com.github.vaerys.main.Utility;
import com.github.vaerys.masterobjects.CommandObject;
import com.github.vaerys.objects.ChannelSettingObject;
import com.github.vaerys.objects.adminlevel.ChannelSettingObject;
import com.github.vaerys.utilobjects.XEmbedBuilder;
import com.github.vaerys.templates.Command;
import sx.blah.discord.handle.obj.IChannel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.github.vaerys.main.Constants;
import com.github.vaerys.main.Utility;
import com.github.vaerys.masterobjects.CommandObject;
import com.github.vaerys.objects.SplitFirstObject;
import com.github.vaerys.objects.utils.SplitFirstObject;
import com.github.vaerys.tags.TagList;
import com.github.vaerys.templates.Command;
import sx.blah.discord.handle.obj.Permissions;
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/com/github/vaerys/commands/admin/PropMutePerms.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.vaerys.enums.ChannelSetting;
import com.github.vaerys.enums.SAILType;
import com.github.vaerys.handlers.RequestHandler;
import com.github.vaerys.handlers.StringHandler;
import com.github.vaerys.masterobjects.CommandObject;
import com.github.vaerys.templates.Command;
import sx.blah.discord.handle.obj.*;
Expand All @@ -18,8 +19,8 @@ public String execute(String args, CommandObject command) {
// check if bot has perms
EnumSet<Permissions> botPerms = command.client.bot.getPermissions(command.guild);
if (!botPerms.contains(Permissions.MANAGE_CHANNELS)) {
return "> I do not have permission to run this command. I need to have Manage Channels.\n" +
"Feel free to remove the permission after i am done as I will no longer need it.";
return "> I do not have permission to run this command. I need to have **Manage Channels**.\n" +
"Feel free to remove the permission after I am done as I will no longer need it.";
}
// get current channel's "Muted" role perms
IRole mutedRole = command.guild.getMutedRole();
Expand All @@ -30,19 +31,28 @@ public String execute(String args, CommandObject command) {

IMessage workingMsg = RequestHandler.sendMessage("`Working...`", command.channel.get()).get();

StringHandler extraComments = new StringHandler();
PermissionOverride mutedPermissions = roleOverrides.get(mutedRole.getLongID());
List<IChannel> guildChannels = command.guild.get().getChannels();
int counter = 0;
for (IChannel channel : guildChannels) {
// remove old permissions, then add our stored set.
channel.removePermissionsOverride(mutedRole);
channel.overrideRolePermissions(mutedRole, mutedPermissions.allow(), mutedPermissions.deny());
counter++;
if (!channel.getModifiedPermissions(command.client.bot.get()).contains(Permissions.MANAGE_PERMISSIONS)) {
if (extraComments.isEmpty()) {
extraComments.append("> Could not apply the permissions to the following channels:");
}
extraComments.append("\n" + channel.mention());
} else {
channel.removePermissionsOverride(mutedRole);
channel.overrideRolePermissions(mutedRole, mutedPermissions.allow(), mutedPermissions.deny());
counter++;
}
}

RequestHandler.deleteMessage(workingMsg);
return "> Set permissions for " + counter + " channels to:\n**Allow**:" + mutedPermissions.allow().toString() +
"\n**Deny**:" + mutedPermissions.deny().toString() +
(extraComments.isEmpty() ? "" : "\n" + extraComments) +
"\n\nYou are now free to remove my **Manage Channels** Permission as I no longer need it.";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.github.vaerys.handlers.GuildHandler;
import com.github.vaerys.handlers.RequestHandler;
import com.github.vaerys.masterobjects.CommandObject;
import com.github.vaerys.objects.ProfileObject;
import com.github.vaerys.objects.userlevel.ProfileObject;
import com.github.vaerys.templates.Command;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IUser;
Expand Down
90 changes: 18 additions & 72 deletions src/main/java/com/github/vaerys/commands/admin/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import com.github.vaerys.enums.ChannelSetting;
import com.github.vaerys.enums.SAILType;
import com.github.vaerys.handlers.FileHandler;
import com.github.vaerys.masterobjects.CommandObject;
import com.github.vaerys.objects.SubCommandObject;
import com.github.vaerys.tags.admintags.TagPath;
import com.github.vaerys.objects.utils.SubCommandObject;
import com.github.vaerys.templates.Command;
import sx.blah.discord.handle.obj.IMessage;
import com.github.vaerys.utilobjects.XEmbedBuilder;
import sx.blah.discord.handle.obj.Permissions;
import sx.blah.discord.util.DiscordException;

import java.awt.*;

/**
* Created by Vaerys on 30/01/2017.
*/
Expand All @@ -26,82 +26,28 @@ public class Test extends Command {

@Override
public String execute(String args, CommandObject command) {

// StringHandler output = new StringHandler();
// output.append("Next step is to pick which settings you want to use.\n")
// .append("There's a lot of settings in modules, and those will be set there.\n")
// .append("Here's a list of the settings that aren't tied to any specific module.\n\n");
//
// List<GuildToggle> globalToggles = ToggleInit.getAllToggles(false);
// List<GuildToggle> modules = ToggleInit.getAllToggles(true);
// List<String> enabled = new LinkedList<>();
// List<String> disabled = new LinkedList<>();
//
//
// globalToggles.sort(Comparator.comparing(GuildToggle::name));
//
// List<SAILType> types = new LinkedList<>();
//
// modules.forEach(t -> types.addAll(t.settings.stream().map(s -> s.name()).collect(Collectors.toList())));
//
// if (!new DebugMode().getDefault()) {
// globalToggles.removeIf(t -> t.name() == SAILType.DEBUG_MODE);
// }
//
// ListIterator iterator = globalToggles.listIterator();
// while (iterator.hasNext()) {
// GuildToggle toggle = (GuildToggle) iterator.next();
// if (types.contains(toggle.name())) {
// iterator.remove();
// } else {
// if (toggle.enabled(command.guild.config)) enabled.add(toggle.name().toString());
// else disabled.add(toggle.name().toString());
// }
// }
//
// String format = "\t> **%s** - %s\n";
// for (GuildToggle t : globalToggles) {
// output.appendFormatted(format, t.name().toString(), t.shortDesc(command));
// }
// output.append("\n");
//
// output.append("You can switch settings on and off with **" +
// new Toggle().getCommand(command) + "** and get more info on each setting with **" +
// new HelpSettings().getCommand(command) + "**.");
//
// XEmbedBuilder embed = new XEmbedBuilder(command);
// embed.withTitle("Global Settings");
// embed.appendField("Enabled", "```" + Utility.listFormatter(enabled, true) + "```", false);
// embed.appendField("Disabled", "```" + Utility.listFormatter(disabled, true) + "```", false);
// RequestHandler.sendEmbedMessage(output.toString(),embed, command.channel);
// return null;

// String webHookUrl = "https://discordapp.com/api/webhooks/443687114417373184/CGcLzpTeQAWuzdXHdRSJYh_1Vc9zhOAxbRVsBBRreQS_esBgIlOAAdDX5U5z2gaZ-KPW";
// XEmbedBuilder embed = new XEmbedBuilder(command.user);
// embed.withDesc(args);
// WebHookObject object = new WebHookObject(embed.build()).setUsername("Blep").setAvatarURL(command.user.getAvatarURL());
// RequestHandler.sendWebHook(webHookUrl, object);

//
// IEmoji emoji = command.guild.getEmojiByName(args);
// if (emoji == null) return "> Not a valid emoji name.";
// return emoji.toString();

// XEmbedBuilder builder = new XEmbedBuilder(command);
// builder.withAuthorName("Note 1 - " +command.user.displayName);
// builder.withAuthorIcon(command.user.getAvatarURL());
// builder.withDescription("blah blah this is a note.\n\n" +
// "`Last edited: " + Utility.formatTime(10, true) + " ago.`");
// builder.withTimestamp(command.message.getTimestamp());
// builder.withFooterText("Created by " + command.client.bot.displayName);
// builder.withFooterIcon(command.client.bot.getAvatarURL());
// builder.send(command.channel);
// return nothing;
// return (long) ((90 - 7) * (Globals.avgMessagesPerDay * command.guild.config.xpRate * command.guild.config.xpModifier) / 8) + "";
// return null;

// EnumSet<Permissions> botPerms = command.client.bot.getPermissions(command.guild);
// return botPerms.contains(Permissions.MANAGE_CHANNELS) ? "> I HAVE MANAGE_CHANNELS" : "> I DO NOT HAVE MANAGE_CHANNELS";
XEmbedBuilder builder = new XEmbedBuilder(Color.RED);
builder.withAuthorName(String.format("@%s", command.user.username));
builder.withTitle("Message Edited.");
builder.withDescription(args);
builder.withFooterText(String.format("Created in #%s, Time Created", command.channel.name));
builder.withTimestamp(command.message.getTimestamp());
builder.send(command);

// return object.isSubCommand(command) + " " + object.getArgs(command) + " " + object.getCommandUsage(command);

// command.guild.characters.addDungeonChar("test");

throw new DiscordException("TestException");

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SAILType type() {

@Override
public ChannelSetting channel() {
return ChannelSetting.MANAGE_CC;
return null;
}

@Override
Expand Down
44 changes: 17 additions & 27 deletions src/main/java/com/github/vaerys/commands/adminccs/EditAdminCC.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@

import com.github.vaerys.enums.ChannelSetting;
import com.github.vaerys.enums.SAILType;
import com.github.vaerys.handlers.FileHandler;
import com.github.vaerys.handlers.StringHandler;
import com.github.vaerys.main.Utility;
import com.github.vaerys.masterobjects.CommandObject;
import com.github.vaerys.objects.AdminCCObject;
import com.github.vaerys.objects.SplitFirstObject;
import com.github.vaerys.tags.TagList;
import com.github.vaerys.tags.cctags.TagEmbedImage;
import com.github.vaerys.objects.adminlevel.AdminCCObject;
import com.github.vaerys.objects.utils.SplitFirstObject;
import com.github.vaerys.templates.Command;
import org.apache.commons.lang3.StringUtils;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.Permissions;

public class EditAdminCC extends Command {
Expand All @@ -24,27 +18,23 @@ public String execute(String args, CommandObject command) {
AdminCCObject cc = command.guild.adminCCs.getCommand(object.getFirstWord());
if (cc == null) return "> Could not find any admin custom commands with that name.";

StringHandler contents = new StringHandler(object.getRest());
IMessage.Attachment attachment = null;
if (command.message.getAttachments().size() != 0) {
attachment = command.message.getAttachments().get(0);
StringHandler contents = NewAdminCC.getContents(command, object.getRest());
NewAdminCC.ResponseCode response = NewAdminCC.testContents(command, contents, cc);

switch (response) {
case EMPTY_CONTENTS:
return "> Cannot edit Admin CC, Contents is empty.";
case TOO_MANY_EMBEDS:
return "> Cannot edit Admin CC, Contents contains more than one <embedImage> tag.";
case NOT_ENOUGH_SLOTS:
return "> This message should never run, but if you did get this message it means you somehow have gone over the slot limit for Admin Custom Commands.";
case OVERLOADS_SLOTS:
return "> There are not enough slots left for you to edit this Admin Custom Command. The new length of the command is too long.";
}
if (attachment != null && attachment.getFilename().endsWith(".txt")) {
contents.append(FileHandler.readFromFile(attachment));
}
TagEmbedImage tag = TagList.getTag(TagEmbedImage.class);
if (attachment != null && Utility.isImageLink(attachment.getFilename())) {
contents.append(tag.prefix).append(attachment.getUrl()).append(tag.suffix);
}
if (StringUtils.countMatches(object.getRest(), tag.prefix) > 1) {
return "> Cannot edit Admin CC, Contents contains more than one <embedImage> tag.";
}

if (contents.isEmpty()) return "> Cannot edit Admin CC, Contents is empty.";
if (contents.length() > 10000) return "> Cannot edit Admin CC, Contents is too long. (Max Chars 10000)";

cc.setContents(contents.toString());
return "> Admin custom command contents updated.";
int remainder = (20 - command.guild.adminCCs.getUsedSlots());
return String.format("> Admin custom command contents updated. (%d Admin CC slot%s remain)", remainder, remainder != 1 ? "s" : "");
}

@Override
Expand All @@ -70,7 +60,7 @@ protected SAILType type() {

@Override
protected ChannelSetting channel() {
return ChannelSetting.MANAGE_CC;
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.github.vaerys.enums.SAILType;
import com.github.vaerys.main.Utility;
import com.github.vaerys.masterobjects.CommandObject;
import com.github.vaerys.objects.AdminCCObject;
import com.github.vaerys.objects.adminlevel.AdminCCObject;
import com.github.vaerys.templates.Command;
import com.github.vaerys.utilobjects.XEmbedBuilder;
import sx.blah.discord.handle.obj.Permissions;
Expand All @@ -19,7 +19,7 @@ public String execute(String args, CommandObject command) {
List<AdminCCObject> adminCCs = command.guild.adminCCs.getCommands();
if (adminCCs.size() == 0) return "> There currently are no Admin Custom Commands right now, come back later.";
XEmbedBuilder builder = new XEmbedBuilder(command);
builder.withTitle("> Here are all of the availible Admin Custom Commands.");
builder.withTitle("> Here are all of the available Admin Custom Commands.");
List<String> commandNames = adminCCs.stream().map(c -> c.getName(command)).collect(Collectors.toList());
builder.withDesc("```\n" + Utility.listFormatter(commandNames, true) + "```");
builder.send(command);
Expand Down
Loading