|
14 | 14 | import net.dv8tion.jda.api.OnlineStatus; |
15 | 15 | import net.dv8tion.jda.api.entities.Activity; |
16 | 16 | import net.dv8tion.jda.api.entities.Guild; |
| 17 | +import net.dv8tion.jda.api.entities.PrivateChannel; |
17 | 18 | import net.dv8tion.jda.api.events.message.MessageReceivedEvent; |
| 19 | +import net.dv8tion.jda.api.exceptions.PermissionException; |
18 | 20 | import net.dv8tion.jda.api.requests.GatewayIntent; |
19 | 21 | import net.dv8tion.jda.api.utils.cache.CacheFlag; |
20 | 22 | import net.thesimpleteam.simplebot.cli.CLI; |
@@ -150,32 +152,34 @@ public static void main(String[] args) throws InterruptedException { |
150 | 152 | } |
151 | 153 |
|
152 | 154 | private static void getHelpConsumer(CommandEvent event, Bot bot) { |
153 | | - StringBuilder helpBuilder = new StringBuilder(String.format(MessageHelper.translateMessage(event, "help.commands"), event.getSelfUser().getName())); |
154 | | - for(CommandCategories category : CommandCategories.values()) { |
155 | | - if(bot.commands.stream().noneMatch(command -> category.category == command.getCategory())) continue; |
156 | | - helpBuilder.append("\n\n__").append(MessageHelper.translateMessage(event, category.category.getName())).append("__ :\n"); |
157 | | - for (Command command : bot.commands.stream().filter(command -> category.category == command.getCategory()).toList()) { |
158 | | - if(command.isHidden() || (command.isOwnerCommand() && !event.isOwner())) continue; |
159 | | - String translatedHelp = MessageHelper.translateMessage(event, command.getHelp()); |
160 | | - if(translatedHelp.contains("²")) { |
161 | | - String[] splittedHelp = translatedHelp.split("²"); |
162 | | - for (int index = 0; index < splittedHelp.length - 1; index++) { |
163 | | - helpBuilder.append("\n`").append(getPrefix(event.getGuild())).append(command.getName()).append(" ").append(MessageHelper.translateMessage(event, command.getArguments()).split("²")[index]).append("`").append(" ➡ *").append(splittedHelp[index]).append("*"); |
| 155 | + try { |
| 156 | + event.getAuthor().openPrivateChannel().complete(); |
| 157 | + StringBuilder helpBuilder = new StringBuilder(String.format(MessageHelper.translateMessage(event, "help.commands"), event.getSelfUser().getName())); |
| 158 | + for(CommandCategories category : CommandCategories.values()) { |
| 159 | + if(bot.commands.stream().noneMatch(command -> category.category == command.getCategory())) continue; |
| 160 | + helpBuilder.append("\n\n__").append(MessageHelper.translateMessage(event, category.category.getName())).append("__ :\n"); |
| 161 | + for (Command command : bot.commands.stream().filter(command -> category.category == command.getCategory()).toList()) { |
| 162 | + if(command.isHidden() || (command.isOwnerCommand() && !event.isOwner())) continue; |
| 163 | + String translatedHelp = MessageHelper.translateMessage(event, command.getHelp()); |
| 164 | + if(translatedHelp.contains("²")) { |
| 165 | + String[] splittedHelp = translatedHelp.split("²"); |
| 166 | + for (int index = 1; index < splittedHelp.length - 1; index++) { |
| 167 | + helpBuilder.append("\n`").append(getPrefix(event.getGuild())).append(command.getName()).append(" ").append(MessageHelper.translateMessage(event, command.getArguments()).split("²")[index]).append("`").append(" ➡ *").append(splittedHelp[index]).append("*"); |
| 168 | + } |
| 169 | + } else { |
| 170 | + helpBuilder.append("\n`").append(getPrefix(event.getGuild())).append(command.getName()).append(" ").append(command.getArguments() != null ? command.getArguments().startsWith("arguments.") ? MessageHelper.translateMessage(event, command.getArguments()) : command.getArguments() : "").append("`").append(" \u27A1 *").append(MessageHelper.translateMessage(event, command.getHelp())).append("*"); |
164 | 171 | } |
165 | | - } else { |
166 | | - helpBuilder.append("\n`").append(getPrefix(event.getGuild())).append(command.getName()).append(" ").append(command.getArguments() != null ? |
167 | | - command.getArguments().startsWith("arguments.") ? MessageHelper.translateMessage(event, command.getArguments()) : command.getArguments() : "").append("`") |
168 | | - .append(" \u27A1 *").append(MessageHelper.translateMessage(event, command.getHelp())).append("*"); |
169 | 172 | } |
170 | 173 | } |
| 174 | + if (event.getJDA().getUserById(bot.ownerID) != null) { |
| 175 | + helpBuilder.append("\n\n").append(MessageHelper.translateMessage(event, "help.contact")).append(" **").append(MessageHelper.getTag(event.getJDA().getUserById(bot.ownerID))).append("**"); |
| 176 | + if (event.getClient().getServerInvite() != null) |
| 177 | + helpBuilder.append(' ').append(MessageHelper.translateMessage(event, "help.discord")).append(' ').append(bot.serverInvite); |
| 178 | + } |
| 179 | + event.replyInDm(helpBuilder.toString(), unused -> {}, unused -> {}); |
| 180 | + } catch (PermissionException e) { |
| 181 | + event.reply(MessageHelper.translateMessage(event, "help.DMBlocked")); |
171 | 182 | } |
172 | | - if (event.getJDA().getUserById(bot.ownerID) != null) { |
173 | | - helpBuilder.append("\n\n").append(MessageHelper.translateMessage(event, "help.contact")).append(" **").append(MessageHelper.getTag(event.getJDA().getUserById(bot.ownerID))).append("**"); |
174 | | - if (event.getClient().getServerInvite() != null) |
175 | | - helpBuilder.append(' ').append(MessageHelper.translateMessage(event, "help.discord")).append(' ').append(bot.serverInvite); |
176 | | - } |
177 | | - event.replyInDm(helpBuilder.toString(), unused -> { |
178 | | - }, t -> event.reply(MessageHelper.translateMessage(event, "help.DMBlocked"))); |
179 | 183 | } |
180 | 184 |
|
181 | 185 | private static void setupLocalizations() throws IOException { |
|
0 commit comments