Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,17 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
return;
}

if (msg.getContentRaw().equals("!forumping")) {
if (msg.getContentRaw().startsWith("!forumping:")) {
Long channelId = Long.parseLong(msg.getContentRaw().split(":")[1]);
if(!discordUtil.isForumChannel(channelId)){
event.getMessage().reply("is not forum channel").queue();
System.out.println("is not forum channel");
return ;
}
CreateDiscordThreadCommand command = CreateDiscordThreadCommand.builder()
.channelDiscordId(1326507142286544957L)
.channelDiscordId(channelId)
.guildDiscordId(event.getGuild().getIdLong())
.webHookUrl("https://discordapp.com/api/webhooks/1341258654082404403/SnSx0qzymTEkwuEeVfXMPsUbSj_yiQ0tlCSOX4WOalSKBrdDlBXbz_TMFqnWIyIBy60m")
.webHookUrl(webHookPort.getOrCreate(event.getGuild().getForumChannelById(channelId).getIdLong()))
.contentMessage("spring server message test success\nhi\ncontent")
.avatarUrl(event.getMember().getEffectiveAvatarUrl())
.userName(event.getMember().getEffectiveName())
Expand Down Expand Up @@ -232,10 +238,19 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
String[] commands = msg.getContentRaw().split(":");
Long msgId = Long.parseLong(commands[1]);
Long originChannelId=discordUtil.getRootChannelId(event.getChannel());
deleteDiscordWebHookMessagePort.deleteInThread(webHookPort.getOrCreate(originChannelId),
deleteDiscordWebHookMessagePort.delete(webHookPort.getOrCreate(originChannelId),
event.getGuild().getIdLong()
,event.getChannel().getIdLong(),msgId);

}
if(msg.getContentRaw().startsWith("!deleteforum:")) {
String[] commands = msg.getContentRaw().split(":");
Long msgId = Long.parseLong(commands[1]);
Long originChannelId=discordUtil.getRootChannelId(event.getChannel());
deleteDiscordWebHookMessagePort.deleteThread(webHookPort.getOrCreate(originChannelId),
event.getGuild().getIdLong()
,event.getChannel().getIdLong(),msgId);

}
if(msg.getContentRaw().startsWith("!editcomment:")) {
String[] commands = msg.getContentRaw().split(":");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.dv8tion.jda.api.entities.WebhookClient;
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
import org.springframework.stereotype.Component;
import space.space_spring.domain.discord.adapter.in.discord.DiscordUtil;
import space.space_spring.domain.discord.application.port.out.deleteWebHookMessage.DeleteDiscordWebHookMessagePort;
import space.space_spring.global.exception.CustomException;

Expand All @@ -20,16 +21,24 @@
@Slf4j
public class DeleteWebHookMessageAdapter implements DeleteDiscordWebHookMessagePort {
private final JDA jda;
private final DiscordUtil discordUtil;
@Override
public void delete(String webHook,Long guildDiscordId, Long channelDiscordId,Long messageId){
try {
if(discordUtil.isForumChannel(channelDiscordId)){
deleteThread(webHook,guildDiscordId,channelDiscordId,messageId);
return;
}
WebhookClient.createClient(jda, webHook).deleteMessageById(messageId).complete();
}catch(ErrorResponseException e){
if(e.getErrorCode()==10008){
throw new CustomException(NOT_PROVIDE_CROSS_DELETE);
}
}
}
public void deleteThread(String webHook,Long guildDiscordId, Long channelDiscordId,Long messageId){
jda.getThreadChannelById(messageId).delete().complete();
}

public void deleteInThread(String webHook,Long guildDiscordId, Long threadDiscordId,Long messageId){
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public interface DeleteDiscordWebHookMessagePort {
void delete(String webHook,Long guildDiscordId,Long channelDiscordId,Long messageId);
void deleteInThread(String webHook,Long guildDiscordId, Long threadDiscordId,Long messageId);
void deleteThread(String webHook,Long guildDiscordId,Long channelDiscordId,Long messageId);
}
Loading