|
9 | 9 | import net.dv8tion.jda.api.entities.MessageEmbed; |
10 | 10 | import net.dv8tion.jda.api.entities.User; |
11 | 11 | import net.dv8tion.jda.api.entities.UserSnowflake; |
| 12 | +import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel; |
12 | 13 | import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; |
13 | 14 | import net.dv8tion.jda.api.entities.emoji.Emoji; |
14 | 15 | import net.dv8tion.jda.api.interactions.Interaction; |
15 | 16 | import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; |
16 | 17 | import net.dv8tion.jda.api.interactions.components.ActionRow; |
17 | 18 | import net.dv8tion.jda.api.interactions.components.ItemComponent; |
18 | 19 | import net.dv8tion.jda.api.interactions.components.buttons.Button; |
| 20 | +import net.dv8tion.jda.api.requests.RestAction; |
19 | 21 | import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; |
20 | 22 | import net.javadiscord.javabot.data.config.BotConfig; |
21 | 23 | import net.javadiscord.javabot.data.config.guild.HelpConfig; |
22 | 24 | import net.javadiscord.javabot.data.h2db.DbActions; |
23 | 25 | import net.javadiscord.javabot.systems.help.dao.HelpAccountRepository; |
24 | 26 | import net.javadiscord.javabot.systems.help.dao.HelpTransactionRepository; |
| 27 | +import net.javadiscord.javabot.systems.user_preferences.UserPreferenceService; |
| 28 | +import net.javadiscord.javabot.systems.user_preferences.model.Preference; |
25 | 29 | import net.javadiscord.javabot.util.ExceptionLogger; |
26 | 30 | import net.javadiscord.javabot.util.MessageActionUtils; |
27 | 31 | import net.javadiscord.javabot.util.Responses; |
@@ -64,6 +68,7 @@ public class HelpManager { |
64 | 68 | private final HelpAccountRepository helpAccountRepository; |
65 | 69 |
|
66 | 70 | private final HelpTransactionRepository helpTransactionRepository; |
| 71 | + private final UserPreferenceService preferenceService; |
67 | 72 |
|
68 | 73 | /** |
69 | 74 | * Builds and replies {@link ActionRow}s with all members which helped the |
@@ -108,6 +113,31 @@ public void close(IReplyCallback callback, boolean withHelpers, @Nullable String |
108 | 113 | Responses.info(callback, "Post Closed", "This post has been closed by %s%s", callback.getUser().getAsMention(), reason != null ? " for the following reason:\n> " + reason : ".") |
109 | 114 | .setEphemeral(false) |
110 | 115 | .queue(s -> postThread.getManager().setLocked(true).setArchived(true).queue()); |
| 116 | + if (callback.getMember().getIdLong() != postThread.getOwnerIdLong() && |
| 117 | + Boolean.parseBoolean(preferenceService.getOrCreate(postThread.getOwnerIdLong(), Preference.PRIVATE_CLOSE_NOTIFICATIONS).getState())) { |
| 118 | + postThread.getOwner().getUser().openPrivateChannel() |
| 119 | + .flatMap(c -> createDMCloseInfoEmbed(callback.getMember(), postThread, reason, c)) |
| 120 | + .queue(success -> {}, failure -> {}); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + private RestAction<Message> createDMCloseInfoEmbed(Member closingMember, ThreadChannel postThread, String reason, PrivateChannel c) { |
| 125 | + EmbedBuilder eb = new EmbedBuilder() |
| 126 | + .setTitle("Post closed") |
| 127 | + .setDescription( |
| 128 | + """ |
| 129 | + Your post %s has been closed by %s |
| 130 | + |
| 131 | + [Post link](%s) |
| 132 | + """ |
| 133 | + .formatted(postThread.getAsMention(), closingMember.getAsMention(), postThread.getJumpUrl())) |
| 134 | + .addField("Deactivate", "You can deactivate notifications like this using the `/preferences` command.", false) |
| 135 | + .setAuthor(closingMember.getEffectiveName(), null, closingMember.getEffectiveAvatarUrl()); |
| 136 | + if (reason != null) { |
| 137 | + eb |
| 138 | + .addField("Reason", reason, false); |
| 139 | + } |
| 140 | + return c.sendMessageEmbeds(eb.build()); |
111 | 141 | } |
112 | 142 |
|
113 | 143 | /** |
|
0 commit comments