feat(bot): implement 'literal' filter
All checks were successful
Build / build (push) Successful in 51s
All checks were successful
Build / build (push) Successful in 51s
This commit is contained in:
parent
d6a014ec91
commit
755bf32774
@ -11,6 +11,7 @@ function splitWords(filterValue: string): string[] {
|
||||
});
|
||||
}
|
||||
|
||||
// Includes all input words (space separated)
|
||||
export const all = (filter: Filter, input: string) => {
|
||||
try {
|
||||
const flags = filter.is_insensitive ? "i" : "";
|
||||
@ -22,6 +23,7 @@ export const all = (filter: Filter, input: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Includes any input word (space separated)
|
||||
export const any = (filter: Filter, input: string) => {
|
||||
try {
|
||||
const flags = filter.is_insensitive ? "i" : "";
|
||||
@ -34,10 +36,19 @@ export const any = (filter: Filter, input: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Includes exact input string
|
||||
export const literal = (filter: Filter, input: string) => {
|
||||
throw new Error("'literal' filter not implemented");
|
||||
try {
|
||||
const filterValue = filter.is_insensitive ? filter.value.toLowerCase() : input;
|
||||
const inputValue = filter.is_insensitive ? input.toLowerCase() : input;
|
||||
return inputValue.includes(filterValue);
|
||||
} catch (error) {
|
||||
console.error(`LITERAL: Invalid regex pattern: ${filter.value}`, error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Matches given regex pattern
|
||||
export const regex = (filter: Filter, input: string) => {
|
||||
try {
|
||||
const flags = filter.is_insensitive ? "i" : "";
|
||||
|
Loading…
x
Reference in New Issue
Block a user