!userfact command help

Yes, so that code doesn’t store data durably anywhere, it wouldn’t work with Nightbot, it contains errors, and it could be rewritten so it’s easier to read.

ChatGPT, or any other AI, isn’t able to write code that works just like that (yet), you have to give it a well thought out prompt, it should have context clues to understand how to write code that integrates well with the existing code base/framework/tool(s), and you should know how to write code so you can fix its mistakes, we’re still at least years away from replacing devs completely, for now it’s just a tool to assist us.


To make a similar command with what we have, we’re going to use the Quote API I mentioned before, get your tokens by following the Manual Installation link.
Refer to the following to identify your PUBLIC_TOKEN and PRIVATE_TOKEN:

$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&data=$(querystring))
$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=$(querystring))
$(urlfetch https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&data=$(querystring))

Copy them and store them somewhere safe, never share your PRIVATE_TOKEN, anyone could then manage your list, that’s why the code I’ll write won’t contain command calls to add the new commands through the chat, add the new commands through the dashboard.


We need three commands: one to consult a fact about someone, one to set a fact about oneself, and another one to delete the fact about oneself (we actually need more than three commands as the last two will require alias commands so we can add checks to avoid issues, but once set up, chatters will only use three commands).

  • !fact — get a fact about someone:

    $(eval f = `$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&data=$(touser)%3A)`; f.startsWith('0.') ? 'There are no fact about this chatter yet' : f;)
    

    :beginner: syntax: !fact optional_username

  • !addfact — add a fact about oneself:

    $(eval u = '$(user)'; q = `$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN)`.split(/\d+\.\s/).map(e => e.split(':')[0]); q.includes(u) ? 'you already added a !fact about yourself' : `PRIVATE_TOKEN&data=$(user)%3A%20$(querystring)`;)
    

    :warning: set this command’s alias to _addfact
    :beginner: syntax: !addfact a cool fact about myself

  • _addfact!addfact’s alias:

    $(eval a = `$(urlfetch https://twitch.center/customapi/addquote?token=$(query))`; f = decodeURIComponent(`$(query)`.replace('PRIVATE_TOKEN&data=$(user)%3A%20', '')); a.includes('Successfully added') ? `$(user) — your fact has been set to: ${f}` : `$(user) — there was an error: ${a.includes('Invalid') ? f : a}`;)
    

    :beginner: do not call this command, it’ll be automatically called by !addfact

  • !delfact — remove the fact about oneself:

    $(eval u = '$(user)'; q = `$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN)`.split(/\d+\.\s/).map(e => e.split(':')[0]); i = q.indexOf(u); i === -1 ? 'you haven\'t set a fact about yourself yet' : `PRIVATE_TOKEN&data=${i}`;)
    

    :warning: set this command’s alias to _delfact
    :beginner: syntax: !delfact

  • _delfact!delfact’s alias:

    $(eval a = `$(urlfetch https://twitch.center/customapi/delquote?token=$(query))`; f = decodeURIComponent(`$(query)`.replace('PRIVATE_TOKEN&data=', '').replace(/\d+/g, '')); a.includes('Successfully deleted') ? '$(user) — your fact has been successfully deleted' : `$(user) — there was an error: ${a.includes('Invalid') ? f : a}`;)
    

    :beginner: do not call this command, it’ll be automatically called by !delfact

:warning: Make sure to replace every instances of PUBLIC_TOKEN (3) and PRIVATE_TOKEN (4) with your tokens.