Skip to content

Commit b67bcaa

Browse files
committed
added more antispam stuff
1 parent 1f8d595 commit b67bcaa

File tree

2 files changed

+160
-10
lines changed

2 files changed

+160
-10
lines changed

src/main/kotlin/com/lambda/module/modules/chat/AntiSpam.kt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import com.lambda.util.ChatUtils.slurs
3535
import com.lambda.util.ChatUtils.swears
3636
import com.lambda.util.ChatUtils.toAscii
3737
import com.lambda.util.NamedEnum
38-
import com.lambda.util.text.MessageDirection
38+
import com.lambda.util.text.DirectMessage
3939
import com.lambda.util.text.MessageParser
4040
import com.lambda.util.text.MessageType
4141
import net.minecraft.text.Text
@@ -45,9 +45,13 @@ object AntiSpam : Module(
4545
description = "Keeps your chat clean",
4646
tag = ModuleTag.CHAT,
4747
) {
48-
private val ignoreSelf by setting("Ignore Self", true)
49-
private val ignoreFriends by setting("Ignore Friends", true)
5048
private val fancyChats by setting("Replace Fancy Chat", false)
49+
50+
private val filterSelf by setting("Ignore Self", true)
51+
private val filterFriends by setting("Ignore Friends", true)
52+
private val filterSystem by setting("Filter System Messages", false)
53+
private val filterDms by setting("Filter DMs", true)
54+
5155
private val ignoreSystem by setting("Ignore System", false)
5256
private val ignoreDms by setting("Ignore DMs", false)
5357

@@ -75,15 +79,13 @@ object AntiSpam : Module(
7579
}
7680

7781
init {
78-
listen<ChatEvent.Message>(42069) { event ->
82+
listen<ChatEvent.Receive> { event ->
7983
var raw = event.message.string
8084
val author = MessageParser.playerName(raw)
8185

8286
if (
83-
ignoreSystem && !MessageType.Both.matches(raw) && !MessageDirection.Both.matches(raw) ||
84-
ignoreDms && MessageDirection.Receive.matches(raw) ||
85-
ignoreFriends && author?.let { FriendManager.isFriend(it) } == true ||
86-
ignoreSelf && MessageType.Self.matches(raw)
87+
ignoreSystem && !MessageType.Both.matches(raw) && !DirectMessage.Both.matches(raw) ||
88+
ignoreDms && DirectMessage.Receive.matches(raw)
8789
) return@listen
8890

8991
val slurMatches = slurs.takeIf { detectSlurs.enabled }.orEmpty().flatMap { it.findAll(raw).toList().reversed() }
@@ -98,7 +100,13 @@ object AntiSpam : Module(
98100
var hasMatches = false
99101

100102
fun doMatch(replace: ReplaceConfig, matches: Sequence<MatchResult>) {
101-
if (cancelled) return
103+
if (
104+
cancelled ||
105+
filterSystem && !MessageType.Both.matches(raw) && !DirectMessage.Both.matches(raw) ||
106+
filterDms && DirectMessage.Receive.matches(raw) ||
107+
filterFriends && author?.let { FriendManager.isFriend(it) } == true ||
108+
filterSelf && MessageType.Self.matches(raw)
109+
) return
102110

103111
when (replace.action) {
104112
ReplaceConfig.ActionStrategy.Hide -> matches.firstOrNull()?.let { event.cancel(); cancelled = true } // If there's one detection, nuke the whole damn thang

src/main/kotlin/com/lambda/util/ChatUtils.kt

Lines changed: 143 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,149 @@ object ChatUtils {
2626
val hex = sequenceOf("\\s([A-Fa-f0-9]+){5,10}$").map { Regex(it) }
2727
val colors = sequenceOf(">", "`").map { Regex(it) }
2828

29-
val fancyToAscii = mapOf('' to 'a', 'ʙ' to 'b', 'c' to 'c', '' to 'd', '' to 'e', '' to 'f', 'ɢ' to 'g', 'ʜ' to 'h', 'ɪ' to 'i', '' to 'j', '' to 'k', 'ʟ' to 'l', '' to 'm', 'ɴ' to 'n', '' to 'o', '' to 'p', 'q' to 'q', 'ʀ' to 'r', '' to 's', '' to 't', '' to 'u', '' to 'v', '' to 'w', 'x' to 'x', 'y' to 'y', '' to 'z',)
29+
val fancyToAscii = mapOf(
30+
'' to '!',
31+
'' to '"',
32+
'' to '#',
33+
'' to '$',
34+
'' to '%',
35+
'' to '&',
36+
'' to '\'',
37+
'' to '(',
38+
'' to ')',
39+
'' to '*',
40+
'' to '+',
41+
'' to ',',
42+
'' to '-',
43+
'' to '.',
44+
'' to '/',
45+
'' to '\\',
46+
'' to '|',
47+
'' to ':',
48+
'' to ';',
49+
'' to '<',
50+
'' to '=',
51+
'' to '>',
52+
'' to '?',
53+
'' to '@',
54+
'' to '[',
55+
'' to ']',
56+
'' to '{',
57+
'' to '}',
58+
'' to '~',
59+
'' to '^',
60+
'_' to '_',
61+
'' to '`',
62+
'' to '0',
63+
'' to '1',
64+
'' to '2',
65+
'' to '3',
66+
'' to '4',
67+
'' to '5',
68+
'' to '6',
69+
'' to '7',
70+
'' to '8',
71+
'' to '9',
72+
'' to 'A',
73+
'' to 'B',
74+
'C' to 'C',
75+
'' to 'D',
76+
'' to 'E',
77+
'' to 'F',
78+
'' to 'G',
79+
'' to 'H',
80+
'' to 'I',
81+
'' to 'J',
82+
'' to 'K',
83+
'' to 'L',
84+
'' to 'M',
85+
'' to 'N',
86+
'' to 'O',
87+
'' to 'P',
88+
'' to 'Q',
89+
'' to 'R',
90+
'' to 'S',
91+
'' to 'T',
92+
'' to 'U',
93+
'' to 'V',
94+
'' to 'W',
95+
'' to 'X',
96+
'' to 'Y',
97+
'' to 'Z',
98+
'' to 'a',
99+
'ʙ' to 'b',
100+
'c' to 'c',
101+
'' to 'd',
102+
'' to 'e',
103+
'' to 'f',
104+
'ɢ' to 'g',
105+
'ʜ' to 'h',
106+
'ɪ' to 'i',
107+
'' to 'j',
108+
'' to 'k',
109+
'ʟ' to 'l',
110+
'' to 'm',
111+
'ɴ' to 'n',
112+
'' to 'o',
113+
'' to 'p',
114+
'q' to 'q',
115+
'ʀ' to 'r',
116+
'' to 's',
117+
'' to 't',
118+
'' to 'u',
119+
'' to 'v',
120+
'' to 'w',
121+
'x' to 'x',
122+
'y' to 'y',
123+
'' to 'z',
124+
'' to 'a',
125+
'' to 'b',
126+
'' to 'c',
127+
'' to 'd',
128+
'' to 'e',
129+
'' to 'f',
130+
'' to 'g',
131+
'' to 'h',
132+
'' to 'i',
133+
'' to 'j',
134+
'' to 'k',
135+
'' to 'l',
136+
'' to 'm',
137+
'' to 'n',
138+
'' to 'o',
139+
'' to 'p',
140+
'' to 'q',
141+
'' to 'r',
142+
'' to 's',
143+
'' to 't',
144+
'' to 'u',
145+
'' to 'v',
146+
'' to 'w',
147+
'' to 'x',
148+
'' to 'y',
149+
'' to 'z',
150+
)
151+
val asciiToFancy = fancyToAscii.entries.associate { (key, value) -> value to key }
152+
val asciiToLeet = mapOf('a' to '4', 'e' to '3', 'g' to '6', 'l' to '1', 'i' to '1', 'o' to '0', 's' to '$', 't' to '7')
30153

154+
val String.toFancy get() = buildString { this@toFancy.forEach { append(asciiToFancy.getOrDefault(it, it)) } }
31155
val String.toAscii get() = buildString { this@toAscii.forEach { append(fancyToAscii.getOrDefault(it, it)) } }
156+
val String.toLeet get() = buildString { this@toLeet.forEach { append(asciiToLeet.getOrDefault(it, it)) } }
157+
val String.toGreen get() = ">$this"
158+
val String.toBlue get() = "`$this"
159+
160+
val String.toUwu get() =
161+
replace("my", "mai")
162+
.replace("friend", "fwend")
163+
.replace("small", "smol")
164+
.replace("cute", "cyute")
165+
.replace("very", "vewy")
166+
.replace("ove", "uv")
167+
.replace("no", "nu")
168+
.replace("you", "yew")
169+
.replace("the", "da")
170+
.replace("is", "ish")
171+
.replace('r', 'w')
172+
.replace("ve", "v")
173+
.replace('l', 'w')
32174
}

0 commit comments

Comments
 (0)