Skip to content

Commit

Permalink
v1.1.0 (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
uwoobeat authored Feb 27, 2024
2 parents 0cc6155 + 12dd01e commit a07fd3c
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/production_build_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ jobs:
images: ${{ env.DOCKERHUB_IMAGE_FULL_NAME }}
tags: |
type=semver,pattern={{version}}
flavor: |
latest=false
# 멀티 아키텍처 지원을 위한 QEMU 설정
- name: Set up QEMU
Expand Down
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ public class UnivEmailVerificationLinkSendService {
private final MemberUtil memberUtil;
public static final Duration VERIFICATION_CODE_TIME_TO_LIVE = Duration.ofMinutes(10);

private static final String NOTIFICATION_MESSAGE = "<div style='margin:20px;'>"
+ "<h1> 안녕하세요 GDSC Hongik 재학생 인증 메일입니다. </h1> <br>"
+ "<h3> 아래의 링크를 %d분 안에 클릭해주세요. </h3> <br>"
+ "<h3> 감사합니다. </h3> <br>"
+ "CODE : <strong>";
private static final String NOTIFICATION_MESSAGE =
"""
<div style='font-family: "Roboto", sans-serif; margin: 40px; background-color: #ffffff; padding: 20px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);'>
<h3 style='color: #202124;'>GDSC Hongik 재학생 인증 메일</h3>
<p style='color: #5f6368;'>안녕하세요!</p>
<p style='color: #5f6368;'>GDSC Hongik 커뮤니티에 지원해주셔서 대단히 감사드립니다.</p>
<p style='color: #5f6368;'>아래의 버튼을 클릭하여 재학생 인증을 완료해주세요. 링크는 %d분 동안 유효합니다.</p>
<a href='%s' style='display: inline-block; background-color: #4285F4; color: white; padding: 12px 24px; margin: 20px 0; border-radius: 4px; text-decoration: none; font-weight: 500;'>재학생 인증하기</a>
<p style='color: #5f6368;'>감사합니다.<br>GDSC Hongik Team</p>
</div>
""";

public void send(String univEmail) {
hongikUnivEmailValidator.validate(univEmail);
Expand All @@ -60,7 +66,7 @@ private void validateUnivEmailNotVerified(String univEmail) {
}

private String writeMailContentWithVerificationLink(String verificationLink) {
return String.format(NOTIFICATION_MESSAGE, VERIFICATION_CODE_TIME_TO_LIVE.toMinutes()) + verificationLink;
return NOTIFICATION_MESSAGE.formatted(VERIFICATION_CODE_TIME_TO_LIVE.toMinutes(), verificationLink);
}

private void saveUnivEmailVerification(String univEmail, String verificationCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,10 @@ public boolean isGrantAvailable() {
return false;
}
}

// 기타 로직

public void updateLastLoginAt() {
this.lastLoginAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public class DiscordConstant {
private DiscordConstant() {}

// 공통 상수
public static final String DISCORD_BOT_STATUS_CONTENT = "정상영업";
public static final String MEMBER_ROLE_NAME = "커뮤니티-멤버";
public static final String ADMIN_ROLE_NAME = "운영진";

// 인증코드 발급 커맨드
public static final String COMMAND_NAME_ISSUING_CODE = "인증코드";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 이메일 인증 코드입니다.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class DiscordConfig {
@ConditionalOnProperty(value = "discord.enabled", havingValue = "true", matchIfMissing = true)
public JDA jda() {
JDA jda = JDABuilder.createDefault(discordProperty.getToken())
.setActivity(Activity.playing("테스트"))
.setActivity(Activity.playing(DISCORD_BOT_STATUS_CONTENT))
.enableIntents(GatewayIntent.GUILD_MESSAGES, GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MEMBERS)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.build();
Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class DiscordProperty {

private final String token;
private final String serverId;
private final String commandChannelId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class CustomUserService extends DefaultOAuth2UserService {
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
OAuth2User oAuth2User = super.loadUser(userRequest);
Member member = fetchOrCreate(oAuth2User);
member.updateLastLoginAt();
return new CustomOAuth2User(oAuth2User, member);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-discord.yml
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:}

0 comments on commit a07fd3c

Please sign in to comment.