This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name similarity check, release 6.0.0
- Loading branch information
xxneox
committed
May 29, 2021
1 parent
06beb17
commit fc7e9b7
Showing
7 changed files
with
91 additions
and
4 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
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
36 changes: 36 additions & 0 deletions
36
core/src/main/java/me/xneox/epicguard/core/check/impl/NameSimilarityCheck.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,36 @@ | ||
package me.xneox.epicguard.core.check.impl; | ||
|
||
import com.google.common.collect.EvictingQueue; | ||
import me.xneox.epicguard.core.EpicGuard; | ||
import me.xneox.epicguard.core.check.Check; | ||
import me.xneox.epicguard.core.user.PendingUser; | ||
import org.apache.commons.text.similarity.LevenshteinDistance; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.List; | ||
import java.util.Queue; | ||
|
||
@SuppressWarnings("UnstableApiUsage") | ||
public class NameSimilarityCheck extends Check { | ||
private final Queue<String> nameHistory = EvictingQueue.create(this.epicGuard.config().nameSimilarityCheck().historySize()); | ||
private final LevenshteinDistance distanceAlgorithm = LevenshteinDistance.getDefaultInstance(); | ||
|
||
public NameSimilarityCheck(EpicGuard epicGuard) { | ||
super(epicGuard); | ||
} | ||
|
||
@Override | ||
public boolean handle(@Nonnull PendingUser user) { | ||
for (String nick : this.nameHistory) { | ||
if (this.distanceAlgorithm.apply(nick, user.nickname()) <= this.epicGuard.config().nameSimilarityCheck().distance()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public @Nonnull List<String> kickMessage() { | ||
return this.epicGuard.messages().disconnect().nameSimilarity(); | ||
} | ||
} |
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