Countdown timer for PCG

Hello,

I’m trying to add a countdown timer till the next Pkmn spawn which is every 15mins)

URL: https://poketwitch.bframework.de/info/events/last_spawn/
example of JSON output: {“next_spawn”: 597, “pokedex_id”: 703, “event_time”: “2022-07-22T17:19:32.960Z”}

Here so far, I can URLfetch and eval the last event time using
!editcom test $(eval top=$(urlfetch json https://poketwitch.bframework.de/info/events/last_spawn/).event_time)

returns
test
nightbot: 2022-07-22T18:49:33.323Z

Now, I want to add 15mins to this timer and countdown from for the next spawn.

any help?

Hey @malice_dumpling!

You’ll need two commands and the $(countdown) variable to do this, the second command will be an alias of the first one, below you’ll find the code to add the commands through your chat.

First, !pcg — the command you call, it fetches the data from the API, adds 15 minutes (900000 milliseconds), and then formats it properly for the $(countdown) variable.

!addcom !pcg -a=_pcg $(eval t = $(urlfetch json https://poketwitch.bframework.de/info/events/last_spawn/).event_time; d = new Date(t).getTime() + 900000; `${new Date(d).toLocaleString('en-US', { timeZone: 'UTC' })} UTC`)

Second, _pcg — automatically called after !pcg executed:

!addcom _pcg Next Pkmn spawn in $(countdown $(query))