Unique Entries Per User

I am attempting to create a set of unique responses for Nightbot. I was looking at this thread and it seems like it’s possible to have unique user commands, but would it require me to essentially add that command for each individual user? The idea is that people could update their own pronouns in chat and then people could do “!pronouns BobTheBuilder” and get back “BobTheBuilder’s pronouns are he/him” etc. This sounds like it could potentially be done with a database but I have no idea how that would work with Nightbot.

@TamiJo Heya, welcome to the community. To be honest, I don’t understand what you actually want. Based on my understanding (ignore my understanding level) command should be like this.

!addcom -cd=5 !pronouns $(eval x = { "user1": "pronouns1", "user2": "pronouns2", "user3": "pronouns3", ..., "userN": "pronounsN" }; try { `$(query)'s pronouns are ` + x.$(query) } catch (e) { "$(query) invalid!" })

Now the problems come that, you can only type up to 200 characters in its response (if adding via Dashboard). You need to make a Pastebin code in such a situation.
Like this:

{
   "user1": "pronouns1",
   "user2": "pronouns2",
   "user3": "pronouns3",
   "user4": "pronouns4",
   "user5": "pronouns5",
   ...,
   ...,
   "userN": "pronounsN"
}

Then you need to fetch the data with $(urlfetch) variable. And the main command would be like this.

!addcom -cd=5 !pronouns $(eval x = $(urlfetch json https://pastebin.com/raw/XXXXXX); try { `$(query)'s pronouns are ` + x.$(query) } catch (e) { "$(query) invalid!" })

Example usage:

Ritik: !pronouns user1
Nightbot: user1's pronouns are pronouns1
Ritik: !pronouns user2
Nightbot: user2's pronouns are pronouns2
Ritik: !pronouns user_3
Nightbot: user_3 invalid!

Hope this helps, I didn’t try this command so if you face any error do ask.
Regards

1 Like

Thanks for the welcome and the response.

This seems a little more in depth than I’m used to, (which is ideal because that means I might be able to understand it, if you’re willing to help me a bit) so I have just a couple of questions:

Firstly; what is the -cd=5 command here? I’m not familiar with this at all.

Secondly; the rest of the command then reads to me as:

‘eval X’ takes input from the user as X.
‘$(URLfetch’ asks Nightbot to check the Pastebin for the data.
‘X.$(query)’ uses the input of the username to check that section of the code on pastebin.
‘catch (e)’ is an exception clause

EDIT: Sorry, also, would this allow users to add their pronouns? I don’t see any allowance for that. It looks like I would just need to add them to the Pastebin manually?

Thank you for the Pastebin trick and how to use it, though. That definitely covers a really large chunk of what I wanted to do.

@TamiJo Ready to go!

  1. -cd=5 : cd means cooldown. This is the minimum amount of time before the command can be used after it’s used. -cd=5 mean cooldown is set to 5 seconds. By default, if you are adding commands from chat, the cooldown is of 30 seconds. I don’t know about Twitch, but on YouTube, it is of 30 seconds.
  2. We made an object in Pastebin and fetch the data using $(urlfetch), in JSON format 'cause the list/data may be more than 400 characters.
  3. Then we store that object in variable x.
  4. x.$(query) will return/print the respective value from the name (objects are in "name": "value" format, basically).
  5. try { } catch ( ) { }, this method with check whether the x.$(query) is returning something, or it’s giving error, if error, it will return $(query) invalid!. Basically this method is used for handling errors.

No, it won’t allow users to add their own pronouns, correct, you need to do that manually.

Hope this will clear all your issues, but still remains any, let me know.
Regards

1 Like

Thank you very much. I assume there isn’t a way to have a command that adds to that JSON file?

@TamiJo Me too, you can’t add any data via this command :)

1 Like

Hey! Thanks for your help so far, but I’m just getting the response “Code generation from strings disallowed for this context” from the bot at this point. I originally tried to do it from scratch using the description you gave, until eventually I copy/pasted your code and replaced the link with the appropriate one.

I feel like it could be something to do with my Pastebin settings, which while I know isn’t really the scope of this forum, I would appreciate if you could LMK what I might have wrong?

EDIT: Also, when I do it without the pastebin it always returns “[User1]'s pronouns are undefined”. It looks like there’s a slightly more intense problem here. If I choose something that isn’t a user (just typing user3) it returns correctly. It is like the formatting of it @ing a user is causing an issue.

If you have any solutions for this that would be great, but I realise it might be getting a bit needy.

EDIT2: I fixed it. The Pastebin was password protected. >_<

Hey @TamiJo!

If you want to get users specify their own pronouns, allow me to redirect you to the quote system API. You’ll get your TOKENS by clicking on the second link in the post, in the Manual Installation section, use these in the commands I wrote. To know where to look for your PUBLIC_TOKEN and PRIVATE_TOKEN, look at the field bellow:

$(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))

Keep your PRIVATE_TOKEN secret, don’t share it anywhere. Add the following commands from the dashboard. Don’t use the chat as anyone could monitor it and copy the token, they could then edit your data.


Edit: improved the commands a bit.

We won’t use $(querystring) alone however, as we’ll use the API to store something else than quotes, so you’ll have…
!addpronouns:

$(eval `$(query)`.replace(/</g,``).replace(/>/g,``))

_addpronouns:

$(eval a=`$(urlfetch http://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=$(user)%20$(querystring))`; a.includes(`Successfully added entry`)?`$(user) added their pronouns to the list: $(query)`:`Error: ${a}`)

!!! Note: _addpronouns is the alias of !addpronouns, therefore make sure to fill the alias field of !addpronouns with _addpronouns.

!pronouns:

$(eval p=`$(urlfetch http://twitch.center/customapi/quote?token=PUBLIC_TOKEN&data=$(touser)&no_id=1)`.split(` `); u=p.shift(); u.toLowerCase()==`$(touser)`.toLowerCase()?`$(touser)'s pronouns are ${p.join(` `)}.`:`$(touser) has yet to add their pronouns to the list, they can do so by using !addpronouns <pronouns>`)

Example of usage:
Emily: !pronouns BobTheBuilder
Nightbot: BobTheBuilder’s pronouns are he/him.
Emily: !pronouns TamiJo
Nightbot: TamiJo has yet to add their pronouns to the list, they can do so by using !addpronouns <⁣pronouns>
Emily: !pronouns
Nightbot: Emily has yet to add their pronouns to the list, they can do so by using !addpronouns <⁣pronouns>
Emily: !addpronouns she/her
Nightbot: Emily added their pronouns to the list: she/her
Emily: !pronouns
Nightbot: Emily’s pronouns are she/her.

3 Likes

WOAH, thank you!

This looks a little complicated at the moment, but I will definitely look into it shortly. :blush:

2 Likes

@TamiJo Replace $(user) with $(touser) or you can use `$(query)`.replace(`@`,``)

Regards

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