Skip to content

Commit 2a65e28

Browse files
authored
Update badword.ts
1 parent 605efcf commit 2a65e28

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

badword.ts

+24-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* THE SOFTWARE.
2222
*/
2323

24+
25+
2426
function escapeRegExp(strings: string): string {
2527
let data = strings.trim().toLowerCase().split("|").filter(Boolean);
2628
for (let index = 0; index < data.length; index++) {
@@ -141,8 +143,14 @@ class FilterBadWord {
141143
}
142144

143145
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+
}
146154

147155
public text_o(text: string): void {
148156
this._text = text.toString();
@@ -162,18 +170,27 @@ class filters_badword extends FilterBadWord {
162170

163171
public get cleans(): string {
164172
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);
169184
}
170-
return this.clean(this.position());
171185
}
186+
187+
// Kembali bersih jika tidak ada kata yang terdeteksi
172188
return this.clean(this.position());
173189
} else {
174190
return this._text.trim();
175191
}
176192
}
193+
177194

178195
set cleans(value: string) {
179196
throw value;

0 commit comments

Comments
 (0)