Advertisement
Vaerys_Dawn

This is apparently a bad thing

Aug 12th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.47 KB | None | 0 0
  1.     @Override
  2.     public String execute(String args, CommandObject command) {
  3.         SplitFirstObject response = new SplitFirstObject(args);
  4.         IUser recipient = command.client.get().getUserByID(response.getFirstWord());
  5.         return sendDM(response.getRest(), command, recipient);
  6.     }
  7.  
  8.     public static String sendDM(String args, CommandObject command, IUser recipient) {
  9.         if (recipient == null) {
  10.             return "> Could Not Send Response, UserID is invalid.";
  11.         }
  12.         if (args == null) {
  13.             return "> Could Not Send Response, Contents cannot be empty.";
  14.         }
  15.         if (Utility.sendDM(command.user.username + ": " + args, recipient.getLongID()).get() == null) {
  16.             return "> An Error occurred while attempting to run this command.";
  17.         } else {
  18.             return "> Message Sent.";
  19.         }
  20.     }
  21.  
  22.     public static RequestBuffer.RequestFuture<IMessage> sendDM(String message, long userID) {
  23.         return RequestBuffer.request(() -> {
  24.             try {
  25.                 IChannel channel = Globals.getClient().getOrCreatePMChannel(Globals.getClient().getUserByID(userID));
  26.                 if (message == null || message.isEmpty()) {
  27.                     return null;
  28.                 }
  29.                 return sendMessage(message, channel).get();
  30.             } catch (DiscordException e) {
  31.                 if (e.getMessage().contains("CloudFlare")) {
  32.                     return sendDM(message, userID).get();
  33.                 } else {
  34.                     e.printStackTrace();
  35.                     return null;
  36.                 }
  37.             } catch (NullPointerException e) {
  38.                 logger.debug("[sendDM] " + e.getMessage());
  39.                 return null;
  40.             }
  41.         });
  42.     }
  43.  
  44.     public static RequestBuffer.RequestFuture<IMessage> sendMessage(String message, IChannel channel) {
  45.         return RequestBuffer.request(() -> {
  46.             IMessage error = null;
  47.             if (message == null) {
  48.                 return error;
  49.             }
  50.             if (message.length() < 2000) {
  51.                 try {
  52.                     if (StringUtils.containsOnly(message, "\n")) {
  53.                         return error;
  54.                     }
  55.                     if (message != null || !message.equals("")) {
  56.                         return channel.sendMessage(removeMentions(message));
  57.                     }
  58.                 } catch (MissingPermissionsException e) {
  59.                     logger.debug("Error sending message to channel with id: " + channel.getStringID() + " on guild with id: " + channel.getGuild().getStringID() +
  60.                             ".\n" + Constants.PREFIX_EDT_LOGGER_INDENT + "Reason: Missing permissions.");
  61.                     return error;
  62.                 } catch (DiscordException e) {
  63.                     if (e.getMessage().contains("CloudFlare")) {
  64.                         return sendMessage(message, channel).get();
  65.                     } else {
  66.                         e.printStackTrace();
  67.                         logger.error(message);
  68.                         return error;
  69.                     }
  70.                 }
  71.             } else {
  72.                 logger.debug("Message to be sent to channel with id: " + channel.getStringID() + "on guild with id: " + channel.getGuild().getStringID() +
  73.                         ".\n" + Constants.PREFIX_EDT_LOGGER_INDENT + "Reason: Message to large.");
  74.                 return error;
  75.             }
  76.             return error;
  77.         });
  78.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement