Is there an existing API for saving key-value pairs

Nightbot doesn’t seem to offer functionality for creating your own global variables accessible by all commands (correct me if I’m wrong) so I am interested in if there are any popular/commonly recommended/existing APIs that allow me to accomplish what is virtually the same thing.

Basically I want to make a !deathcount command and a !adddeaths N command. I know I can use aliases to set the death count manually, and that’s what is currently set up, however an API like this will make the ideal setup possible, as well as make life easier in other situations as well.

So yeah, just something I’ve been looking for for a while, figured it was about time I ask here if anybody else is aware of something that would accomplish this or a relatively similar task. Thanks in advance for any help (even if it is gently letting me know that what I was isn’t a thing.)

You can store values using this quote system designed for Nightbot: [CustomAPI] Quote system

Go to You will see three lines. Your first token is after token= and before &data= on the first line. Your second token is after token= and before &data= on the second and third lines. Replace FIRSTTOKEN and SECONDTOKEN with these before you add the following commands.


$(eval quote = `$(urlfetch json`; deaths = quote == "There are no quotes added" ? 0 : quote; `Streamer has died ${deaths} time${deaths === "1" ? "" : "s"}!`)

!adddeath (alias to !adddeatheditor, userlevel moderator)

$(eval quote = `$(urlfetch json`; deaths = parseInt(quote); if (isNaN(deaths)){"$NOTINITIALIZED$"} else {delta = (`$(query)` ? parseInt(`$(query)`) : 1); if (isNaN(delta)){"$INVALIDQUERY$"} else{newDeathsEncoded = encodeURIComponent(deaths + delta); `?token=SECONDTOKEN&data=1%20${newDeathsEncoded}`}})

!adddeatheditor (userlevel moderator)

$(eval r=`$(urlfetch$(query))`;if (r.startsWith("Successfully modified entry ")){match=`$(query)`.match(/=1%20(.*)$/);if(match){deaths=decodeURIComponent(match[1]);`Streamer has now died ${deaths} time${deaths=="1"?"":"s"}!`}else{"!adddeath is misconfigured"}}else if(r=="Invalid entry index."||`$(query)`=="$NOTINITIALIZED$"){"A moderator must use !resetdeaths"}else if(`$(query)`=="$INVALIDQUERY$"){"Enter a number after !adddeath"}else{"Use !adddeath"})

!resetdeaths (userlevel moderator)

$(eval clearresponse = `$(urlfetch`; addresponse = `$(urlfetch`; (clearresponse === "All entries have been deleted" && addresponse === "Successfully added entry #1") ? "The death counter has been reset" : `Error initializing !deaths (${clearresponse}, ${addresponse})`)

So there’s no real API for this? I need to use a quote system as a hacky workaround?

It’s not really any more hacky than how a system specifically designed for key-value pairs would have to work.

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