Vaerys_Dawn

Old vs new UserInfo Command

May 19th, 2018
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.17 KB | None | 0 0
  1. // Old Code
  2.     @Override
  3.     public String execute(String args, CommandObject command) {
  4.         UserObject user;
  5.         if (args == null || args.isEmpty()) {
  6.             user = command.user;
  7.         } else {
  8.             user = Utility.getUser(command, args, true);
  9.         }
  10.         if (user == null) {
  11.             return "> Could not find user.";
  12.         }
  13.         ProfileObject profile = user.getProfile(command.guild);
  14.         if (profile == null && user.get().isBot()) {
  15.             profile = new ProfileObject(user.longID);
  16.             command.guild.users.addUser(profile);
  17.         } else if (profile == null) {
  18.             return "> Could not get a profile for " + user.displayName + ".";
  19.         }
  20.  
  21.         if (!GuildHandler.testForPerms(command, Permissions.ADMINISTRATOR) &&
  22.                 (user.isPrivateProfile(command.guild) && user.longID != command.user.longID)) {
  23.             return "> " + user.displayName + " has set their profile to private.";
  24.         }
  25.  
  26.         //start of the profile builder.
  27.         XEmbedBuilder builder = new XEmbedBuilder(user);
  28.         List<IRole> roles = user.roles;
  29.         ArrayList<String> roleNames = new ArrayList<>();
  30.         ArrayList<String> links = new ArrayList<>();
  31.  
  32.         //init booleans
  33.         boolean showCC = command.guild.config.moduleCC;
  34.         boolean showLevel = !command.guild.config.modulePixels || profile.getXP() == 0;
  35.  
  36.         //sets title to user Display Name;
  37.         builder.withAuthorName(user.displayName);
  38.  
  39.         //sets thumbnail to user Avatar.
  40.         builder.withThumbnail(user.avatarURL);
  41.  
  42.         //gets the age of the account.
  43.         long difference = 0;
  44.         if (user.get() != null) {
  45.             long nowUTC = ZonedDateTime.now(ZoneOffset.UTC).toEpochSecond();
  46.             ZonedDateTime creationDate = user.get().getCreationDate().atZone(ZoneId.systemDefault()).withZoneSameInstant(ZoneOffset.UTC);
  47.             long creationUTC = creationDate.toEpochSecond();
  48.  
  49.             difference = nowUTC - creationUTC;
  50.         }
  51.  
  52.         //collect role names;
  53.         roleNames.addAll(roles.stream().filter(role -> !role.isEveryoneRole()).map(IRole::getName).collect(Collectors.toList()));
  54.  
  55.         if (profile.getLinks() != null && profile.getLinks().size() > 0) {
  56.             links.addAll(profile.getLinks().stream().map(link -> link.toString()).collect(Collectors.toList()));
  57.         }
  58.  
  59.         //builds desc
  60.         StringBuilder desc = new StringBuilder();
  61.         StringBuilder footer = new StringBuilder();
  62.         if (profile.getSettings().contains(UserSetting.READ_RULES) && command.guild.config.readRuleReward) {
  63.             builder.withFooterIcon(Constants.STICKER_STAR_URL);
  64.         }
  65.         if (command.guild.config.userInfoShowsDate && user.get() != null) {
  66.             builder.withTimestamp(user.get().getCreationDate());
  67.             footer.append("UserID: " + profile.getUserID() + ", Creation Date");
  68.         } else {
  69.             if (difference != 0) {
  70.                 desc.append("**Account Created: **" + Utility.formatTimeDifference(difference));
  71.             }
  72.             footer.append("User ID: " + profile.getUserID());
  73.         }
  74.         builder.withFooterText(footer.toString());
  75.  
  76.         //append gender
  77.         desc.append("\n**Gender: **" + profile.getGender());
  78.  
  79.         //append cc count and level
  80.         if (showCC || showLevel) desc.append("\n");
  81.         if (showCC) desc.append(String.format("**Custom Commands:** %d", user.customCommands.size()));
  82.         if (showLevel) {
  83.             if (showCC) desc.append(indent + indent + indent);
  84.             desc.append(String.format("**Level: **", PixelHandler.xpToLevel(profile.getXP())));
  85.         }
  86.  
  87.         //append roles
  88.         if (roleNames.size() != 0) desc.append("\n**Roles: **" + Utility.listFormatter(roleNames, true));
  89.         desc.append("\n\n");
  90.         //append quote
  91.         if (!profile.getQuote().isEmpty()) desc.append("*" + profile.getQuote() + "*");
  92.         //append links
  93.         if (links.size() != 0) desc.append(Utility.listFormatter(links, true));
  94.  
  95.         //set author Icon
  96.         if (user.longID == 153159020528533505L) {
  97.             builder.withAuthorIcon(Constants.DEV_IMAGE_URL);
  98.             builder.withAuthorUrl(Constants.LINK_GITHUB);
  99.         } else if (user.isPatron) builder.withAuthorIcon(Constants.PATREON_ICON_URL);
  100.         //bots only
  101.         if (user.isBot) builder.withAuthorIcon(Constants.BOT_USER_URL);
  102.         if (user.get() == null){
  103.             builder.withAuthorIcon(Constants.UNKNOWN_USER_URL);
  104.         }
  105.         //add desc
  106.         builder.withDesc(desc.toString());
  107.         //sends Message
  108.         if (user.getProfile(command.guild).getSettings().contains(UserSetting.PRIVATE_PROFILE)) {
  109.             RequestHandler.sendEmbedMessage("", builder, command.user.get().getOrCreatePMChannel());
  110.             return "> Profile sent to your Direct messages.";
  111.         }
  112.         RequestHandler.sendEmbedMessage("", builder, command.channel.get());
  113.         return null;
  114.    }
  115.  
  116.  
  117. // New Code
  118.     @Override
  119.     public String execute(String args, CommandObject command) {
  120.         UserObject user;
  121.         if (args == null || args.isEmpty()) user = command.user;
  122.         else user = Utility.getUser(command, args, true);
  123.         if (user == null) return "> Could not find user.";
  124.  
  125.         ProfileObject profile = user.getProfile(command.guild);
  126.  
  127.         //init bot profile
  128.         if (profile == null && user.get().isBot()) {
  129.             profile = new ProfileObject(user.longID);
  130.             command.guild.users.addUser(profile);
  131.         } else if (profile == null) {
  132.             return "> Could not get a profile for " + user.displayName + ".";
  133.         }
  134.  
  135.         //private profile check
  136.         if (!GuildHandler.testForPerms(command, Permissions.ADMINISTRATOR) &&
  137.                 (user.isPrivateProfile(command.guild) && user.longID != command.user.longID)) {
  138.             return "> " + user.displayName + " has set their profile to private.";
  139.         }
  140.  
  141.         //start of the profile builder.
  142.         XEmbedBuilder builder = new XEmbedBuilder(user);
  143.         List<IRole> roles = user.roles;
  144.         List<String> roleNames = roles.stream().filter(role -> !role.isEveryoneRole()).map(IRole::getName).collect(Collectors.toList());
  145.         List<String> links = profile.getLinks().stream().map(link -> link.toString()).collect(Collectors.toList());
  146.         long accountAge = user.getAccountAgeSeconds();
  147.         boolean showCC = command.guild.config.moduleCC;
  148.         boolean showLevel = command.guild.config.modulePixels && profile.getXP() != 0;
  149.         StringBuilder desc = new StringBuilder();
  150.  
  151.         //sets title to user Display Name;
  152.         builder.withAuthorName(user.displayName);
  153.  
  154.         //sets thumbnail to user Avatar.
  155.         builder.withThumbnail(user.avatarURL);
  156.  
  157.         //set author Icon
  158.         if (user.longID == 153159020528533505L) {
  159.             builder.withAuthorIcon(Constants.DEV_IMAGE_URL);
  160.             builder.withAuthorUrl(Constants.LINK_GITHUB);
  161.         } else if (user.isPatron) builder.withAuthorIcon(Constants.PATREON_ICON_URL);
  162.         //bots only
  163.         if (user.isBot) builder.withAuthorIcon(Constants.BOT_USER_URL);
  164.         if (user.get() == null) {
  165.             builder.withAuthorIcon(Constants.UNKNOWN_USER_URL);
  166.         }
  167.  
  168.         //append sticker
  169.         if (profile.getSettings().contains(UserSetting.READ_RULES) && command.guild.config.readRuleReward) {
  170.             builder.withFooterIcon(Constants.STICKER_STAR_URL);
  171.         }
  172.  
  173.         //build desc desc
  174.         if (command.guild.config.userInfoShowsDate) {
  175.             builder.withTimestamp(user.creationDate);
  176.             builder.withFooterText("UserID: " + profile.getUserID() + ", Creation Date");
  177.         } else {
  178.             desc.append("**Account Created: **" + Utility.formatTimeDifference(accountAge));
  179.             builder.withFooterText("User ID: " + profile.getUserID());
  180.         }
  181.  
  182.         //append gender
  183.         desc.append("\n**Gender: **" + profile.getGender());
  184.  
  185.         //append cc count and level
  186.         if (showCC || showLevel) desc.append("\n");
  187.         if (showCC) desc.append(String.format("**Custom Commands:** %d", user.customCommands.size()));
  188.         if (showLevel) {
  189.             if (showCC) desc.append(indent + indent + indent);
  190.             desc.append(String.format("**Level:** %d", PixelHandler.xpToLevel(profile.getXP())));
  191.         }
  192.  
  193.         //append roles
  194.         if (roleNames.size() != 0) desc.append("\n**Roles: **" + Utility.listFormatter(roleNames, true));
  195.         desc.append("\n\n");
  196.  
  197.         //append quote
  198.         if (!profile.getQuote().isEmpty()) desc.append("*" + profile.getQuote() + "*");
  199.         //append links
  200.         if (links.size() != 0) desc.append(Utility.listFormatter(links, true));
  201.  
  202.         //add desc
  203.         builder.withDesc(desc.toString());
  204.         //sends Message
  205.         if (user.getProfile(command.guild).getSettings().contains(UserSetting.PRIVATE_PROFILE)) {
  206.             RequestHandler.sendEmbedMessage("", builder, command.user.get().getOrCreatePMChannel());
  207.             return "> Profile sent to your Direct messages.";
  208.         }
  209.         RequestHandler.sendEmbedMessage("", builder, command.channel.get());
  210.         return null;
  211.     }
Advertisement
Add Comment
Please, Sign In to add comment