@@ -62,14 +62,18 @@ export function shouldFilterMessage(action: Chat.MessageAction): boolean {
62
62
if ( ! condition . value ) {
63
63
numValidFilters -- ;
64
64
} else {
65
- try {
66
- const regex = parseRegex ( condition . value ) ;
67
- const result = regex . test ( compStr ) ;
68
- if ( result === condition . invert ) {
69
- break ;
70
- }
71
- } catch ( e ) {
72
- console . error ( e ) ;
65
+ // try {
66
+ // const regex = parseRegex(condition.value);
67
+ // const result = regex.test(compStr);
68
+ // if (result === condition.invert) {
69
+ // break;
70
+ // }
71
+ // } catch (e) {
72
+ // console.error(e);
73
+ // break;
74
+ // }
75
+ const { result, error } = testRegex ( condition . value , compStr ) ;
76
+ if ( error || result === condition . invert ) {
73
77
break ;
74
78
}
75
79
}
@@ -84,6 +88,22 @@ export function shouldFilterMessage(action: Chat.MessageAction): boolean {
84
88
return false ;
85
89
}
86
90
91
+ export const testRegex = ( expression : string , value : string ) : { result : boolean ; error : Error | false ; } => {
92
+ try {
93
+ const regex = parseRegex ( expression ) ;
94
+ return {
95
+ result : regex . test ( value ) ,
96
+ error : false
97
+ } ;
98
+ } catch ( e ) {
99
+ console . error ( e ) ;
100
+ return {
101
+ result : false ,
102
+ error : e as Error
103
+ } ;
104
+ }
105
+ }
106
+
87
107
export function shouldActivatePreset ( preset : YtcF . FilterPreset , info : SimpleVideoInfo ) : boolean {
88
108
for ( const trigger of preset . triggers ) {
89
109
let compStr = '' ;
@@ -111,13 +131,15 @@ export function shouldActivatePreset(preset: YtcF.FilterPreset, info: SimpleVide
111
131
const result = s1 [ trigger . type ] ( s2 ) ;
112
132
if ( result ) return true ;
113
133
} else {
114
- try {
115
- const regex = parseRegex ( trigger . value ) ;
116
- const result = regex . test ( compStr ) ;
117
- if ( result ) return true ;
118
- } catch ( e ) {
119
- console . error ( e ) ;
120
- }
134
+ // try {
135
+ // const regex = parseRegex(trigger.value);
136
+ // const result = regex.test(compStr);
137
+ // if (result) return true;
138
+ // } catch (e) {
139
+ // console.error(e);
140
+ // }
141
+ const { result } = testRegex ( trigger . value , compStr ) ;
142
+ if ( result ) return true ;
121
143
}
122
144
}
123
145
return false ;
0 commit comments