Skip to content

Commit

Permalink
2.7.1 Info Channels now with more customisation.
Browse files Browse the repository at this point in the history
+ added special messages to the Role command when you enter your
arguments wrong.
+ added more checks to the Pixel system
* Fixed a bug in which a user profile wouldn't get created until your
first gain of pixels.
* Reverted a change of name for the slashCommands command.
* updated help and info commands to only show information (such as
channels and commands) relevant to the user.
+ editInfoFiles command, this command allows you to modify all of the
files needed to use the Updateinfo command properly
* fixed a bug with updateinfo where it wouldn't error properly if the ID
of the user was incorrect
* fixed a bug that would cause using the admin edits for ccs to have
weird behaviour.
+ added RandomStatuses to the Config.Json File. you can now set statuses
that will update every 5 mins. this means that it is now fully
customisable and not hardcoded.
* Further work has been done on the XP system, decay base code has been
added.
- unused toggle setting "LoginMessage" was removed.
  • Loading branch information
Vaerys-Dawn committed Jun 29, 2017
1 parent 5c0697f commit 960b395
Show file tree
Hide file tree
Showing 38 changed files with 6,316 additions and 672 deletions.

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

859 changes: 420 additions & 439 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion DiscordSAIL.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.json:json:20140107" level="project" />
<orderEntry type="library" name="Maven: com.github.austinv11:Discord4j:shaded:2.8.1" level="project" />
<orderEntry type="library" name="Maven: com.github.austinv11:Discord4j:shaded:2.8.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.24" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.6" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.3" level="project" />
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<dependency>
<groupId>com.github.austinv11</groupId>
<artifactId>Discord4j</artifactId>
<version>2.8.1</version>
<version>2.8.3</version>
<classifier>shaded</classifier>
</dependency>
<dependency>
Expand Down
102 changes: 102 additions & 0 deletions src/main/java/Commands/Admin/EditInfoFiles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package Commands.Admin;

import Commands.CommandObject;
import Commands.Help.Info;
import Interfaces.Command;
import Main.Constants;
import Main.Utility;
import Objects.SplitFirstObject;
import sx.blah.discord.handle.obj.Permissions;

/**
* Created by Vaerys on 26/06/2017.
*/
public class EditInfoFiles implements Command {
@Override
public String execute(String args, CommandObject command) {
SplitFirstObject object = new SplitFirstObject(args);
switch (object.getFirstWord().toLowerCase()) {
case "uploadimage":
return InfoEditModes.uploadFile(command.message);
case "removeimage":
return InfoEditModes.removeFile(object.getRest(), command.message);
case "listimages":
return InfoEditModes.listFiles(command.message);
case "listfiles":
return InfoEditModes.listFiles(command.message);
case "uploadinfo":
return InfoEditModes.uploadInfo(command.message);
case "getinfofile": {
return InfoEditModes.getInfoFile(command.message);
}
default:
return "Invalid Edit Mode.\n" + Utility.getCommandInfo(this, command);
}
}

@Override
public String[] names() {
return new String[]{"EditInfoFiles", "UpdateInfoFiles"};
}

@Override
public String description() {
return "Allows for editing of the updateInfo command.\n" +
"**Modes:**\n" +
"- uploadImage: **Requires image file.**\n" +
"- removeImage: **Requires file name.**\n" +
"- listFiles/listImages\n" +
"- uploadInfo: **Requires \"" + Constants.FILE_INFO + "\" file.**\n" +
"- getInfoFile";
}

@Override
public String usage() {
return "[EditMode] (ImageFile/ImageName/Info.txt)";
}

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

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

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

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

import Main.Constants;
import Main.Globals;
import Main.Utility;
import Objects.XEmbedBuilder;
import sx.blah.discord.handle.obj.IMessage;

import java.awt.*;
import java.io.*;
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;

/**
* Created by Vaerys on 26/06/2017.
*/
public class InfoEditModes {

public static String uploadFile(IMessage message) {
if (message.getAttachments() == null || message.getAttachments().size() == 0) {
return "> No file to upload found.";
} else {
try {
IMessage.Attachment attachment = message.getAttachments().get(0);
File file = new File(Utility.getGuildImageDir(message.getGuild().getStringID()) + attachment.getFilename());
File imagDir = new File(Utility.getGuildImageDir(message.getGuild().getStringID()));
File[] imageList = imagDir.listFiles();

if (!Utility.isImageLink(attachment.getFilename())) {
return "> Cannot upload File. File type is invalid.";
}

//grab file
final HttpURLConnection connection = (HttpURLConnection) new URL(attachment.getUrl()).openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) " + "AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31");
InputStream stream = connection.getInputStream();

//save or update file
if (file.exists()) {
file.delete();
Files.copy(stream, Paths.get(file.getPath()));
return "> File **" + attachment.getFilename() + "** updated";
} else {
if (imageList.length >= 25) {
return "> Max images already reached, you will need to remove an old image to upload a new one.";
} else {
Files.copy(stream, Paths.get(file.getPath()));
return "> File **" + attachment.getFilename() + "** uploaded";
}
}
} catch (IOException e) {
e.printStackTrace();
return "> An error occurred trying to upload your file.";
}
}
}

public static String removeFile(String rest, IMessage message) {
File imagDir = new File(Utility.getGuildImageDir(message.getGuild().getStringID()));
File[] imageList = imagDir.listFiles();
for (File f : imageList) {
if (f.getName().equalsIgnoreCase(rest)) {
f.delete();
return "> File Removed.";
}
}
return "> File Not Found.";
}

public static String listFiles(IMessage message) {
//send Embed
XEmbedBuilder builder = new XEmbedBuilder();
builder.withTitle("> Here are the files available to you:");
File imagDir = new File(Utility.getGuildImageDir(message.getGuild().getStringID()));
File[] imageList = imagDir.listFiles();
ArrayList<String> fileNames = new ArrayList<>();
for (File f : imageList) {
fileNames.add(f.getName());
}
builder.withColor(Utility.getUsersColour(Globals.getClient().getOurUser(), message.getGuild()));
builder.withDesc("```\n" + Utility.listFormatter(fileNames, true) + "```");
Utility.sendEmbedMessage("", builder, message.getChannel());
return null;
}

public static String uploadInfo(IMessage message) {
if (message.getAttachments() == null || message.getAttachments().size() == 0) {
return "> No file to upload found.";
} else {
try {
IMessage.Attachment attachment = message.getAttachments().get(0);
File file = new File(Utility.getFilePath(message.getGuild().getStringID(), Constants.FILE_INFO));

if (!attachment.getFilename().equals(Constants.FILE_INFO)) {
return "> Cannot upload file, File name must be \"" + Constants.FILE_INFO + "\"";
}

//grab file
final HttpURLConnection connection = (HttpURLConnection) new URL(attachment.getUrl()).openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) " + "AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31");
InputStream stream = connection.getInputStream();

//save or update file
if (file.exists()) {
file.delete();
Files.copy(stream, Paths.get(file.getPath()));
return "> Updated **" + Constants.FILE_INFO + "** file.";
} else {
Files.copy(stream, Paths.get(file.getPath()));
return "> New **" + Constants.FILE_INFO + "** file uploaded.";
}
} catch (IOException e) {
e.printStackTrace();
return "> An error occurred trying to upload your file.";
}
}
}

