Skip to content

Commit 12ebe7d

Browse files
committed
fix: solve and report related problems
1 parent 1415517 commit 12ebe7d

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/SolvedCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.diamondfire.helpbot.bot.command.permissions.Permission;
88
import com.diamondfire.helpbot.bot.command.reply.PresetBuilder;
99
import com.diamondfire.helpbot.bot.command.reply.feature.informative.*;
10-
import com.diamondfire.helpbot.bot.events.CommandEvent;
10+
import com.diamondfire.helpbot.bot.events.*;
1111
import com.diamondfire.helpbot.util.SolvedPostManager;
1212
import net.dv8tion.jda.api.entities.channel.ChannelType;
1313
import net.dv8tion.jda.api.entities.channel.concrete.*;
@@ -72,8 +72,8 @@ public void run(CommandEvent event) {
7272
return;
7373
}
7474

75-
// Apply the solved tag.
76-
SolvedPostManager.addSolved(threadChannel);
75+
/// Apply the solved tag, the [PostChannelEvent] listener will call [SolvedPostManager#addSolved].
76+
SolvedPostManager.applySolvedTag(threadChannel);
7777
}
7878

7979
}

src/main/java/com/diamondfire/helpbot/sys/report/ReportListener.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public void onButtonInteraction(@NotNull ButtonInteractionEvent event) {
9696
**Thank you for helping keep DiamondFire safe!**
9797
* Multiple proofs are allowed.
9898
* Proofs can be both **videos and screenshots**.
99-
* Uploaded screenshots should be **uncropped**
100-
> Meaning, take a __full screenshot__ of your screen.
99+
* Uploaded screenshots should be **uncropped**.
100+
> Meaning, [take a screenshot](https://www.take-a-screenshot.org/) of your __entire__ screen.
101101
* Make sure reports are made in **good faith with valid proof**.
102102
""");
103103

@@ -185,9 +185,7 @@ private ModalMapping getValue(ModalInteraction event, String customId) {
185185
// Instead of event#getValue since it returns null when not found,
186186
// we just assume the components always exist as we already confirm
187187
// it's the report modal.
188-
return event.getValues().stream()
189-
.filter(mapping -> mapping.getCustomId().equals(customId))
190-
.findFirst().orElseThrow();
188+
return event.getValue(customId);
191189
}
192190

193191
}

src/main/java/com/diamondfire/helpbot/util/SolvedPostManager.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
88
import net.dv8tion.jda.api.entities.channel.forums.ForumTag;
99
import net.dv8tion.jda.api.entities.channel.unions.ChannelUnion;
10-
import org.jetbrains.annotations.Nullable;
1110

1211
import java.util.*;
1312

1413
public final class SolvedPostManager {
1514

15+
private static final int CHANNEL_NAME_LIMIT = 100;
16+
private static final String ELLIPSIS = "...";
17+
1618
private SolvedPostManager() {}
1719

1820
public static Optional<ForumTag> getSolvedTag(ThreadChannel channel) {
@@ -26,21 +28,33 @@ public static boolean isSolved(ThreadChannel channel) {
2628
}
2729

2830
public static void addSolved(ThreadChannel channel) {
31+
if (!applySolvedTag(channel)) return;
32+
33+
if (!isSolved(channel)) {
34+
String newName = "[SOLVED] " + channel.getName();
35+
if (newName.length() > CHANNEL_NAME_LIMIT) {
36+
newName = newName.substring(0, CHANNEL_NAME_LIMIT - ELLIPSIS.length()) + ELLIPSIS;
37+
}
38+
channel.getManager().setName(newName).queue();
39+
}
40+
41+
sendEmbed(channel, "Post marked as solved");
42+
}
43+
44+
/**
45+
* @return true if successful
46+
*/
47+
public static boolean applySolvedTag(ThreadChannel channel) {
2948
Optional<ForumTag> optionalTag = getSolvedTag(channel);
30-
if (optionalTag.isEmpty()) return;
49+
if (optionalTag.isEmpty()) return false;
3150
ForumTag solvedTag = optionalTag.get();
3251

3352
List<ForumTag> tags = new ArrayList<>(channel.getAppliedTags());
3453
if (!tags.contains(solvedTag)) {
3554
tags.add(solvedTag);
3655
channel.getManager().setAppliedTags(tags).queue();
3756
}
38-
39-
if (!isSolved(channel)) {
40-
channel.getManager().setName("[SOLVED] " + channel.getName()).queue();
41-
}
42-
43-
sendEmbed(channel, "Post marked as solved");
57+
return true;
4458
}
4559

4660
public static void removeSolved(ThreadChannel channel) {

0 commit comments

Comments
 (0)