-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
90 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/gdschongik/gdsc/domain/discord/handler/NonCommandHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.gdschongik.gdsc.domain.discord.handler; | ||
|
||
import static com.gdschongik.gdsc.global.common.constant.DiscordConstant.*; | ||
|
||
import com.gdschongik.gdsc.global.util.DiscordUtil; | ||
import java.util.Objects; | ||
import lombok.RequiredArgsConstructor; | ||
import net.dv8tion.jda.api.entities.Member; | ||
import net.dv8tion.jda.api.entities.Role; | ||
import net.dv8tion.jda.api.events.GenericEvent; | ||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class NonCommandHandler implements DiscordEventHandler { | ||
|
||
private final DiscordUtil discordUtil; | ||
|
||
@Override | ||
public void delegate(GenericEvent genericEvent) { | ||
MessageReceivedEvent event = (MessageReceivedEvent) genericEvent; | ||
Role adminRole = discordUtil.findRoleByName(ADMIN_ROLE_NAME); | ||
|
||
Member member = Objects.requireNonNull(event.getMember()); | ||
|
||
if (member.getUser().isBot()) { | ||
return; | ||
} | ||
|
||
if (member.getRoles().contains(adminRole)) { | ||
return; | ||
} | ||
|
||
event.getMessage().delete().queue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ public class EmailConstant { | |
public static final String VERIFY_EMAIL_API_ENDPOINT = "/onboarding/verify-email?%s="; | ||
public static final String VERIFY_EMAIL_REQUEST_PARAMETER_KEY = "token"; | ||
public static final String HONGIK_UNIV_MAIL_DOMAIN = "@g.hongik.ac.kr"; | ||
public static final String SENDER_PERSONAL = "GDSC Hongik 운영팀"; | ||
public static final String SENDER_PERSONAL = "GDSC Hongik"; | ||
public static final String SENDER_ADDRESS = "[email protected]"; | ||
public static final String VERIFICATION_EMAIL_SUBJECT = "GDSC Hongik 이메일 인증 코드입니다."; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/gdschongik/gdsc/global/discord/listener/NonCommandListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.gdschongik.gdsc.global.discord.listener; | ||
|
||
import com.gdschongik.gdsc.domain.discord.handler.NonCommandHandler; | ||
import com.gdschongik.gdsc.global.discord.Listener; | ||
import com.gdschongik.gdsc.global.property.DiscordProperty; | ||
import lombok.RequiredArgsConstructor; | ||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@Listener | ||
@RequiredArgsConstructor | ||
public class NonCommandListener extends ListenerAdapter { | ||
|
||
private final DiscordProperty discordProperty; | ||
private final NonCommandHandler nonCommandHandler; | ||
|
||
@Override | ||
public void onMessageReceived(@NotNull MessageReceivedEvent event) { | ||
String eventChannelId = event.getChannel().getId(); | ||
|
||
if (eventChannelId.equals(discordProperty.getCommandChannelId())) { | ||
nonCommandHandler.delegate(event); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
discord: | ||
token: ${DISCORD_BOT_TOKEN:} | ||
server-id: ${DISCORD_SERVER_ID:} | ||
command-channel-id: ${DISCORD_COMMAND_CHANNEL_ID:} |