|
12 | 12 | import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
13 | 13 | import net.dv8tion.jda.api.requests.RestAction;
|
14 | 14 | import net.dv8tion.jda.api.requests.restaction.MessageCreateAction;
|
15 |
| -import net.dv8tion.jda.api.utils.FileUpload; |
16 | 15 | import net.dv8tion.jda.internal.requests.CompletedRestAction;
|
17 | 16 | import org.slf4j.Logger;
|
18 | 17 | import org.slf4j.LoggerFactory;
|
|
26 | 25 | import org.togetherjava.tjbot.features.chatgpt.ChatGptService;
|
27 | 26 | import org.togetherjava.tjbot.features.componentids.ComponentIdInteractor;
|
28 | 27 |
|
29 |
| -import javax.annotation.Nullable; |
30 |
| - |
31 | 28 | import java.awt.*;
|
32 |
| -import java.io.InputStream; |
33 | 29 | import java.util.ArrayList;
|
34 | 30 | import java.util.Arrays;
|
35 | 31 | import java.util.Collection;
|
@@ -57,8 +53,6 @@ public final class HelpSystemHelper {
|
57 | 53 |
|
58 | 54 | static final Color AMBIENT_COLOR = new Color(255, 255, 165);
|
59 | 55 |
|
60 |
| - private static final String CODE_SYNTAX_EXAMPLE_PATH = "codeSyntaxExample.png"; |
61 |
| - |
62 | 56 | private final Predicate<String> hasTagManageRole;
|
63 | 57 | private final Predicate<String> isHelpForumName;
|
64 | 58 | private final String helpForumPattern;
|
@@ -111,43 +105,16 @@ public HelpSystemHelper(Config config, Database database, ChatGptService chatGpt
|
111 | 105 | }
|
112 | 106 |
|
113 | 107 | RestAction<Message> sendExplanationMessage(GuildMessageChannel threadChannel) {
|
114 |
| - return mentionGuildSlashCommand(threadChannel.getGuild(), HelpThreadCommand.COMMAND_NAME, |
115 |
| - HelpThreadCommand.Subcommand.CLOSE.getCommandName()) |
116 |
| - .flatMap(closeCommandMention -> sendExplanationMessage(threadChannel, |
117 |
| - closeCommandMention)); |
118 |
| - } |
119 |
| - |
120 |
| - private RestAction<Message> sendExplanationMessage(GuildMessageChannel threadChannel, |
121 |
| - String closeCommandMention) { |
122 |
| - boolean useCodeSyntaxExampleImage = true; |
123 |
| - InputStream codeSyntaxExampleData = |
124 |
| - HelpSystemHelper.class.getResourceAsStream("/" + CODE_SYNTAX_EXAMPLE_PATH); |
125 |
| - if (codeSyntaxExampleData == null) { |
126 |
| - useCodeSyntaxExampleImage = false; |
127 |
| - } |
| 108 | + MessageEmbed helpEmbed = new EmbedBuilder() |
| 109 | + .setDescription( |
| 110 | + """ |
| 111 | + If nobody is calling back, that usually means that your question was **not well asked** and \ |
| 112 | + hence nobody feels confident enough answering. Try to use your time to elaborate, \ |
| 113 | + **provide details**, context, more code, examples and maybe some screenshots. \ |
| 114 | + With enough info, someone knows the answer for sure.""") |
| 115 | + .build(); |
128 | 116 |
|
129 |
| - String message = |
130 |
| - "While you are waiting for getting help, here are some tips to improve your experience:"; |
131 |
| - |
132 |
| - List<MessageEmbed> embeds = List.of(HelpSystemHelper.embedWith( |
133 |
| - "Code is much easier to read if posted with **syntax highlighting** and proper formatting.", |
134 |
| - useCodeSyntaxExampleImage ? "attachment://" + CODE_SYNTAX_EXAMPLE_PATH : null), |
135 |
| - HelpSystemHelper.embedWith( |
136 |
| - """ |
137 |
| - If nobody is calling back, that usually means that your question was **not well asked** and \ |
138 |
| - hence nobody feels confident enough answering. Try to use your time to elaborate, \ |
139 |
| - **provide details**, context, more code, examples and maybe some screenshots. \ |
140 |
| - With enough info, someone knows the answer for sure."""), |
141 |
| - HelpSystemHelper.embedWith( |
142 |
| - "Don't forget to close your thread using the command %s when your question has been answered, thanks." |
143 |
| - .formatted(closeCommandMention))); |
144 |
| - |
145 |
| - MessageCreateAction action = threadChannel.sendMessage(message); |
146 |
| - if (useCodeSyntaxExampleImage) { |
147 |
| - action = action |
148 |
| - .addFiles(FileUpload.fromData(codeSyntaxExampleData, CODE_SYNTAX_EXAMPLE_PATH)); |
149 |
| - } |
150 |
| - return action.setEmbeds(embeds); |
| 117 | + return threadChannel.sendMessageEmbeds(helpEmbed); |
151 | 118 | }
|
152 | 119 |
|
153 | 120 | /**
|
@@ -261,17 +228,6 @@ void writeHelpThreadToDatabase(long authorId, ThreadChannel threadChannel) {
|
261 | 228 | });
|
262 | 229 | }
|
263 | 230 |
|
264 |
| - private static MessageEmbed embedWith(CharSequence message) { |
265 |
| - return embedWith(message, null); |
266 |
| - } |
267 |
| - |
268 |
| - private static MessageEmbed embedWith(CharSequence message, @Nullable String imageUrl) { |
269 |
| - return new EmbedBuilder().setColor(AMBIENT_COLOR) |
270 |
| - .setDescription(message) |
271 |
| - .setImage(imageUrl) |
272 |
| - .build(); |
273 |
| - } |
274 |
| - |
275 | 231 | Optional<Role> handleFindRoleForCategory(String category, Guild guild) {
|
276 | 232 | String roleName = category + categoryRoleSuffix;
|
277 | 233 | Optional<Role> maybeHelperRole = guild.getRolesByName(roleName, true).stream().findAny();
|
|
0 commit comments