Skip to content

Commit

Permalink
fix: sport keys to match guild config sport
Browse files Browse the repository at this point in the history
  • Loading branch information
fearandesire committed Dec 29, 2024
1 parent 60eebdb commit 9f16367
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/utils/guilds/channels/ChannelManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,19 @@ export default class ChannelManager {
*/
async processChannels(data: ScheduledChannelsData) {
const { channels, guilds } = data;

// ? Transform Sport Key in all Channels
const transformedChannels = channels.map((channel) => ({
...channel,
sport: StringUtils.sportKeyTransform(channel.sport) as SportsServing,
}));
// Process each guild separately
for (const guild of guilds) {
const eligibleChannels = _.chain(channels)
const eligibleChannels = _.chain(transformedChannels)
// First filter by sport
.filter((channel) => channel.sport === guild.sport)
// Then filter by preferred teams if they exist
.filter((channel) => {
if (!guild.preferred_teams?.length) return true;
if (!guild?.preferred_teams?.length) return true;

const teamsInMatch = [channel.home_team, channel.away_team];
return _.some(guild.preferred_teams, (team) =>
Expand Down

0 comments on commit 9f16367

Please sign in to comment.