dev pfp
dev
@photoshop.eth
Alright... time to write the script that calculates the Sunday raffle winners! ...will try to break it down slowly in the thread 🧡
14 replies
15 recasts
22 reactions

dev pfp
dev
@photoshop.eth
First of all... to view the raffle thread and all the entries I'm using @super because @warpcast hides some of the comments.
1 reply
1 recast
1 reaction

dev pfp
dev
@photoshop.eth
Then I inspect the DOM to find the list of entries and check that it matches the reply count (at the moment 508)
1 reply
1 recast
1 reaction

dev pfp
dev
@photoshop.eth
Getting a random entry is easy with the random node select script we've used before, but this time we need to add some extra entries for user who gave tips
1 reply
0 recast
0 reaction

dev pfp
dev
@photoshop.eth
Now the cast HTML structure is a bit funky on Supercast so to get the winner name we have to use a querySelector "a a + a a" and build the entry mapping with inital entries of 1 (the free entry)
1 reply
0 recast
0 reaction

dev pfp
dev
@photoshop.eth
To calculate the tips we need to find the cast message and we need to use another querySelector
1 reply
0 recast
0 reaction

dev pfp
dev
@photoshop.eth
To find the tip amount and calculate tip entries we can use a regular expression to search through the message. Then we take the first matching group, divide by 100 and return it with a maximum of then and rounding the value down.
1 reply
0 recast
0 reaction

dev pfp
dev
@photoshop.eth
Next we take all of the entries and create one long ass array with one handle per entry
1 reply
0 recast
0 reaction

dev pfp
dev
@photoshop.eth
Next we need to pick the winner handles from the array. First, for good measure, we randomize the array. Then pick 8 winners and return the winners object πŸŽ‰
1 reply
0 recast
0 reaction

dev pfp
dev
@photoshop.eth
Now this test run gives us 968 entries to choose from. But these are not the final winners. The raffle will be held in two hours! If you read all the way here and see your handle πŸ‘‡ drop a comment and I'll give you an extra tip πŸ˜‰
0 reply
0 recast
0 reaction