Skip to content

Commit

Permalink
excluded words fix
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesabarnes committed Oct 25, 2024
1 parent 282baec commit 6ba6996
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
{
"leagueId": "4370",
"notifyRoleId": "1244253264787279873",
"channelId": "565267644627025930"
"channelId": "565267644627025930",
"excludedWords": ["practice"]
},
{
"leagueId": "4407",
Expand Down
13 changes: 11 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface ConfigLeague {
leagueId: string;
notifyRoleId: string;
channelId: string;
excludedWords?: string[];
}

type Game = {
Expand Down Expand Up @@ -80,13 +81,13 @@ async function checkUpcomingGames() {
});

const leaguePromises = (config?.leagues || []).map(async (league) => {
await fetchUpcomingLeagueEvents(league.leagueId, league.notifyRoleId, league.channelId);
await fetchUpcomingLeagueEvents(league.leagueId, league.notifyRoleId, league.channelId, league.excludedWords);
});

await Promise.all([...teamPromises, ...leaguePromises]);
}

async function fetchUpcomingLeagueEvents(leagueId: string, notifyRoleId: string, leagueChannelId: string) {
async function fetchUpcomingLeagueEvents(leagueId: string, notifyRoleId: string, leagueChannelId: string, excludedWords?: string[]) {
try {
const url=`https://www.thesportsdb.com/api/v1/json/${SPORTSDB_API_KEY}/eventsnextleague.php?id=${leagueId}`;
const response = await fetch(url);
Expand All @@ -95,6 +96,14 @@ async function fetchUpcomingLeagueEvents(leagueId: string, notifyRoleId: string,

if (events && events.length > 0) {
for (const event of events) {

if (excludedWords && excludedWords.length > 0) {
const excluded = excludedWords.some(word => event.strEvent.toLowerCase().includes(word.toLowerCase()));
if (excluded) {
continue;
}
}

const gameDate = new Date(event.dateEvent + ' ' + event.strTime);
const game = {
eventId: event.idEvent,
Expand Down

0 comments on commit 6ba6996

Please sign in to comment.