Creating a count command for referrals

Hey there forum,

So I’m one of those computer code-illiterate savages.

I’m trying to create a !refer command in my channel, where if someone types !refer (username), then that user will accumulate a point. After three points, they are eligible to take place in a raffle.

Additionally, I’m not sure if there is a way to cap/limit the number of referrals per account to one particular user to 1.

Many thanks.


Using $(count) won’t work because it is a general counter. There’s no native way to setup user-specific counters. But I’ve come up with a workaround below.

Click this link. It will generate three links and two tokens, a public token (8 characters long) and a private token (16 characters long). The public token is located within the first generated link. The private token is located within both the second and third generated links. The tokens are found after token= and before &data=$(querystring) Copy them down and keep them somewhere safe!

I have set up 3 commands below, !refer and _!refer which work in tandem to register a referral (only !refer is meant to be used directly) and determine a user’s eligibility to enter the raffle (at least 3 referrals), and !referclear (mod-only) which clears all referrals. Copy and paste the command setups into chat one by one to add the commands. Replace PUBLIC_TOKEN with your public token and PRIVATE_TOKEN with your private token.

!addcom -cd=5 !refer -a=_!refer $(eval u=`$(user)`;a=decodeURIComponent(`$(querystring)`);b=`~${u}~${a}~`;`PRIVATE_TOKEN`+(a&&`$(twitch $(query))`!=`Unknown Twitch Channel`&&`$(urlfetch$(user)~$(query)~&no_id=1)`.toLowerCase()!=b.toLowerCase()?`&data=`+b:``))

!addcom -cd=5 _!refer $(eval a=`$(urlfetch$(query))`;b=decodeURIComponent(`$(querystring)`);c=b.split(`~`)[2];d=`$(urlfetch json`.match(RegExp(`~\\w+~${c}~`,`gi`));e=d?d.length:0;b.includes(`PRIVATE_TOKEN`)?(a.includes(`Successfully added entry`)?`$(user) has referred ${c}! ${c} has been referred ${e} times${e>=3?` and is eligible to enter the raffle`:``}.`:`Already referred/Invalid name!`):` `)

!addcom -ul=mod !referclear $(eval `$(urlfetch`==`All entries have been deleted`?`The referrals list has been cleared!`:`Try again later...`)

Command usages:
!refer [user to refer]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.