fix newlines

This commit is contained in:
2024-08-12 22:31:24 +02:00
parent 6396892913
commit 2b847a02b3
3 changed files with 25 additions and 7 deletions
@@ -0,0 +1,13 @@
package me.youhavetrouble.noted;
public class MessageUtil {
public static String fixNewlines(String input) {
return input.replaceAll("\\\\n", "\n");
}
public static String formatForDiscord(String string) {
return fixNewlines(string);
}
}
@@ -1,6 +1,7 @@
package me.youhavetrouble.noted.command; package me.youhavetrouble.noted.command;
import me.youhavetrouble.noted.Main; import me.youhavetrouble.noted.Main;
import me.youhavetrouble.noted.MessageUtil;
import me.youhavetrouble.noted.Storage; import me.youhavetrouble.noted.Storage;
import me.youhavetrouble.noted.note.Note; import me.youhavetrouble.noted.note.Note;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
@@ -83,7 +84,10 @@ public class AddNoteCommand extends Command {
return; return;
} }
Note note = Note.createNew(titleOption.getAsString(), contentOption.getAsString()); Note note = Note.createNew(
MessageUtil.formatForDiscord(titleOption.getAsString()),
MessageUtil.formatForDiscord(contentOption.getAsString())
);
OptionMapping titleUrlOption = event.getOption("title-url"); OptionMapping titleUrlOption = event.getOption("title-url");
if (titleUrlOption != null) { if (titleUrlOption != null) {
@@ -114,7 +118,7 @@ public class AddNoteCommand extends Command {
OptionMapping authorOption = event.getOption("author"); OptionMapping authorOption = event.getOption("author");
if (authorOption != null) { if (authorOption != null) {
note = note.withAuthor(authorOption.getAsString()); note = note.withAuthor(MessageUtil.formatForDiscord(authorOption.getAsString()));
} }
OptionMapping authorUrlOption = event.getOption("author-url"); OptionMapping authorUrlOption = event.getOption("author-url");
@@ -124,7 +128,7 @@ public class AddNoteCommand extends Command {
OptionMapping footerOption = event.getOption("footer"); OptionMapping footerOption = event.getOption("footer");
if (footerOption != null) { if (footerOption != null) {
note = note.withFooter(footerOption.getAsString()); note = note.withFooter(MessageUtil.formatForDiscord(footerOption.getAsString()));
} }
OptionMapping footerUrlOption = event.getOption("footer-url"); OptionMapping footerUrlOption = event.getOption("footer-url");
@@ -1,6 +1,7 @@
package me.youhavetrouble.noted.command; package me.youhavetrouble.noted.command;
import me.youhavetrouble.noted.Main; import me.youhavetrouble.noted.Main;
import me.youhavetrouble.noted.MessageUtil;
import me.youhavetrouble.noted.Storage; import me.youhavetrouble.noted.Storage;
import me.youhavetrouble.noted.note.Note; import me.youhavetrouble.noted.note.Note;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
@@ -122,7 +123,7 @@ public class EditNoteCommand extends Command {
OptionMapping titleOption = event.getOption("title"); OptionMapping titleOption = event.getOption("title");
if (titleOption != null) { if (titleOption != null) {
note = note.withTitle(titleOption.getAsString()); note = note.withTitle(MessageUtil.formatForDiscord(titleOption.getAsString()));
} }
OptionMapping titleUrlOption = event.getOption("title-url"); OptionMapping titleUrlOption = event.getOption("title-url");
@@ -132,7 +133,7 @@ public class EditNoteCommand extends Command {
OptionMapping contentOption = event.getOption("content"); OptionMapping contentOption = event.getOption("content");
if (contentOption != null) { if (contentOption != null) {
note = note.withContent(contentOption.getAsString()); note = note.withContent(MessageUtil.formatForDiscord(contentOption.getAsString()));
} }
OptionMapping imageUrlOption = event.getOption("image-url"); OptionMapping imageUrlOption = event.getOption("image-url");
@@ -159,7 +160,7 @@ public class EditNoteCommand extends Command {
OptionMapping authorOption = event.getOption("author"); OptionMapping authorOption = event.getOption("author");
if (authorOption != null) { if (authorOption != null) {
note = note.withAuthor(authorOption.getAsString()); note = note.withAuthor(MessageUtil.formatForDiscord(authorOption.getAsString()));
} }
OptionMapping authorUrlOption = event.getOption("author-url"); OptionMapping authorUrlOption = event.getOption("author-url");
@@ -169,7 +170,7 @@ public class EditNoteCommand extends Command {
OptionMapping footerOption = event.getOption("footer"); OptionMapping footerOption = event.getOption("footer");
if (footerOption != null) { if (footerOption != null) {
note = note.withFooter(footerOption.getAsString()); note = note.withFooter(MessageUtil.formatForDiscord(footerOption.getAsString()));
} }
OptionMapping footerUrlOption = event.getOption("footer-url"); OptionMapping footerUrlOption = event.getOption("footer-url");