Skip to content
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

Feat/18 : 비속어 필터 추가 #19

Merged
merged 3 commits into from
Sep 27, 2024
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class RandomNameGenerator {
);

List<String> objective = Arrays.asList(
"인덕이", "안뇽이"
"인덕이", "안뇽이", "비룡이"
);
public String generate(){
Collections.shuffle(adjective);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/Be9room/festime/config/BadWordFilteringConfig.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,7 @@ public class MessageController {
private final SimpMessagingTemplate template;
private final MessageService messageService;
private final TimeLimitService timeLimitService;
private final BadWordFiltering badWordFiltering;

/**
* 메세지 전송
Expand All @@ -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);
}
}
Expand Down
Loading