Chat/api/src/main/java/com/alttd/chat/managers/RegexManager.java

43 lines
1.1 KiB
Java
Raw Normal View History

2021-06-02 17:55:55 +00:00
package com.alttd.chat.managers;
2021-05-13 22:06:21 +00:00
2021-06-06 19:32:13 +00:00
import com.alttd.chat.config.RegexConfig;
import com.alttd.chat.objects.ChatFilter;
2021-06-13 11:53:49 +00:00
import com.alttd.chat.util.ALogger;
2021-06-06 19:32:13 +00:00
import java.util.ArrayList;
2021-06-06 19:32:13 +00:00
import java.util.List;
2021-05-20 16:45:26 +00:00
public class RegexManager {
2021-06-06 19:32:13 +00:00
private static List<ChatFilter> chatFilters;
2021-05-13 22:06:21 +00:00
2021-06-06 19:32:13 +00:00
public static void initialize() {
chatFilters = new ArrayList<>();
2021-06-06 19:32:13 +00:00
RegexConfig.init();
}
2021-06-06 19:32:13 +00:00
public static void addFilter(ChatFilter filter) {
chatFilters.add(filter);
}
2021-06-06 19:32:13 +00:00
public static String replaceText(String text) { // TODO loop all objects in the list and check if they violate based on the MATCHER
for(ChatFilter chatFilter : chatFilters) {
switch (chatFilter.getType()) {
2021-06-13 11:53:49 +00:00
case CHAT:
break;
2021-06-06 19:32:13 +00:00
case REPLACE:
text = chatFilter.replaceText(text);
break;
case BLOCK:
if(chatFilter.matches(text)) { // todo find a better way to do this?
return null;
}
break;
}
}
return text;
}
}