Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TagRemoveMentions extends TagObject {
- public TagRemoveMentions(int priority) {
- super(priority);
- }
- @Override
- public String execute(String from, CommandObject command, String args) {
- boolean isRoleMention = false;
- String id;
- if (Pattern.compile("<@&[0-9]*>").matcher(from).find()) {
- id = StringUtils.substringBetween(from, "<@&", ">");
- isRoleMention = true;
- } else {
- id = StringUtils.substringBetween(from, "<@!", ">");
- if (id == null) {
- id = StringUtils.substringBetween(from, "<@", ">");
- }
- }
- if (!isRoleMention) {
- try {
- long userID = Long.parseUnsignedLong(id);
- IUser user = command.guild.getUserByID(userID);
- if (user != null) {
- from = from.replace(user.mention(true), user.getDisplayName(command.guild.get()));
- from = from.replace(user.mention(false), user.getDisplayName(command.guild.get()));
- } else {
- throw new NumberFormatException("You shouldn't see this.");
- }
- } catch (NumberFormatException e) {
- from = from.replace("<@!" + id + ">", "null");
- from = from.replace("<@" + id + ">", "null");
- }
- } else {
- //remove role mentions
- try {
- long roleID = Long.parseUnsignedLong(id);
- IRole role = command.guild.getRoleByID(roleID);
- if (role != null) {
- from = from.replace("<@&" + id + ">", role.getName());
- } else {
- throw new NumberFormatException("You shouldn't see this.");
- }
- } catch (NumberFormatException e) {
- from = from.replace("<@&" + id + ">", "null");
- }
- }
- return from;
- }
- @Override
- public boolean cont(String from) {
- return Pattern.compile("<@!?[0-9]*>").matcher(from).find() ||
- Pattern.compile("<@&[0-9]*>").matcher(from).find();
- }
- @Override
- public String tagName() {
- return "<removeMentions>";
- }
- @Override
- public int argsRequired() {
- return 0;
- }
- @Override
- public String usage() {
- return null;
- }
- @Override
- public String desc() {
- return "Removes mass mentions like Everyone and Here and turns role and user mentions into plain text.\n\n" +
- "**This is always in every Custom Command.**";
- }
- @Override
- public String handleTag(String from, CommandObject command, String args) {
- while (cont(from)) {
- from = execute(from, command, args);
- }
- from = from.replaceAll("(?i)@everyone", "**[REDACTED]**");
- from = from.replaceAll("(?i)@here", "**[REDACTED]**");
- return from;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement