Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Command
- @CommandAnnotation(
- name = "GetCCData", description = "Sends a Json File with all of the Custom command's data.", usage = "[Command Name]",
- type = Constants.TYPE_CC, channel = Constants.CHANNEL_BOT_COMMANDS, requiresArgs = true)
- public String getCCData(){
- customCommands.sendCCasJSON(channel.getID(),args,guildID);
- return null;
- }
- //SendCCasJson
- public void sendCCasJSON(String channelID, String commandName, String guildID) {
- GuildConfig guildConfig = (GuildConfig) FileHandler.readFromJson(Utility.getFilePath(guildID, Constants.FILE_GUILD_CONFIG), GuildConfig.class);
- String botChannelID = guildConfig.getChannelTypeID(Constants.CHANNEL_BOT_COMMANDS);
- IChannel channel = Globals.getClient().getChannelByID(channelID);
- for (CCommandObject c : commands) {
- if (c.getName().equalsIgnoreCase(commandName)) {
- File file = FileHandler.createTempFile(c, c.getName());
- if (Utility.sendFile("> Here is the Raw Data for Custom Command: **" + c.getName() + "**", channel, file).get()) {
- Utility.sendMessage("> An error occurred when attempting to get CC data.", channel);
- }
- return;
- }
- }
- Utility.sendMessage(Constants.ERROR_CC_NOT_FOUND, channel);
- return;
- }
- //FileHandler.CreateTempFile
- /**saves data from POGO of type "object" to temp file using String "name".*/
- public static File createTempFile(Object object, String name){
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- try {
- File file = File.createTempFile(name,".json");
- FileWriter writer = new FileWriter(file);
- gson.toJson(object,writer);
- return file;
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
- //Utility.SendFile
- public static RequestBuffer.RequestFuture<Boolean> sendFile(String message, IChannel channel, File file) {
- return RequestBuffer.request(() -> {
- try {
- if (StringUtils.containsOnly(message, "\n") || (message == null) || message.equals("")) {
- if (message != null) {
- channel.sendFile(file);
- }else {
- logger.error("Error sending File to channel with id: " + channel.getID() + " on guild with id: " + channel.getGuild().getID() +
- ".\n" + Constants.PREFIX_EDT_LOGGER_INDENT + "Reason: No file to send");
- return true;
- }
- }else {
- if (message != null) {
- channel.sendFile(file,message);
- }else {
- sendMessage(message,channel);
- return true;
- }
- }
- } catch (DiscordException e) {
- if (e.getMessage().contains("CloudFlare")) {
- sendMessage(message, channel);
- } else {
- e.printStackTrace();
- return true;
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (MissingPermissionsException e) {
- logger.error("Error sending File to channel with id: " + channel.getID() + " on guild with id: " + channel.getGuild().getID() +
- ".\n" + Constants.PREFIX_EDT_LOGGER_INDENT + "Reason: Missing permissions.");
- return true;
- }
- return false;
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment