diff --git a/build.gradle b/build.gradle index 994c07b..f774355 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,7 @@ dependencies { implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0' // Redis implementation 'org.springframework.boot:spring-boot-starter-data-redis' + implementation 'io.github.vaneproject:badwordfiltering:1.0.0' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' diff --git a/src/main/java/Be9room/festime/common/RandomNameGenerator.java b/src/main/java/Be9room/festime/common/RandomNameGenerator.java index 9f56370..d1ccb3d 100644 --- a/src/main/java/Be9room/festime/common/RandomNameGenerator.java +++ b/src/main/java/Be9room/festime/common/RandomNameGenerator.java @@ -14,7 +14,7 @@ public class RandomNameGenerator { ); List objective = Arrays.asList( - "인덕이", "안뇽이" + "인덕이", "안뇽이", "비룡이" ); public String generate(){ Collections.shuffle(adjective); diff --git a/src/main/java/Be9room/festime/config/BadWordFilteringConfig.java b/src/main/java/Be9room/festime/config/BadWordFilteringConfig.java new file mode 100644 index 0000000..86818ed --- /dev/null +++ b/src/main/java/Be9room/festime/config/BadWordFilteringConfig.java @@ -0,0 +1,13 @@ +package Be9room.festime.config; + +import com.vane.badwordfiltering.BadWordFiltering; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class BadWordFilteringConfig { + @Bean + public BadWordFiltering badwordFiltering(){ + return new BadWordFiltering(); + } +} diff --git a/src/main/java/Be9room/festime/controller/MessageController.java b/src/main/java/Be9room/festime/controller/MessageController.java index c927f35..cd1413e 100644 --- a/src/main/java/Be9room/festime/controller/MessageController.java +++ b/src/main/java/Be9room/festime/controller/MessageController.java @@ -10,6 +10,7 @@ import Be9room.festime.service.MessageService; import Be9room.festime.service.TimeLimitService; import Be9room.festime.validation.annotation.CheckPage; +import com.vane.badwordfiltering.BadWordFiltering; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; @@ -29,6 +30,7 @@ public class MessageController { private final SimpMessagingTemplate template; private final MessageService messageService; private final TimeLimitService timeLimitService; + private final BadWordFiltering badWordFiltering; /** * 메세지 전송 @@ -40,8 +42,10 @@ public void message(MessageChatDto message){ //중복 입력 방지 30초 if(timeLimitService.isTimeElapsed(message.getMemberId())){ + //비속어 필터 적용 + String filteredMessage = badWordFiltering.change(message.getMessage(), new String [] {"_", "@", " ", " ", "!", "#", "$", "%", "^", "&", "*", "(", ")", "-", "+","=","/", "|", "~", "`", "?", ">", "<", ",", ".", ";", ":"}); + message.setMessage(filteredMessage); messageService.save(message); - template.convertAndSend("/topic/guestbook", message); } }