21
21
* THE SOFTWARE.
22
22
*/
23
23
24
+
25
+
24
26
function escapeRegExp ( strings : string ) : string {
25
27
let data = strings . trim ( ) . toLowerCase ( ) . split ( "|" ) . filter ( Boolean ) ;
26
28
for ( let index = 0 ; index < data . length ; index ++ ) {
@@ -141,8 +143,14 @@ class FilterBadWord {
141
143
}
142
144
143
145
class filters_badword extends FilterBadWord {
144
- private cl : boolean ;
145
- private st : boolean ;
146
+ protected cl : boolean ;
147
+ protected st : boolean ;
148
+
149
+ constructor ( cl : boolean = true , st : boolean = true ) {
150
+ super ( ) ; // Memanggil konstruktor kelas induk
151
+ this . cl = cl ; // Inisialisasi properti cl
152
+ this . st = st ; // Inisialisasi properti st
153
+ }
146
154
147
155
public text_o ( text : string ) : void {
148
156
this . _text = text . toString ( ) ;
@@ -162,18 +170,27 @@ class filters_badword extends FilterBadWord {
162
170
163
171
public get cleans ( ) : string {
164
172
if ( this . cl ) {
165
- if ( this . thisToxic [ 1 ] === 1 && this . thisToxic . length > 2 ) {
166
- if ( this . st ) {
167
- const sensore = "*" . repeat ( this . thisToxic [ 2 ] . length ) ;
168
- return this . clean ( this . position ( ) ) . replace ( this . thisToxic [ 2 ] , sensore ) ;
173
+ const toxicResult = this . thisToxic ; // Simpan hasil dalam variabel
174
+
175
+ // Pastikan toxicResult adalah array dan tidak false
176
+ if ( Array . isArray ( toxicResult ) && toxicResult [ 1 ] === 1 && toxicResult . length > 2 ) {
177
+ const toxicWord = toxicResult [ 2 ] ;
178
+
179
+ // Pastikan toxicWord adalah string
180
+ if ( typeof toxicWord === 'string' ) {
181
+ const sensore = "*" . repeat ( toxicWord . length ) ;
182
+ // Memanggil clean dengan hasil posisi yang telah dibersihkan
183
+ return this . clean ( this . position ( ) ) . replace ( toxicWord , sensore ) ;
169
184
}
170
- return this . clean ( this . position ( ) ) ;
171
185
}
186
+
187
+ // Kembali bersih jika tidak ada kata yang terdeteksi
172
188
return this . clean ( this . position ( ) ) ;
173
189
} else {
174
190
return this . _text . trim ( ) ;
175
191
}
176
192
}
193
+
177
194
178
195
set cleans ( value : string ) {
179
196
throw value ;
0 commit comments