You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
newOptionData(OptionType.STRING,"auto-indent","The type of indentation that should be applied to the message, does not automatically indent if left blank",false)
@@ -74,7 +76,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
74
76
.filter(m -> !m.getAuthor().isBot()).findFirst()
75
77
.orElse(null);
76
78
if (target != null) {
77
-
event.getHook().sendMessageFormat("```%s\n%s\n```", format, StringUtils.standardSanitizer().compute(target.getContentRaw()))
79
+
event.getHook().sendMessageFormat("```%s\n%s\n```", format, IndentationHelper.formatIndentation(StringUtils.standardSanitizer().compute(target.getContentRaw()),IndentationHelper.IndentationType.valueOf(indentation)))
78
80
.setAllowedMentions(List.of())
79
81
.setComponents(buildActionRow(target))
80
82
.queue();
@@ -89,7 +91,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
* Utility class to help indent strings that contain code.
5
+
*/
6
+
publicclassIndentationHelper {
7
+
/**
8
+
* Enum which denotes the different types of indentation possible.
9
+
* When {@link #NULL} is passed to any method in this class, the output of said method should match the input.
10
+
*/
11
+
publicenumIndentationType {
12
+
/**
13
+
* A tab character (\t) should be used for indentation.
14
+
*/
15
+
TABS("\t"),
16
+
/**
17
+
* Four spaces should be used for indentation.
18
+
*/
19
+
FOUR_SPACES(" "),
20
+
/**
21
+
* Two spaces should be used for indentation
22
+
*/
23
+
TWO_SPACES(" "),
24
+
/**
25
+
* Doesn't define an indentation type but
26
+
* Is used as a substitute to null to indicate that a String given to any method in {@link IndentationHelper} should not be changed.
27
+
*/
28
+
NULL("");
29
+
30
+
/**
31
+
* Holds the characters used for indentation of the type.
32
+
*/
33
+
privatefinalStringpattern;
34
+
35
+
/**
36
+
* Constructs the indentation type
37
+
* @param pattern The pattern to be used as indentation
38
+
*/
39
+
IndentationType(Stringpattern) {
40
+
this.pattern = pattern;
41
+
}
42
+
43
+
/**
44
+
* Get the pattern for a given Indentation type.
45
+
* @return the pattern to be used for indenting.
46
+
*/
47
+
publicStringgetPattern() {
48
+
returnpattern;
49
+
}
50
+
51
+
/**
52
+
* Returns the number of characters a pattern is using.
53
+
* @return the number of characters the pattern of this type consists of.
54
+
*/
55
+
privateintgetNumberOfChars() {
56
+
returnpattern.length();
57
+
}
58
+
59
+
}
60
+
61
+
/**
62
+
* Aims to indent the given String using the pattern provided. Will return the String unchanged if {@link IndentationHelper.IndentationType#NULL} is passed as the IndentationType parameter.
63
+
* @param text The text that should be indented.
64
+
* @param type The type of indentation to be used.
65
+
* @return The indented String with the format specified.
assertEquals(formatted[k++], IndentationHelper.formatIndentation(unformatted[i], IndentationHelper.IndentationType.FOUR_SPACES),"Method failed to format a text with four spaces correctly");
35
+
assertEquals(formatted[k++], IndentationHelper.formatIndentation(unformatted[i], IndentationHelper.IndentationType.TWO_SPACES),"Method failed to format a text with two spaces correctly");
36
+
assertEquals(formatted[k++], IndentationHelper.formatIndentation(unformatted[i], IndentationHelper.IndentationType.TABS), "Method failed to format a text with tabs correctly.");
37
+
assertEquals(formatted[k++], IndentationHelper.formatIndentation(unformatted[i], IndentationHelper.IndentationType.NULL), "Method returned a String not matching the input");
0 commit comments