Closed ghost closed 4 years ago
You will only get one subscription-type event call per event in that case. A giftpaidupgrade
and its anonymous version are not resubs. It's just a commitment by the user to upgrade/continue their subscription at a later date, and at that time they'll be prompted that they can send a resub message.
If you try logging the methods object, you'll see what's available. It's more simple than the IRC tags.
var plan = message.tags["msg-param-sub-plan"] || "";
var planName = _.unescapeIRC(_.get(message.tags["msg-param-sub-plan-name"], "")) || null;
var prime = plan.includes("Prime");
var methods = { prime, plan, planName };
https://github.com/tmijs/tmi.js/blob/master/lib/client.js#L646-L649
To log that, someone has to sub tho. Aren't there any examples of method object, because i have no idea what to do with that piece of code :sob: @AlcaDesign
const tierList = { 1000: 'Tier 1', 2000: 'Tier 2', 3000: 'Tier 3' };
client.on('resub', (channel, username, months, message, userstate, methods) => {
const { prime, plan, planName } = methods;
let msg = `${username} just resubbed`;
if(prime) msg += ' using Prime';
else if(plan !== '1000') msg += ' at ${tierList[plan]}';
client.say(channel, `${msg}!`);
});
If someone resubscribes with a Prime subscription, it will say 'Alca just resubbed using Prime!' If someone resubscribes at Tier 1, it will say 'Alca just resubbed!' If someone resubscribes at Tier 2, it will say 'Alca just resubbed at Tier 2!'!' If someone resubscribes at Tier 3, it will say 'Alca just resubbed at Tier 3!'
Here's a couple ways you can test the code:
const displayName = 'Alca';
const login = 'alca';
const roomID = '7676884';
const planList = [ 'Prime', '1000', '2000', '3000' ];
const plan = planList[0]; // Switch between 0, 1, 2, and 3 for each index of planList.
const message = 'Great stream -- keep it up!';
client._onMessage({
data: `@badges=staff/1,subscriber/6,turbo/1;badge-info=subscriber/8;color=#008000;display-name=${displayName};emotes=;flags=;id=00000000-0000-0000-0000-000000000000;login=${login};mod=0;msg-id=resub;msg-param-cumulative-months=8;msg-param-should-share-streak=0;msg-param-sub-plan-name=Channel\\sSubscription\\s(${displayName});msg-param-sub-plan=${plan};room-id=${roomID};subscriber=1;system-msg=${displayName}\\sSubscribed\\swith\\sTwitch\\sPrime.;tmi-sent-ts=${Date.now()};turbo=0;user-id=${roomID};user-type=staff :tmi.twitch.tv USERNOTICE #${login} :${message}`
});
onResub('#alca', 'Alca', 0, 'Yo yo yo', {}, { prime: false, plan: '2000', planName: 'Channel Subscription (Alca)' });
Ok that gives me some idea. Thank you so much for your time @AlcaDesign
Ok, so the
anongiftpaidupgrade
andgiftpaidupgrade
events confuse me a bit. Do I see these's events withresub
event too, or are they completely seperate events?Other thing is I can't figure out how to get subscription plan?
method["msg-param-sub-plan"]
?