package com.blamejared.mcbot.commands.api;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Accessors;
import sx.blah.discord.api.internal.json.objects.EmbedObject;

import com.blamejared.mcbot.MCBot;
import com.blamejared.mcbot.util.Nonnull;

@RequiredArgsConstructor
@Getter
public abstract class CommandBase implements ICommand {

    private final @Nonnull String name;
    @Accessors(fluent = true)
    private final boolean admin;

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + getName().hashCode();
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        
        CommandBase other = (CommandBase) obj;
        return getName().equals(other.getName());
    }
    
    private static final Pattern REGEX_MENTION = Pattern.compile("<@([0-9]+)>");
    
    public static String escapeMentions(String message){
    	Matcher matcher = REGEX_MENTION.matcher(message);
    	while (matcher.find()) {
    		message = message.replace(matcher.group(), MCBot.instance.getUserByID(matcher.group(1)).getName());
        }
        return message;
    }
    
    public static EmbedObject escapeMentions(EmbedObject embed) {
    	embed.title = escapeMentions(embed.title);
    	embed.description = escapeMentions(embed.description);
    	return embed;
    }
}

@@ -1114,16 +1114,18 @@
 pile(%22%3C@
+&?
 (%5B0-9%5D+)
@@ -1286,140 +1286,345 @@
   %09%09
-message = message.replace(matcher.group(), MCBot.instance.getUserByID(matcher.group(1)).getName());%0A        %7D%0A        return message
+String user = matcher.group().contains(%22&%22) ? %0A    %09%09%09%09%22the %22 + MCBot.instance.getRoleByID(matcher.group(1)).getName() : %0A    %09%09%09%09MCBot.instance.getUserByID(matcher.group(1)).getName();%0A%0A    %09%09message = message.replace(matcher.group(), user);%0A        %7D%0A        return message.replace(%22@here%22, %22everyone%22).replace(%22@everyone%22, %22everyone%22)
 ;%0A  

Fix escaping for non-user mentions