Push progress
This commit is contained in:
@@ -1,32 +1,63 @@
|
||||
package com.alttd.chat.objects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ChatFilter {
|
||||
|
||||
private final String regex;
|
||||
private final FilterType type;
|
||||
private String replacement = "";
|
||||
private final Properties properties = new Properties();
|
||||
private final Pattern pattern;
|
||||
private final FilterType filterType;
|
||||
|
||||
public ChatFilter(String regex, FilterType type) {
|
||||
this.regex = regex;
|
||||
this.type = type;
|
||||
public ChatFilter(Map<String, Object> props) {
|
||||
addDefaults();
|
||||
properties.keySet().stream().filter(props::containsKey).forEach((nkey) -> properties.put(nkey, props.get(nkey)));
|
||||
pattern = Pattern.compile(getRegex());
|
||||
filterType = FilterType.getType((String) properties.get("type"));
|
||||
}
|
||||
|
||||
public ChatFilter(String regex, FilterType type, String replacement) {
|
||||
this.regex = regex;
|
||||
this.type = type;
|
||||
this.replacement = replacement;
|
||||
private void addDefaults() {
|
||||
properties.put("name", "");
|
||||
properties.put("type", null);
|
||||
properties.put("regex", "");
|
||||
properties.put("replacement", "");
|
||||
properties.put("exclusions", new ArrayList<String>());
|
||||
}
|
||||
|
||||
public String getRegex() {
|
||||
return regex;
|
||||
return (String) properties.get("regex");
|
||||
}
|
||||
|
||||
public FilterType getType() {
|
||||
return type;
|
||||
return filterType;
|
||||
}
|
||||
|
||||
public String getReplacement() {
|
||||
return replacement;
|
||||
return (String) properties.get("replacement");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> getExclusions() {
|
||||
return (List<String>) properties.get("exclusions");
|
||||
}
|
||||
|
||||
public boolean matches(String input) {
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
public String replaceText(String input) {
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
while (matcher.find()) {
|
||||
String group = matcher.group();
|
||||
if(!getExclusions().contains(group)) { // doesn't work well with capitals, use a stream filter?
|
||||
input = input.replace(group, getReplacement());
|
||||
}
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public class ChatUser {
|
||||
private String prefixAll;
|
||||
private boolean toggleGc;
|
||||
private UUID replyTarget;
|
||||
private long gcCooldown;
|
||||
|
||||
private LinkedList<Mail> mails;
|
||||
|
||||
@@ -38,6 +39,7 @@ public class ChatUser {
|
||||
|
||||
toggleGc = toggle_Gc;
|
||||
replyTarget = null;
|
||||
gcCooldown = System.currentTimeMillis(); //
|
||||
mails = new LinkedList<>(); // todo load mails
|
||||
}
|
||||
|
||||
@@ -122,4 +124,8 @@ public class ChatUser {
|
||||
public void addMail(Mail mail) {
|
||||
mails.add(mail);
|
||||
}
|
||||
|
||||
public long getGcCooldown() {
|
||||
return gcCooldown;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user