-
-
Notifications
You must be signed in to change notification settings - Fork 91
Notify proper post deletion #1270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,12 @@ | |
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; | ||
import net.dv8tion.jda.api.entities.channel.forums.ForumTag; | ||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; | ||
import net.dv8tion.jda.api.events.message.MessageDeleteEvent; | ||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter; | ||
import net.dv8tion.jda.api.requests.RestAction; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.togetherjava.tjbot.features.EventReceiver; | ||
import org.togetherjava.tjbot.features.UserInteractionType; | ||
|
@@ -38,6 +41,9 @@ | |
*/ | ||
public final class HelpThreadCreatedListener extends ListenerAdapter | ||
implements EventReceiver, UserInteractor { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(HelpThreadCreatedListener.class); | ||
|
||
private final HelpSystemHelper helper; | ||
|
||
private final Cache<Long, Instant> threadIdToCreatedAtCache = Caffeine.newBuilder() | ||
|
@@ -71,6 +77,34 @@ public void onMessageReceived(MessageReceivedEvent event) { | |
} | ||
} | ||
|
||
@Override | ||
public void onMessageDelete(MessageDeleteEvent event) { | ||
// Check if the deleted message was from a thread | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think u misunderstood the task. its not about deleting any message in a help thread. its about deleting the original (first) message only. and ideally also only if it was deleted by OP. otherwise it also triggers when someone else deletes it (for example a mod). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not familiar with the role system in the server. Normal user's can also created posts or is it for OP's and above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any user can create a question thread and any user can send messages in the thread. the github-issue is about OP deleting the first message in the thread, not "any". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Btw for clarification: OP stands for "Original Poster", so it means the person creating the question in our case |
||
if (event.isFromThread()) { | ||
ThreadChannel threadChannel = event.getChannel().asThreadChannel(); | ||
Channel parentChannel = threadChannel.getParentChannel(); | ||
|
||
// Check if it's a help forum thread | ||
if (helper.isHelpForumName(parentChannel.getName())) { | ||
// Retrieve the thread owner using the owner's ID | ||
long ownerId = threadChannel.getOwnerIdLong(); | ||
threadChannel.getGuild() | ||
.retrieveMemberById(ownerId) | ||
.queue(member -> threadChannel | ||
.sendMessage( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. id prefer sending a DM instead of a public message. public message only as fallback if DMs are closed. see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair. we can keep it then, i guess. |
||
""" | ||
It looks like a message was deleted in this help post.\s | ||
To properly close this post, please __right-click__ on the **Created Post** __followed by__ **Delete Post**\s | ||
instead of deleting messages. This ensures proper record-keeping and\s | ||
helps other users find solutions.""") | ||
Comment on lines
+94
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. people in our server cant delete threads. u need to educate them about using |
||
.queue(), | ||
failure -> LOGGER.error( | ||
"Could not retrieve thread owner for thread ID {}: {}", | ||
threadChannel.getId(), failure.getMessage(), failure)); | ||
Comment on lines
+101
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
} | ||
|
||
private boolean wasThreadAlreadyHandled(long threadChannelId) { | ||
// NOTE Discord/JDA fires this event twice per thread (bug?), we work around by remembering | ||
// the threads we already handled | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to create a new listener here, this one seems to handle creation stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this is definitely the wrong class to handle this