public static String getInfoFile(IMessage message) {
String filePath = Utility.getFilePath(message.getGuild().getStringID(), Constants.FILE_INFO);
File file = new File(filePath);
if (file.exists()) {
Utility.sendFile("> Here is your **"+Constants.FILE_INFO+ "** file.", file, message.getChannel());
} else {
return "> Cannot send file, **" + Constants.FILE_INFO + "** file does not exist yet.";
}
return null;
}
}
12 changes: 9 additions & 3 deletions src/main/java/Commands/Admin/UpdateInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
import Main.Utility;
import sx.blah.discord.handle.obj.Permissions;

import java.util.ArrayList;

/**
* Created by Vaerys on 31/01/2017.
*/
public class UpdateInfo implements Command {
@Override
public String execute(String args, CommandObject command) {
if (command.guildConfig.getChannelIDsByType(Command.CHANNEL_INFO) == null) {
return "> No Info channel set up yet, you need to set one up in order to run this command.\n" + Utility.getCommandInfo(this,command);
return "> No Info channel set up yet, you need to set one up in order to run this command.\n" + Utility.getCommandInfo(this, command);
} else {
new InfoHandler(command.channel, command.guild);
return null;
if (command.guildConfig.getChannelIDsByType(Command.CHANNEL_INFO).contains(command.channelSID)) {
new InfoHandler(command.channel, command.guild);
return null;
} else {
return "> Command must be performed in " + command.client.getChannelByID(command.guildConfig.getChannelIDsByType(CHANNEL_INFO).get(0)).mention() + ".";
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/Commands/CC/CCEditModes.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ public class CCEditModes {

public static String lock(CCommandObject c, CommandObject command, IUser author, IGuild guild) {
if (Utility.testForPerms(new Permissions[]{Permissions.MANAGE_MESSAGES}, author, guild)) {
return "> Lock for " + c.getName() + " is now " + c.toggleShitPost() + ".";
c.toggleLocked();
return "> Lock for " + c.getName() + " is now " + c.isLocked() + ".";
} else {
return command.notAllowed;
}
}

public static String shitPost(CCommandObject c, CommandObject command, IUser author, IGuild guild) {
if (Utility.testForPerms(new Permissions[]{Permissions.MANAGE_MESSAGES}, author, guild)) {
return "> Shitpost for " + c.getName() + " is now " + c.toggleShitPost() + ".";
c.toggleShitPost();
return "> Shitpost for " + c.getName() + " is now " + c.isShitPost() + ".";
} else {
return command.notAllowed;
}
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/Commands/CC/ListCCs.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ public String listCommands(int page, CommandObject command) {
builder.withColor(Utility.getUsersColour(command.client.getOurUser(), command.guild));

for (CCommandObject c : command.customCommands.getCommandList()) {
if (counter > 15) {
pages.add("`" + Utility.listFormatter(list, true) + "`");
list.clear();
counter = 0;
}
list.add(command.guildConfig.getPrefixCC() + c.getName());
totalCCs++;
counter++;
// if (command.guild.getUserByID(c.getUserID()) != null) {
if (counter > 15) {
pages.add("`" + Utility.listFormatter(list, true) + "`");
list.clear();
counter = 0;
}
list.add(command.guildConfig.getPrefixCC() + c.getName());
totalCCs++;
counter++;
// }
}
pages.add("`" + Utility.listFormatter(list, true) + "`");
try {
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 @@ -46,6 +46,7 @@ public static ArrayList<Command> get() {
commands.add(new MaxMessages());
commands.add(new Module());
commands.add(new Mute());
commands.add(new EditInfoFiles());
// commands.add(new RewardRole());
commands.add(new SetAdminRole());
commands.add(new SetMutedRole());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Commands/General/SlashList.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public String execute(String args, CommandObject command) {

@Override
public String[] names() {
return new String[]{"Commands/Slash"};
return new String[]{"SlashList","SlashCommands","Slash"};
}

@Override
Expand Down
Loading

0 comments on commit 960b395

Please sign in to comment.