dev pfp
dev
@frag.eth
Alright... time to write the script that calculates the Sunday raffle winners! ...will try to break it down slowly in the thread šŸ§µ
4 replies
3 recasts
17 reactions

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

dev pfp
dev
@frag.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
@frag.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
@frag.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
@frag.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
@frag.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
@frag.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
@frag.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