Created
February 18, 2024 17:22
-
-
Save markcarey/2c100f96bf1051f96ead250c9167d906 to your computer and use it in GitHub Desktop.
Count $DEGEN in thread
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (threadHash) { | |
const casts = await util.getAllCastsInThread(threadHash); // calls Neynar API to fetch all replies to a cast | |
var count = 0; | |
var regexp = /\b([0-9]+) \$degen\b/i; | |
for (var i = 0; i < casts.length; i++) { | |
//console.log("count", count); | |
var cast = casts[i]; | |
if (cast.parentHash == threadHash) { | |
var text = cast.text; | |
if (regexp.test(text)) { | |
var match = text.match(regexp); | |
count += parseInt(match[1]); | |
} // if regexp | |
} // if parentHash | |
} // for | |
frame.imageText = `This thread has received | |
${count.toLocaleString('en-US')} $DEGEN`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note this only counts tips in direct reply to the cast. In other words, if someone replies to a reply with a tip, then the tip goes to the replier and not the original caster, so we don't count.