Skip to content

Commit

Permalink
Merge pull request #30 from reddit-seattle/dev
Browse files Browse the repository at this point in the history
Ship NHL API V2
  • Loading branch information
burn-piano-island authored Dec 29, 2023
2 parents 0737681 + bcb35ab commit ac3f596
Show file tree
Hide file tree
Showing 52 changed files with 4,448 additions and 1,385 deletions.
1,323 changes: 832 additions & 491 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
"description": "",
"main": "dist/index.js",
"dependencies": {
"@discordjs/builders": "^0.8.2",
"@discordjs/rest": "^0.1.0-canary.0",
"@discordjs/builders": "^1.7.0",
"@discordjs/rest": "^2.2.0",
"date-fns": "^2.16.1",
"date-fns-tz": "^1.0.12",
"discord-api-types": "^0.24.0",
"discord.js": "^13.3.1",
"discord-api-types": "^0.37.66",
"discord.js": "^14.14.1",
"dotenv": "^8.2.0",
"fuzzball": "^1.3.1",
"node-cron": "^3.0.0",
"node-cron": "^3.0.3",
"node-fetch": "^2.6.7",
"table": "^6.8.1",
"underscore": "^1.12.1"
},
"devDependencies": {
"@types/node": "^14.14.16",
"@types/node-cron": "^2.0.4",
"@types/node-fetch": "^2.5.7",
"@types/underscore": "^1.10.24",
"typescript": "^4.3.5"
"typescript": "^5.3.3"
},
"scripts": {
"tsc": "tsc",
Expand Down
57 changes: 0 additions & 57 deletions src/commands/HelpCommands.ts

This file was deleted.

77 changes: 0 additions & 77 deletions src/commands/PlayerCommands.ts

This file was deleted.

51 changes: 0 additions & 51 deletions src/commands/PlayoffCommands.ts

This file was deleted.

102 changes: 102 additions & 0 deletions src/commands/Schedule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import {
EmbedBuilder,
SlashCommandBuilder,
SlashCommandSubcommandBuilder,
} from "@discordjs/builders";
import { Command } from "../models/Command";
import { API } from "../service/API";
import { Game as DayScheduleGame } from "../service/models/responses/DaySchedule";
import { Game as TeamWeeklyScheduleGame } from "../service/models/responses/TeamWeeklyScheduleResponse";
import { Game as TeamMonthlyScheduleGame } from "../service/models/responses/TeamMonthlyScheduleResponse";
import { format, utcToZonedTime } from "date-fns-tz";
import _ from "underscore";
import { optionalDateOption, processLocalizedDateInput, relativeDateString, requiredTeamOption, teamOrPlayerAutocomplete, validTeamName } from "../utils/helpers";
import { Config } from "../utils/constants";

const teamScheduleSubgroupCommand = new SlashCommandSubcommandBuilder()
.setName("team")
.setDescription("look up a team's schedule")
.addStringOption(requiredTeamOption)
.addStringOption((option) =>
option
.setName("type")
.setDescription("Weekly or Monthly")
.addChoices(
{ name: "weekly", value: "weekly" },
{ name: "monthly", value: "monthly" }
)
);
const leagueScheduleSubgroupCommand = new SlashCommandSubcommandBuilder()
.setName("all")
.setDescription("see all games")
.addStringOption(optionalDateOption);

export const GetSchedule: Command = {
name: "schedule",
description: "NHL Game Schedule",
slashCommandDescription: new SlashCommandBuilder()
.addSubcommand(leagueScheduleSubgroupCommand)
.addSubcommand(teamScheduleSubgroupCommand),
executeSlashCommand: async (interaction) => {
const subcommand = interaction.options.getSubcommand();
if (subcommand == "team") {
const team = interaction.options.getString("team", true);
if (!validTeamName(team)) {
interaction.reply("That's not an NHL team name buddy");
return;
}
await interaction.deferReply();
const monthly = interaction.options.getString("type") == "monthly";
const schedule = monthly
? await API.Schedule.GetTeamMonthlySchedule(team)
: await API.Schedule.GetTeamWeeklySchedule(team);
await interaction.followUp({
embeds: [ScheduleEmbedBuilder(schedule, `${team} ${monthly ? 'Monthly' : 'Weekly'}`)],
});
} /*if (subcommand = 'all') */ else {
await interaction.deferReply();
const dateInput = interaction.options.getString("date", false);
const adjustedDate = processLocalizedDateInput(dateInput);
const schedule = await API.Schedule.GetDailySchedule(adjustedDate);
await interaction.followUp({
embeds: [ScheduleEmbedBuilder(schedule, format(adjustedDate ?? new Date(), Config.TITLE_DATE_FORMAT))],
});
}
},
autocomplete: teamOrPlayerAutocomplete,
};

// TODO - EmbedBuilders module
const ScheduleEmbedBuilder = (
schedule: (
| DayScheduleGame
| TeamWeeklyScheduleGame
| TeamMonthlyScheduleGame
)[],
scheduleTypeDisplay: string
) => {
return new EmbedBuilder().setTitle(`${scheduleTypeDisplay} Schedule`).addFields(
schedule.map((item) => {
const {startTimeUTC, venue, awayTeam, homeTeam} = item;
const dateSlug = relativeDateString(startTimeUTC);
const dateStr = `${format(utcToZonedTime(startTimeUTC, Config.TIME_ZONE), Config.BODY_DATE_FORMAT)} (${dateSlug})`;
const venuStr = `Venue: ${venue.default}`
let output = `${dateStr}\n${venuStr}`
// only show radio links if available
const {radioLink: awayAudio} = awayTeam;
const {radioLink: homeAudio} = homeTeam;
const homeRadioStr = homeAudio && `[${homeTeam.abbrev}](${homeAudio})`;
const awayRadioStr = awayAudio && `[${awayTeam.abbrev}](${awayAudio})`;
if(homeRadioStr || awayRadioStr){
output+= `\nListen: ${[homeRadioStr, awayRadioStr].filter(x => x != undefined).join(' - ')}`;
}


return {
name: `${awayTeam.abbrev} @ ${homeTeam.abbrev}`,
value: output,
inline: false,
};
})
);
};
Loading

0 comments on commit ac3f596

Please sign in to comment.