Need help with custom commands.

The command uses this link:
Is it possible to hide the API key from other people using the command like if they were to check commands for my channel? If it will show in the command list under my Nightbot for my twitch channel, then disregard everything else here as the API key should be private.

I want to make a command that sends the “map” and “remainingTimer” under “current”, I want it to look like: "The current map is: “map” with “remainingTimer” left.

Then another command that sends the “map”, “readableDate_start” and “remainingMins” under “next”, which’ll say: "The next map is: “map” in “readableDate_start” for “remainingMins” minutes.
If possible, calculate how many hours before it’ll happen with the “readableDate_start”.

    "battle_royale": {
        "current": {
            "start": 1649966400,
            "end": 1649971800,
            "readableDate_start": "2022-04-14 20:00:00",
            "readableDate_end": "2022-04-14 21:30:00",
            "map": "Kings Canyon",
            "code": "kings_canyon_rotation",
            "DurationInSecs": 5400,
            "DurationInMinutes": 90,
            "asset": "https:\/\/\/assets\/maps\/Kings_Canyon.png",
            "remainingSecs": 1400,
            "remainingMins": 23,
            "remainingTimer": "00:23:20"
        "next": {
            "start": 1649971800,
            "end": 1649977200,
            "readableDate_start": "2022-04-14 21:30:00",
            "readableDate_end": "2022-04-14 23:00:00",
            "map": "Storm Point",
            "code": "storm_point_rotation",
            "DurationInSecs": 5400,
            "DurationInMinutes": 90

By design, users checking the public commands list are not able to see the actual URL you are calling. It will just show them [urlfetch], like this:

So no one will see the API key you are using in your request. Only people with access to add/edit commands will see the actual URL. If you do not want that, you would need to add some kind of proxy that would forward the request with the API key added on some server-side script.

For the commands, something like this should work:

Get current map

$(eval const api = $(urlfetch json; "The current map is: " + + " with " + api.battle_royale.current.remainingTimer + " left.")

Get next map

$(eval const api = $(urlfetch json; "The next map is: " + + " in " + + " for " + + " minutes.")

For a “fancy time” in the latter, you would need to know the timezone in which the dates are represented (most likely UTC, as most APIs do) and you could use the Countup command to make it look more fancy in there.

1 Like

Thank you for the explanation and help.

Would it be possible to convert “remainingTimer” to an easier way to read it? For example, “00:23:20” (hh:mm:ss) to 23 minutes and 20 seconds? Not sure how to use countup for this.

Making the assumption that the timestamp in remainingTimer will always be in hours:minutes:seconds format, you can split it on the colon and grab the elements separately.

api.battle_royale.current.remainingTimer.split(":")[0] // hours
api.battle_royale.current.remainingTimer.split(":")[1] // minutes
api.battle_royale.current.remainingTimer.split(":")[2] // seconds

So putting that together in a complete command, you’d end up with something like (added some linebreaks for readability):

  const api = $(urlfetch json;
  "The current map is: " + + " with " +
  api.battle_royale.current.remainingTimer.split(":")[1] + " minutes and " +
  api.battle_royale.current.remainingTimer.split(":")[2] + " seconds left."

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.