From 2c87d1c8e687a4abc6fe4b849f458c1dabe4fdd0 Mon Sep 17 00:00:00 2001 From: EazyFTW Date: Sun, 23 Aug 2020 12:49:52 -0500 Subject: [PATCH] Removed tickets. --- .../module/modules/TicketModule.java | 18 +-- .../TechDiscordBot/tickets/ChatMessage.java | 29 ----- .../tickets/EmbedChatMessage.java | 39 ------ .../tickets/TranscriptBuilder.java | 119 ------------------ .../tickets/TranscriptMessage.java | 49 -------- 5 files changed, 2 insertions(+), 252 deletions(-) delete mode 100644 src/main/java/me/TechsCode/TechDiscordBot/tickets/ChatMessage.java delete mode 100644 src/main/java/me/TechsCode/TechDiscordBot/tickets/EmbedChatMessage.java delete mode 100644 src/main/java/me/TechsCode/TechDiscordBot/tickets/TranscriptBuilder.java delete mode 100644 src/main/java/me/TechsCode/TechDiscordBot/tickets/TranscriptMessage.java diff --git a/src/main/java/me/TechsCode/TechDiscordBot/module/modules/TicketModule.java b/src/main/java/me/TechsCode/TechDiscordBot/module/modules/TicketModule.java index ef7ea93a..36324a60 100644 --- a/src/main/java/me/TechsCode/TechDiscordBot/module/modules/TicketModule.java +++ b/src/main/java/me/TechsCode/TechDiscordBot/module/modules/TicketModule.java @@ -6,7 +6,6 @@ import me.TechsCode.TechDiscordBot.objects.Query; import me.TechsCode.TechDiscordBot.objects.Requirement; import me.TechsCode.TechDiscordBot.objects.TicketPriority; -import me.TechsCode.TechDiscordBot.tickets.TranscriptBuilder; import me.TechsCode.TechDiscordBot.util.Plugin; import me.TechsCode.TechDiscordBot.util.TechEmbedBuilder; import net.dv8tion.jda.api.Permission; @@ -391,15 +390,9 @@ public void onMessageCmd(GuildMessageReceivedEvent e) { } else if(e.getMessage().getContentDisplay().startsWith("!close")) { e.getMessage().delete().submit(); if (isTicketCreator) { - TranscriptBuilder.Builder ticket = new TranscriptBuilder.Builder() - .channel(e.getChannel()) - .member(e.getMember()) - .password() - .upload(). - message(); new TechEmbedBuilder("Ticket") - .setText("Thank you for contacting us " + e.getAuthor().getAsMention() + ". Consider writing a review if you enjoyed the support!\n\n**Here is the transcript**:\n" + ticket.getUrl()) + .setText("Thank you for contacting us " + e.getAuthor().getAsMention() + ". Consider writing a review if you enjoyed the support!") .send(e.getChannel()); e.getChannel().delete().completeAfter(15, TimeUnit.SECONDS); @@ -423,15 +416,8 @@ public void onMessageCmd(GuildMessageReceivedEvent e) { String reason = String.join(" ", Arrays.copyOfRange(reasons, 1, reasons.length)); String reasonSend = (hasReason ? " \n \n**Reason**: " + reason : ""); - TranscriptBuilder.Builder ticket = new TranscriptBuilder.Builder() - .channel(e.getChannel()) - .member(member) - .password() - .upload(). - message(); - new TechEmbedBuilder("Ticket") - .setText(e.getAuthor().getAsMention() + " has closed this support ticket." + reasonSend + "\n\n**Here is the transcript**:" + ticket.getUrl()) + .setText(e.getAuthor().getAsMention() + " has closed this support ticket." + reasonSend) .send(e.getChannel()); e.getChannel().delete().completeAfter(15, TimeUnit.SECONDS); diff --git a/src/main/java/me/TechsCode/TechDiscordBot/tickets/ChatMessage.java b/src/main/java/me/TechsCode/TechDiscordBot/tickets/ChatMessage.java deleted file mode 100644 index a9734659..00000000 --- a/src/main/java/me/TechsCode/TechDiscordBot/tickets/ChatMessage.java +++ /dev/null @@ -1,29 +0,0 @@ -package me.TechsCode.TechDiscordBot.tickets; - -public class ChatMessage { - - private final String from, content, timestamp, avatarURL; - - public ChatMessage(String from, String content, String timestamp, String avatarURL) { - this.from = from; - this.content = content; - this.timestamp = timestamp; - this.avatarURL = avatarURL; - } - - public String getFrom() { - return from; - } - - public String getContent() { - return content; - } - - public String getTimestamp() { - return timestamp; - } - - public String getAvatarURL() { - return avatarURL; - } -} diff --git a/src/main/java/me/TechsCode/TechDiscordBot/tickets/EmbedChatMessage.java b/src/main/java/me/TechsCode/TechDiscordBot/tickets/EmbedChatMessage.java deleted file mode 100644 index 6b903992..00000000 --- a/src/main/java/me/TechsCode/TechDiscordBot/tickets/EmbedChatMessage.java +++ /dev/null @@ -1,39 +0,0 @@ -package me.TechsCode.TechDiscordBot.tickets; - -public class EmbedChatMessage { - - private final String from, title, content, color, avatarURL, timestamp; - - public EmbedChatMessage(String from, String title, String content, String color, String avatarURL, String timestamp) { - this.from = from; - this.title = title; - this.content = content; - this.color = color; - this.avatarURL = avatarURL; - this.timestamp = timestamp; - } - - public String getFrom() { - return from; - } - - public String getTitle() { - return title; - } - - public String getContent() { - return content; - } - - public String getColor() { - return color; - } - - public String getAvatarURL() { - return avatarURL; - } - - public String getTimestamp() { - return timestamp; - } -} diff --git a/src/main/java/me/TechsCode/TechDiscordBot/tickets/TranscriptBuilder.java b/src/main/java/me/TechsCode/TechDiscordBot/tickets/TranscriptBuilder.java deleted file mode 100644 index b99917f3..00000000 --- a/src/main/java/me/TechsCode/TechDiscordBot/tickets/TranscriptBuilder.java +++ /dev/null @@ -1,119 +0,0 @@ -package me.TechsCode.TechDiscordBot.tickets; - -import me.TechsCode.TechDiscordBot.TechDiscordBot; -import me.TechsCode.TechDiscordBot.mysql.storage.Transcript; -import me.TechsCode.TechDiscordBot.objects.DefinedQuery; -import me.TechsCode.TechDiscordBot.objects.Query; -import me.TechsCode.TechDiscordBot.util.PasswordGenerator; -import me.TechsCode.TechDiscordBot.util.TechEmbedBuilder; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.TextChannel; -import org.jsoup.helper.Validate; - -import java.util.Collections; -import java.util.List; - -public class TranscriptBuilder { - - public static class Builder { - - private String html, password, channelId; - private Member member; - - private static final DefinedQuery TRANSCRIPTS_CHANNEL = new DefinedQuery() { - @Override - protected Query newQuery() { return TechDiscordBot.getBot().getChannels("transcripts"); } - }; - - public Builder() {} - - public Builder channel(TextChannel channel) { - Validate.notNull(channel, "Channel cannot be null!"); - this.channelId = channel.getId(); - String channelName = channel.getName(); - List messages = channel.getHistory().retrievePast(100).complete(); - Collections.reverse(messages); - StringBuilder html = new StringBuilder(); - html.append("").append("#%CHANNEL_NAME% - {GUILD_NAME}"); - html.append("").append(""); - for(Message message : messages) { - html.append("
"); - TranscriptMessage msg = new TranscriptMessage(message); - if(msg.isNormal()) { - ChatMessage chatMessage = msg.getChatMessage(); - String data = "
{USERNAME}{TIMESTAMP}
{MESSAGE}
"; - data = data.replace("{USERNAME}", chatMessage.getFrom()).replace("{TIMESTAMP}", chatMessage.getTimestamp()).replace("{AVATAR}", chatMessage.getAvatarURL()).replace("{MESSAGE}", chatMessage.getContent()); - html.append(data); - } else { - EmbedChatMessage chatMessage = msg.getEmbedChatMessage(); - String data = "
{USERNAME}{TIMESTAMP}
{TITLE}: {MESSAGE}
"; - data = data.replace("{USERNAME}", chatMessage.getFrom()).replace("{TIMESTAMP}", chatMessage.getTimestamp()).replace("{AVATAR}", chatMessage.getAvatarURL()).replace("{MESSAGE}", chatMessage.getContent()).replace("{COLOR}", chatMessage.getColor()).replace("{TITLE}", chatMessage.getTitle()); - html.append(data); - } - html.append("
"); - html.append("
"); - } - - html.append("").append(""); - html.append("").append(""); - String finished = html.toString(); - finished = finished.replace("%CHANNEL_NAME%", channelName).replace("{GUILD_NAME}", TechDiscordBot.getGuild().getName()); - this.html = finished; - return this; - } - - public Builder member(Member member) { - this.member = member; - return this; - } - - public Builder password(int length) { - this.password = new PasswordGenerator.PasswordGeneratorBuilder() - .useUpper(true) - .useLower(true) - .useDigits(true) - .build() - .generate(length); - return this; - } - - public Builder password() { - return password(10); - } - - public Builder password(String password) { - this.password = password; - return this; - } - - public String getPassword() { - return this.password; - } - - public String getHtml() { - return this.html; - } - - public String getChannelId() { - return this.channelId; - } - - public String getUrl() { - return "https://tickets.techscode.de/" + this.channelId + "/" + this.password; - } - - public Builder message() { - new TechEmbedBuilder("New Transcript") - .setText((this.member == null ? "Unknown" : member.getAsMention()) + "'s Ticket Transcript.\n\nhttps://tickets.techscode.de/" + this.channelId + "/" + this.password) - .send(TRANSCRIPTS_CHANNEL.query().first()); - return this; - } - - public Builder upload() { - Transcript transcript = new Transcript(this.channelId, this.html, this.password); - TechDiscordBot.getStorage().uploadTranscript(transcript); - return this; - } - } -} \ No newline at end of file diff --git a/src/main/java/me/TechsCode/TechDiscordBot/tickets/TranscriptMessage.java b/src/main/java/me/TechsCode/TechDiscordBot/tickets/TranscriptMessage.java deleted file mode 100644 index d4e7ee61..00000000 --- a/src/main/java/me/TechsCode/TechDiscordBot/tickets/TranscriptMessage.java +++ /dev/null @@ -1,49 +0,0 @@ -package me.TechsCode.TechDiscordBot.tickets; - -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageEmbed; - -import java.awt.*; -import java.time.OffsetDateTime; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; - -public class TranscriptMessage { - - private EmbedChatMessage embedChatMessage; - private ChatMessage chatMessage; - - public TranscriptMessage(Message message) { - String avatarURL = message.getAuthor().getAvatarUrl() != null ? message.getAuthor().getAvatarUrl() : "https://i.imgur.com/nnegGEV.png"; - if(message.getEmbeds().size() == 0) { - this.chatMessage = new ChatMessage(message.getAuthor().getName(), message.getContentDisplay(), getDate(message.getTimeCreated()), avatarURL); - } else { - MessageEmbed embed = message.getEmbeds().get(0); - MessageEmbed.AuthorInfo authorInfo = embed.getAuthor(); - Color color = embed.getColor() != null ? embed.getColor() : new Color(91, 107, 113); - this.embedChatMessage = new EmbedChatMessage(message.getAuthor().getName(), (authorInfo != null && authorInfo.getName() != null ? authorInfo.getName() : ""), (embed.getDescription() == null ? "" : embed.getDescription()), hexFromColor(color), avatarURL, getDate(message.getTimeCreated())); - } - } - - private String hexFromColor(Color color) { return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue()); } - - private String getDate(OffsetDateTime date) { - return date.format(DateTimeFormatter.ofPattern("MMMM dd, yyyy 'at' hh:mm a").withZone(ZoneOffset.UTC)) + " UTC"; - } - - public boolean isEmbed() { - return this.embedChatMessage != null && this.chatMessage == null; - } - - public boolean isNormal() { - return !this.isEmbed(); - } - - public EmbedChatMessage getEmbedChatMessage() { - return embedChatMessage; - } - - public ChatMessage getChatMessage() { - return chatMessage; - } -}