bot filter work

This commit is contained in:
Corban-Lee Jones 2025-05-12 23:45:37 +01:00
parent 0297fb12b6
commit ba286e769b

View File

@ -52,12 +52,12 @@ const processItems = async (items: RssParser.Item[], feed: ExpandedFeed, channel
}; };
const processItem = async (item: RssParser.Item, feed: ExpandedFeed, channel: DiscordChannel, client: Client) => { const processItem = async (item: RssParser.Item, feed: ExpandedFeed, channel: DiscordChannel, client: Client) => {
const filterPromises = feed.filters.map(async filter => { for (const filter of feed.filters) {
return passesFilter(filter, item); if (!await passesFilter(filter, item)) {
}); console.log("fails filter")
return;
const filterResults = await Promise.all(filterPromises); }
if (filterResults.includes(false)) return; }
const embed = new EmbedBuilder(); const embed = new EmbedBuilder();
embed.setTitle(item.title ?? null); embed.setTitle(item.title ?? null);
@ -79,7 +79,7 @@ const getItemImageUrl = async (url: string) => {
}; };
const passesFilter = async (filter: Filter, item: RssParser.Item) => { const passesFilter = async (filter: Filter, item: RssParser.Item) => {
if (!filter.matching_algorithm.trim()) return !filter.is_whitelist; if (!filter.value.trim()) return !filter.is_whitelist;
let matchFound = false; let matchFound = false;
@ -92,5 +92,7 @@ const passesFilter = async (filter: Filter, item: RssParser.Item) => {
); );
} }
return filter.is_whitelist ? matchFound : !matchFound; console.log(`${matchFound} - ${filter.is_whitelist}`);
return filter.is_whitelist ? !matchFound : matchFound;
}; };