import { Job } from '../../common/job' ; import { IContainer , Mode } from '../../common/types' ; import { TextChannel } from 'discord.js' ; import ms from 'ms' ; interface IWeatherEvent { features ? : IFeaturesEntity [ ] | null ; } interface IFeaturesEntity { properties : IProperties ; } interface IProperties { severity : string ; headline : string ; senderName : string ; } export class WeatherEventsJob extends Job { public override name : string = 'Weather Events' ; public override interval : number = ms ( '1h' ) ; private static readonly _ENDPOINT : string = 'https://api.weather.gov/alerts/active?area=FL' ; constructor ( ) { super ( ) ; } public override async execute ( container ) { if ( process . env . NODE_ENV === Mode . Production ) { return ; } const channel = container . guildService . getChannel ( 'weather_events' ) as TextChannel ; const resp = await container . httpService . get ( WeatherEventsJob . _ENDPOINT ) ; const data = resp . data ; if ( ! data . features || data . features . length === 0 ) { return ; } const headlines = data . features . filter ( ( feature ) => { const highSeverity = feature . properties . severity === 'Severe' || feature . properties . severity === 'Extreme' ; return highSeverity && feature . properties . senderName . includes ( 'Orlando' ) ; } ) . map ( ( feature ) => feature . properties . headline ) ; if ( headlines . length === 0 ) { return ; } await channel . send ( headlines . reverse ( ) . join ( '\n' ) ) . catch ( ( err ) => console . log ( err ) ) ; } }