NightDev Community Forums

Using Nighbot to run a simple Auction

Hi team,

I’d like to use Nightbot to run a relatively simple auction using Twitch’s Chat.

Bidding:

User would input ‘!bid [number]’ to make a bid. For example, !bid 5.

If this is the highest bid, Nightbot would return a string to confirm that the User is the highest bidder.

Check top bid:

Users can input !topbid and Nightbot would return a string to confirm what the current top bid is and the User name with the top bid.

Reset:

Mods should have the ability to reset the auction using a comment - !restartauction.

Any guidance would be greatly appreciated!

Hey @Cavmyster!

Your best bet would be to write your own API for it.

Thanks @Emily.

Writing my own API is beyond me unfortunately. Is this something that would be easy to commission someone to assist with? If so, any suggestions on how I could find someone to help?

You could commission someone for that, yes. However, I don’t know where you’d go, there’s Fiverr I know about, but I never used it, I don’t know if you can get a dev there, but you likely can.


Another solution would be to use the Quote System API, since it’s just a bidding system it should be alright, although know that any abuse of it could mean the termination of your keys/tokens:

I think something like this could work:
!bid, is made out of !bid and its alias _bid, they respectively are:

$(eval q=`$(1)`;a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=0)`.split(`|`);a.pop();u=[];b=[];a.forEach(e=>{t=e.split(` `);b.push(t.pop());u.push(t.pop())});m=Math.max(...b);if(m===-Infinity){m=0}i=b.indexOf(`${m}`);if(q>0){if(m>=q){`$(user) — You need to bid higher than ${b[i]} (${u[i]}).`}else{`PRIVATE_TOKEN&data=$(user) ${q}|`}}else{`$(user) — A bid must be a number above 0.`})

$(eval q=decodeURIComponent(`$(querystring)`);a=`$(urlfetch https://twitch.center/customapi/addquote?token=$(query))`;if(q.includes(`PRIVATE_TOKEN`)){if(a.includes(`Successfully added entry`)){q=q.replace(`PRIVATE_TOKEN&data=`,``).replace(`|`,``).split(` `);`${q[0]} successfully bid ${q[1]}.`}else{`$(user) — There was an error, try again.`}}else{q})

!topbid:

$(eval a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=0)`.split(`|`);a.pop();u=[];b=[];a.forEach(e=>{t=e.split(` `);b.push(t.pop());u.push(t.pop())});m=Math.max(...b);if(m===-Infinity){m=0}i=b.indexOf(`${m}`);if(m>0){`${u[i]} has the top bid with ${b[i]}`}else{`$(user) — There are no bids yet, be the first!`})

!resetauction:

$(urlfetch https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&clear=1)

You need to replace the PUBLIC_TOKEN (2) and PRIVATE_TOKEN (4) fields, to generate them click on the second link in the Quote API System topic: the PUBLIC_TOKEN is 8 characters long, the PRIVATE_TOKEN is 16 characters long, it’s the string after the ?token= part.

Make sure that _bid is the alias of !bid, and that !resetauction is mod-only.

Please don’t add the commands containing your PRIVATE_TOKEN through the chat, keep them secret, don’t even post them here.


Hopefully that’ll work first try, I didn’t have time to test it. :crossed_fingers: If there’s an issue please take screenshots (without the PRIVATE_TOKEN) and I’ll try to fix it, but you’ll have to give me time, I’m busy lately.

The !bid command checks if the user is bidding an amount above the current top bid, if not it informs them and their entry isn’t counted.

If you want a different output to !resetauction, which you likely will, let me know what’s the current output and your desired one, and I’ll update the code.

Thank you @Emily!

I’ll give this a try and test. As I think about this system more, I’m starting to think that using a Google Sheet (or something similar) to collect all the bids and usernames would be an important step to ensure nobody can come in with a bogus bid and undermine the whole feature.

I’ll likely post the assignment on Fiver (I’d prefer to pay people for their time - don’t want to take advantage of anyone’s generosity :slight_smile: ).

Well, by using the Quote API you can remove the bids that just don’t make sense and break the whole thing.
Or you can also remove the check I put in place to make sure people always bid higher, so people can bid whatever they want.

If you end up going on Fiverr, make sure they know what Nightbot is and that they know the documentation and things like that, would hate to see you scammed. But the Quote API should be enough for what you’re trying to do, the Google Sheet seems a bit overkill.

1 Like

Thanks @Emily!

Do you by any chance know if the Quote API can be used to generate a list of bids?

I can see there is a way to generate a list of quotes, though I’m not sure whether it would also include the username of the person that contributed the bid/quote.

If we can do something like this then I think we’re gold. Essentially I just want to make sure that, if the top bidder doesn’t pay up, we know who to contact as the next highest bidder.

@Emily thanks for your help with this.

I’ve attached some images of the test. It seems to accept the bids ok, but there are some errors in recalling the highest bidder name and the amount of the highest bid.

I’m copying the code here as well (minus the private key).

Lastly, I’ve added the image of the !bid command to show how I’ve set the _bid as alias (hopefully I’ve done this correctly).

1 Like

@Emily so I worked out how to do a bidder’s list by using the following code:

$(urlfetch https://twitch.center/customapi/quote?token=40522ace&data=list)

That works perfectly! I’m not sure if there would be a way to sort that list from highest to lowest.

It looks like the only thing I need help with is getting the ‘undefined’ issue resolved when the !topbidder command is used and when someone doesn’t bid higher than the highest bidder.

1 Like

It will because I associated the bid with the username.


Yup, I believe I identified the error, for some reason the # isn’t pushed to the quote list. So I’m gonna update the commands accordingly bellow.

Yes, that’s perfect.


Glad you figured it out!

There isn’t, but since the !bid command always makes sure the new bid is higher than the last one (if you’d like to change this behavior, let me know), this shouldn’t be an issue, the bids will be in ascending order.


Alright, let’s fix the broken code:

!bid and _bid respectively:

$(eval q=`$(1)`;a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=0)`.split(`|`);a.pop();u=[];b=[];a.forEach(e=>{t=e.split(` `);b.push(t.pop());u.push(t.pop())});m=Math.max(...b);if(m===-Infinity){m=0}i=b.indexOf(`${m}`);if(q>0){if(m>=q){`$(user) — You need to bid higher than ${b[i]} (${u[i]}).`}else{`PRIVATE_TOKEN&data=$(user) ${q}|`}}else{`$(user) — A bid must be a number above 0.`})

