Search in sources :

Example 1 with DynamicConfig

use of github.scarsz.configuralize.DynamicConfig in project DiscordSRV by Scarsz.

the class ConsoleMessage method toString.

@Override
public String toString() {
    if (formatted != null)
        return formatted;
    String line = this.line;
    final DynamicConfig config = DiscordSRV.config();
    // return if this is not an okay level to send
    boolean isAnOkayLevel = false;
    for (String enabledLevel : config.getStringList("DiscordConsoleChannelLevels")) {
        if (eventLevel.equals(enabledLevel.toUpperCase())) {
            isAnOkayLevel = true;
            break;
        }
    }
    if (!isAnOkayLevel)
        return null;
    // remove coloring
    line = DiscordUtil.aggressiveStrip(line);
    line = MessageUtil.strip(line);
    // do nothing if line is blank before parsing
    if (StringUtils.isBlank(line))
        return null;
    // apply regex to line
    for (Map.Entry<Pattern, String> entry : DiscordSRV.getPlugin().getConsoleRegexes().entrySet()) {
        line = entry.getKey().matcher(line).replaceAll(entry.getValue());
        if (StringUtils.isBlank(line))
            return null;
    }
    // escape markdown
    line = DiscordUtil.escapeMarkdown(line);
    // trim
    line = line.trim();
    String timestamp = TimeUtil.timeStamp();
    String formattedMessage = PlaceholderUtil.replacePlaceholdersToDiscord(LangUtil.Message.CONSOLE_CHANNEL_LINE.toString()).replace("%date%", timestamp).replace("%datetime%", timestamp).replace("%level%", eventLevel).replace("%line%", line);
    this.formatted = formattedMessage;
    return formattedMessage;
}
Also used : Pattern(java.util.regex.Pattern) DynamicConfig(github.scarsz.configuralize.DynamicConfig) Map(java.util.Map)

Aggregations

DynamicConfig (github.scarsz.configuralize.DynamicConfig)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1