From 1421d52598e17da3b8e146902157f3c56f672204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Mon, 19 Dec 2022 21:58:57 +0100 Subject: [PATCH] Keep newlines in urban dictionary parser --- .../commands/message/UrbanDictionaryCommand.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/UrbanDictionaryCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/UrbanDictionaryCommand.java index 947feb0..75e5151 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/UrbanDictionaryCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/UrbanDictionaryCommand.java @@ -102,13 +102,21 @@ public class UrbanDictionaryCommand implements MessageCommand for(String htmlMeaning : htmlMeanings) { - String text = htmlMeaning.replaceAll("<.*?>", ""); + String text = htmlMeaning + .replaceAll("", "\n") // keep newlines + .replaceAll("<.*?>", ""); // remove all other html tags + // discord only allows 1024 characters for embed fields + if(text.length() > 1024) text = text.substring(0, 1023); plaintextMeanings.add(text); } for(String htmlExample : htmlExamples) { - String text = htmlExample.replaceAll("<.*?>", ""); + String text = htmlExample + .replaceAll("", "\n") // keep newlines + .replaceAll("<.*?>", ""); // remove all other html tags + // discord only allows 1024 characters for embed fields + if(text.length() > 1024) text = text.substring(0, 1023); plaintextExamples.add(text); }