2025-01-26 14:10:11 -05:00
import { WebhookClient } from "discord.js" ;
import { summary } from "./api.js" ;
import { readFileSync } from "fs" ;
const config = readFileSync ( process . argv [ 1 ] , "utf-8" ) ;
2025-01-26 14:19:48 -05:00
console . log ( config ) ;
2025-01-26 14:10:11 -05:00
const webhook = new WebhookClient ( { url : config . webhook } ) ;
for ( let user of config . users ) {
let result = await summary ( user . wktoken ) ;
let current _reviews = result . data . reviews . filter ( review => new Date ( review . available _at ) < new Date ( ) ) . map ( lesson => lesson . subject _ids ) . flat ( ) ;
let future _reviews = result . data . reviews . map ( review => review . subject _ids ) . flat ( ) ;
let future _time = new Date ( result . data . reviews . at ( - 1 ) . available _at ) ;
if ( current _reviews . length > 0 ) {
let message = ` <@ ${ user . discord } > You have reviews! If you do your wanikani now, there's only ** ${ current _reviews . length } **! <t: ${ Math . floor ( future _time / 1000 ) } :R> you'll have ** ${ future _reviews . length } ** reviews. ` ;
await webhook . send ( {
content : message ,
username : "WaniKani Reminder" ,
avatarURL : "https://pbs.twimg.com/profile_images/1213575248911552512/WP11ESTy_400x400.jpg" ,
} )
}
}