Skip to content

Instantly share code, notes, and snippets.

@markcarey
Created February 18, 2024 17:22
Show Gist options
  • Save markcarey/2c100f96bf1051f96ead250c9167d906 to your computer and use it in GitHub Desktop.
Save markcarey/2c100f96bf1051f96ead250c9167d906 to your computer and use it in GitHub Desktop.
Count $DEGEN in thread
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`;
}
@markcarey
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment