Tweak some stuff relating to FormattedText, make invite not get escaped, ever

This commit is contained in:
Vankka 2022-04-12 13:18:56 +03:00
parent ad7bca010f
commit eba37d9b6f
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
4 changed files with 12 additions and 11 deletions

View File

@ -226,7 +226,7 @@ public class SendableDiscordMessageImpl implements SendableDiscordMessage {
throw new IllegalStateException("DiscordSRVApi not available");
}
this.replacements.put(PlaceholderService.PATTERN,
wrapFunction(matcher -> api.placeholderService().getResultAsString(matcher, context)));
wrapFunction(matcher -> api.placeholderService().getResultAsPlain(matcher, context)));
return this;
}

View File

@ -52,6 +52,6 @@ public interface PlaceholderService {
PlaceholderLookupResult lookupPlaceholder(@NotNull String placeholder, @NotNull Object... context);
Object getResult(@NotNull Matcher matcher, @NotNull Set<Object> context);
CharSequence getResultAsString(@NotNull Matcher matcher, @NotNull Set<Object> context);
CharSequence getResultAsPlain(@NotNull Matcher matcher, @NotNull Set<Object> context);
}

View File

@ -18,6 +18,7 @@
package com.discordsrv.common.invite;
import com.discordsrv.api.placeholder.FormattedText;
import com.discordsrv.api.placeholder.annotation.Placeholder;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.config.main.DiscordInviteConfig;
@ -92,7 +93,7 @@ public class DiscordInviteModule extends AbstractModule<DiscordSRV> {
}
@Placeholder("discord_invite")
public String getInvite() {
return invite != null ? invite : UNKNOWN_INVITE;
public CharSequence getInvite() {
return new FormattedText(invite != null ? invite : UNKNOWN_INVITE);
}
}

View File

@ -175,16 +175,16 @@ public class PlaceholderServiceImpl implements PlaceholderService {
}
@Override
public CharSequence getResultAsString(@NotNull Matcher matcher, @NotNull Set<Object> context) {
public CharSequence getResultAsPlain(@NotNull Matcher matcher, @NotNull Set<Object> context) {
Object result = getResult(matcher, context);
return getResultAsString(result);
return getResultAsPlain(result);
}
private CharSequence getResultAsString(Object result) {
private CharSequence getResultAsPlain(Object result) {
if (result == null) {
return "";
} else if (result instanceof CharSequence) {
return result.toString();
return (CharSequence) result;
}
Object output = null;
@ -213,7 +213,7 @@ public class PlaceholderServiceImpl implements PlaceholderService {
private String updateContent(List<PlaceholderLookupResult> results, String placeholder, Matcher matcher, String input) {
Object representation = getResultRepresentation(results, placeholder, matcher);
CharSequence output = getResultAsString(representation);
CharSequence output = getResultAsPlain(representation);
if (output == null) {
output = String.valueOf(representation);
}
@ -241,9 +241,9 @@ public class PlaceholderServiceImpl implements PlaceholderService {
case SUCCESS:
replacement = result.getValue();
if (replacement == null) {
replacement = getResultAsString(null);
replacement = getResultAsPlain(null);
}
if (StringUtils.isNotBlank(getResultAsString(replacement))) {
if (StringUtils.isNotBlank(getResultAsPlain(replacement))) {
return replacement;
}
break;