Skip to content

Commit

Permalink
Lotta stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
SwordOfSouls committed Nov 26, 2022
1 parent 6f6faed commit 51d4ad6
Show file tree
Hide file tree
Showing 16 changed files with 329 additions and 22 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import org.swordofsouls.discord.chatexporter.Html.Html;
import org.swordofsouls.discord.chatexporter.Html.HtmlFile;
import org.swordofsouls.discord.chatexporter.Utils.File.FileUtils;
import org.swordofsouls.discord.chatexporter.Utils.Time.TimeUtils;

import java.time.Instant;
import java.time.ZoneId;

public class BaseBuilder extends HtmlBase {
public BaseBuilder(HtmlFile file) {
Expand All @@ -11,6 +16,10 @@ public BaseBuilder(HtmlFile file) {
@Override
public HtmlFile build() {
file.replace("SD", "");
file.replace("CSS", "");
file.replace("MEDIA_BLOCK", "");
file.replace("INSERT_TOP", "");
file.replace("INSERT_PANEL", "");
return getFile();
}

Expand Down Expand Up @@ -50,4 +59,23 @@ public void setMessages(String messages) {
public void setMetaData(String metaData) {
file.replace("META_DATA", metaData);
}
public void setCustomCss(String css) {
file.replace("CSS", css);
}
public void setCustomMediaBlock(String mediaBlock) {
file.replace("MEDIA_BLOCK", mediaBlock);
}
public void setCustomTop(String htmlTop) {
file.replace("INSERT_TOP", htmlTop);
}
public void setCustomMiddle(String htmlMiddle) {
file.replace("INSERT_PANEL", htmlMiddle);
}
public void setCreationTime(Instant instant, ZoneId zone) {
file.replace("DATE_TIME", TimeUtils.getFullFormattedTime(instant, zone));
}
public void setOverflow(Integer overflow) {
file.replace("OVERFLOW", String.valueOf(overflow));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.swordofsouls.discord.chatexporter.Html.Builders.Components;

import org.swordofsouls.discord.chatexporter.Html.Builders.HtmlBase;
import org.swordofsouls.discord.chatexporter.Html.HtmlFile;

import java.awt.*;

public class ButtonBuilder extends HtmlBase {
public ButtonBuilder(HtmlFile file) {
super(file);
}

public void setColor(Color color) {
file.replace("STYLE", String.format("#%02x%02x%02x", color.getRed(), color.getGreen(),color.getBlue()));
}
public void setDisabled(Boolean value) {
if(value) file.replace("DISABLED", "chatlog__component-disabled");
}
public void setUrl(String url) {
file.replace("URL", url);
}
public void setEmoji(String emoji) {
file.replace("EMOJI", emoji);
}
public void setLabel(String label) {
file.replace("LABEL", label);
}
public void setIcon(String icon) {
file.replace("ICON", icon);
}

@Override
public HtmlFile build() {
file.replace("DISABLED","");
file.replace("URL","");
file.replace("ICON","");
file.replace("LABEL","");
file.replace("EMOJI","");
return getFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public MessageBuilder(HtmlFile file) {
}

public void setTimestamp(Instant instant, ZoneId timeZone) {
file.replace("TIME", instant.atZone(timeZone).format(DateTimeFormatter.ofPattern("HH:mm a")));
file.replace("TIMESTAMP", instant.atZone(timeZone).format(DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm a")));
file.replace("TIME", instant.atZone(timeZone).format(DateTimeFormatter.ofPattern("hh:mm a")));
file.replace("TIMESTAMP", instant.atZone(timeZone).format(DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm a")));
}

}
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
package org.swordofsouls.discord.chatexporter.Html.Builders.Message;

import jdk.jfr.ContentType;
import org.javacord.api.entity.Attachment;
import org.javacord.api.entity.message.MessageAttachment;
import org.javacord.api.entity.message.component.ActionRow;
import org.javacord.api.entity.message.component.Button;
import org.javacord.api.entity.message.component.HighLevelComponent;
import org.javacord.api.entity.message.component.LowLevelComponent;
import org.javacord.api.entity.message.embed.Embed;
import org.javacord.api.entity.message.embed.EmbedAuthor;
import org.javacord.api.entity.message.embed.EmbedField;
import org.javacord.api.entity.message.embed.EmbedFooter;
import org.swordofsouls.discord.chatexporter.Html.Builders.Components.ButtonBuilder;
import org.swordofsouls.discord.chatexporter.Html.Builders.HtmlBase;
import org.swordofsouls.discord.chatexporter.Html.Html;
import org.swordofsouls.discord.chatexporter.Html.HtmlFile;
import org.swordofsouls.discord.chatexporter.Utils.Color.ButtonStyleUtils;
import org.swordofsouls.discord.chatexporter.Utils.File.FileUtils;
import org.swordofsouls.discord.chatexporter.Utils.Time.TimeUtils;

import java.awt.datatransfer.MimeTypeParseException;
import java.time.Instant;
import java.time.ZoneId;
import java.util.List;

public class MessageCore extends HtmlBase {
public MessageCore(HtmlFile file) {
super(file);
file.replace("ATTACHMENTS","");
file.replace("COMPONENTS","");
file.replace("EMOJI","");
}

@Override
public HtmlFile build() {
file.replace("EDIT","");
return getFile();
}

public void setMessageId(Long messageId) {
file.replace("MESSAGE_ID", messageId.toString());
}
public void setContent(String content) {
file.replace("MESSAGE_CONTENT", content);
HtmlFile messageContentLineF = Html.Message.CONTENT();
messageContentLineF.replace("MESSAGE_CONTENT", content);
file.replace("MESSAGE_CONTENT", messageContentLineF.getContent());
}
public void setEmbeds(List<Embed> embeds) {
StringBuilder embedStringBuilder = new StringBuilder();
Expand Down Expand Up @@ -93,4 +108,77 @@ public void setEmbeds(List<Embed> embeds) {
}
file.replace("EMBEDS", embedStringBuilder.toString());
}
public void setComponents(List<HighLevelComponent> components) {
StringBuilder componentStringBuilder = new StringBuilder();
for(HighLevelComponent component : components) {
if(component.asActionRow().isPresent()) {
ActionRow row = component.asActionRow().get();
for(LowLevelComponent lowLevelComponent : row.getComponents()) {
if(lowLevelComponent.isButton() && lowLevelComponent.asButton().isPresent()) {
Button button = lowLevelComponent.asButton().get();
ButtonBuilder buttonBuilder = new ButtonBuilder(Html.Component.BUTTON());
boolean disabled;
if(button.isDisabled().isPresent()) disabled = button.isDisabled().get();
else disabled = false;
buttonBuilder.setColor(ButtonStyleUtils.buttonStyle(button.getStyle(), disabled));
buttonBuilder.setDisabled(disabled);
if(button.getLabel().isPresent()) buttonBuilder.setLabel(button.getLabel().get());
if(button.getUrl().isPresent()) buttonBuilder.setUrl(button.getUrl().get());
if(button.getEmoji().isPresent()) {
if(button.getEmoji().get().asUnicodeEmoji().isPresent()) buttonBuilder.setEmoji(button.getEmoji().get().asUnicodeEmoji().get());
}
componentStringBuilder.append(buttonBuilder.build().getContent());
}
}
}
}
file.replace("COMPONENTS",componentStringBuilder.toString());
}
public void setEditedTimestamp(Instant instant, ZoneId zone) {
HtmlFile edit = Html.Message.EDITED();
edit.replace("TIMESTAMP", TimeUtils.getFullFormattedTime(instant, zone));
file.replace("EDIT", edit.getContent());
}
public void setAttachments(List<MessageAttachment> attachments) {
StringBuilder attachmentBuilder = new StringBuilder();
for(MessageAttachment attachment : attachments) {
String extension = attachment.getFileName().split("\\.",2)[1];
String icon = FileUtils.getIcon(attachment.getFileName());
if(FileUtils.IMAGE_TYPES.contains(extension)) {
HtmlFile image = Html.Attachment.IMAGE();
image.replace("ATTACH_URL", attachment.getUrl().toString());
image.replace("ATTACH_URL_THUMB", attachment.getUrl().toString());
attachmentBuilder.append(image.getContent());
continue;
}
if(FileUtils.DOCUMENT_TYPES.contains(extension) || FileUtils.ACROBAT_TYPES.contains(extension)
|| FileUtils.CODE_TYPES.contains(extension) || FileUtils.WEBCODE_TYPES.contains(extension)) {
HtmlFile image = Html.Attachment.MESSAGE();
image.replace("ATTACH_URL", attachment.getUrl().toString());
image.replace("ATTACH_BYTES",
org.apache.commons.io.FileUtils.byteCountToDisplaySize(attachment.getSize()));
image.replace("ATTACH_FILE", attachment.getFileName());
image.replace("ATTACH_ICON", icon);
attachmentBuilder.append(image.getContent());
continue;
}
if(FileUtils.VIDEO_TYPES.contains(extension)) {
HtmlFile image = Html.Attachment.VIDEO();
image.replace("ATTACH_URL", attachment.getUrl().toString());
attachmentBuilder.append(image.getContent());
continue;
}
if(FileUtils.AUDIO_TYPES.contains(extension)) {
HtmlFile image = Html.Attachment.AUDIO();
image.replace("ATTACH_ICON", icon);
image.replace("ATTACH_URL", attachment.getUrl().toString());
image.replace("ATTACH_BYTES",
org.apache.commons.io.FileUtils.byteCountToDisplaySize(attachment.getSize()));
image.replace("ATTACH_AUDIO", attachment.getUrl().toString());
image.replace("ATTACH_FILE", attachment.getFileName());
attachmentBuilder.append(image.getContent());
}
}
file.replace("ATTACHMENTS", attachmentBuilder.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ public void setBot(String botTag) {
file.replace("BOT_TAG", botTag);
}
public void setTimestamp(Instant instant, ZoneId timeZone) {
file.replace("TIME", instant.atZone(timeZone).format(DateTimeFormatter.ofPattern("HH:mm a")));
file.replace("TIME", instant.atZone(timeZone).format(DateTimeFormatter.ofPattern("hh:mm a")));
file.replace("TIMESTAMP", TimeUtils.getFullFormattedTime(instant, timeZone));
file.replace("DEFAULT_TIMESTAMP",
instant.atZone(timeZone).format(DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm a")));
instant.atZone(timeZone).format(DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm a")));
}

@Override
public HtmlFile build() {
super.build();
file.replace("USER_ICON","");
file.replace("REFERENCE","");
file.replace("REFERENCE_SYMBOL","");
file.replace("USER_COLOUR","");
return getFile();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.swordofsouls.discord.chatexporter.Html.Builders.Message;

import org.swordofsouls.discord.chatexporter.Html.Builders.HtmlBase;
import org.swordofsouls.discord.chatexporter.Html.HtmlFile;
import org.swordofsouls.discord.chatexporter.Utils.File.FileUtils;

import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class PinMessageBuilder extends HtmlBase {
public PinMessageBuilder(HtmlFile file) {
super(file);
file.replace("PIN_URL", FileUtils.PINNED_MESSAGE_ICON);
}

@Override
public HtmlFile build() {
return getFile();
}

public void setMessageId(Long messageId) {
file.replace("MESSAGE_ID", messageId.toString());
}
public void setRefMessageId(Long refMessageId) {
file.replace("REF_MESSAGE_ID", refMessageId.toString());
}
public void setName(String name) {
file.replace("NAME_TAG", name);
file.replace("NAME", name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static final class Bot {
public static HtmlFile REFERENCE_UNKNOWN() { return new HtmlFile(ROOT +"reference_unknown"); }
public static HtmlFile START() { return new HtmlFile(ROOT +"start"); }
public static HtmlFile THREAD() { return new HtmlFile(ROOT +"thread"); }
public static HtmlFile EDITED() { return new HtmlFile(ROOT +"edited"); }
}
public static final class Reaction {
public static final String ROOT = "Reaction/";
Expand Down
Loading

0 comments on commit 51d4ad6

Please sign in to comment.