$(eval q=decodeURIComponent(`$(querystring)`);a=`$(urlfetch https://twitch.center/customapi/addquote?token=$(query))`;if(q.includes(`PRIVATE_TOKEN`)){if(a.includes(`Successfully added entry`)){q=q.replace(`PRIVATE_TOKEN&data=`,``).replace(`|`,``).split(` `);`${q[0]} successfully bid ${q[1]}.`}else{`$(user) — There was an error, try again.`}}else{q})

!topbid:

$(eval a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=0)`.split(`|`);a.pop();u=[];b=[];a.forEach(e=>{t=e.split(` `);b.push(t.pop());u.push(t.pop())});m=Math.max(...b);if(m===-Infinity){m=0}i=b.indexOf(`${m}`);if(m>0){`${u[i]} has the top bid with ${b[i]}`}else{`$(user) — There are no bids yet, be the first!`})

@Emily thanks again for all your help.

There appears to be something broken :frowning: .

image

Any ideas?

Well, that’s… surprising.
As far as I can see, the quotes are properly added this time, so it should work just fine… Yet it doesn’t. Ok, I’ll review the code once more and take the time to test it before sending it to you.

1 Like

Alright, I figured it out, finally:

!bid and _bid respectively:

$(eval q=`$(1)`;a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=0)`.split(`|`);a.pop();u=[];b=[];a.forEach(e=>{t=e.split(` `);b.push(t.pop());u.push(t.pop())});m=Math.max(...b);if(m===-Infinity){m=0}i=b.indexOf(`${m}`);if(q>0){if(m>=q){`$(user) — You need to bid higher than ${b[i]} (${u[i]}).`}else{`PRIVATE_TOKEN&data=$(user) ${q}|`}}else{`$(user) — A bid must be a number above 0.`})

$(eval q=decodeURIComponent(`$(querystring)`);a=`$(urlfetch https://twitch.center/customapi/addquote?token=$(query))`;if(q.includes(`PRIVATE_TOKEN`)){if(a.includes(`Successfully added entry`)){q=q.replace(`PRIVATE_TOKEN&data=`,``).replace(`|`,``).split(` `);`${q[0]} successfully bid ${q[1]}.`}else{`$(user) — There was an error, try again.`}}else{q})

!topbid:

$(eval a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=0)`.split(`|`);a.pop();u=[];b=[];a.forEach(e=>{t=e.split(` `);b.push(t.pop());u.push(t.pop())});m=Math.max(...b);if(m===-Infinity){m=0}i=b.indexOf(`${m}`);if(m>0){`${u[i]} has the top bid with ${b[i]}`}else{`$(user) — There are no bids yet, be the first!`})
2 Likes

IT WORKS! Thanks so much for all your help @Emily - you’re an absolute legend!

1 Like