mIRC Home    About    Download    Register    News    Help

Topic Options
#265503 - 17/05/19 06:16 PM Twitch Subscriber Notification Script
Blas Offline
Vogon poet

Registered: 27/10/15
Posts: 111
I've noticed several posts asking for help on getting Twitch Subscriber notifications working. I put this script together which should hopefully help get people on the right track. It's a cleaned up updated version of a script that I posted previously on this forum. I have not had a chance to test it myself but it's based off of the script that I've been using for a while so I am confident that it will function. Please let me know if you find anything that is broken. Thanks.

Code:
; A Basic Script for Subscriber Notifications in mIRC (May 17, 2019)
; by twitch.tv/Blasman13
; $MSGTAG HELP: https://dev.twitch.tv/docs/irc/tags/#usernotice-twitch-tags
; You can find your Twitch User ID that is needed on the the third line (YOUR_TWITCH_USERID) of the actual script below here: https://bashtech.net/twitch/profile.php
; note that some rarer sub alerts aren't covered here (giftpaidupgrade, rewardgift, anongiftpaidupgrade)

RAW USERNOTICE:*: {
  ; look for any notices directed at your Twitch channel && are subscription related
  IF (($msgtags(room-id).key == YOUR_TWITCH_USERID) && ($istok(sub resub subgift submysterygift, $msgtags(msg-id).key, 32))) {
    ; gather variables for the rest of your script
    VAR %run_extras $true
    VAR %name $IIF($regex($msgtags(display-name).key, /^[a-z\d_]+$/ig), $msgtags(display-name).key, $msgtags(login).key)
    VAR %msg-id $msgtags(msg-id).key
    VAR %msg-param-cumulative-months $msgtags(msg-param-cumulative-months).key
    VAR %msg-param-months $msgtags(msg-param-months).key
    VAR %msg-param-streak-months $msgtags(msg-param-streak-months).key
    VAR %msg-param-sub-plan $IIF($msgtags(msg-param-sub-plan).key isnum, $calc($msgtags(msg-param-sub-plan).key/1000), $msgtags(msg-param-sub-plan).key)
    ; MASS SUB GIFTER ALERT: thank the person who gifted the subs and prevent messages for each individual sub
    IF (%msg-id == submysterygift) {
      VAR %msg-param-mass-gift-count $msgtags(msg-param-mass-gift-count).key
      INC %submysterygift. $+ %name %msg-param-mass-gift-count
      MSG $1 %name just gifted %msg-param-mass-gift-count tier %msg-param-sub-plan subscriptions to the community!
    }
    ; NEW SUBSCRIBER ALERT
    ELSEIF (%msg-id == sub) {
      IF (%msg-param-sub-plan isnum) MSG $1 %name just subscribed at tier %msg-param-sub-plan $+ !
      ELSEIF (%msg-param-sub-plan == Prime) MSG $1 %name just subscribed with Twitch Prime!
    }
    ; RE-SUBSCRIBER ALERT
    ELSEIF (%msg-id == resub) {
      IF (%msg-param-sub-plan isnum) VAR %msg_resub %name just re-subscribed at tier %msg-param-sub-plan $+ $chr(44)
      ELSEIF (%msg-param-sub-plan == Prime) VAR %msg_resub %name just re-subscribed using Twitch Prime $+ $chr(44)
      IF (%msg-param-cumulative-months > 1) VAR %msg_resub %msg_resub and has been subscribed for a total of %msg-param-cumulative-months months $+ $chr(44)
      IF (%msg-param-streak-months > 1) VAR %msg_resub %msg_resub and is on a %msg-param-streak-months month sub streak $+ $chr(44)
      MSG $1 $left(%msg_resub,-1) $+ !
    }
    ; GIFTED SUB (single only) ALERT
    ELSEIF (%msg-id == subgift) {
      ; if the Twitch notice is NOT the result of a MASS SUB GIFT
      IF (!$($+(%,submysterygift.,%name),2)) {
        VAR %name_gifted_to $IIF($regex($msgtags(msg-param-recipient-display-name).key, /^[a-z\d_]+$/ig), $msgtags(msg-param-recipient-display-name).key, $msgtags(msg-param-recipient-user-name).key)
        MSG $1 %name just GIFTED a tier %tier subscription to %gifted_to_display_name $+ ! $IIF(%msg-param-months > 1, It is their %msg-param-months month sub anniversary!, $null)
      }
      ; if the Twitch notice IS the result of a MASS SUB GIFT, then we display NOTHING for each individual sub
      ELSE {
        VAR %run_extras $false
        DEC %submysterygift. [ $+ [ %name ] ]
        IF (!$($+(%,submysterygift.,%name),2)) UNSET %submysterygift. [ $+ [ %name ] ]
      }
    }
    IF (%run_extras) {
      ; extra stuff to do whenever a sub, resub, single gifted sub, or mass sub gift happens (only runs once!)... in other words, this WON'T run for every individual sub during a mass sub gift!
    }
  }
}
_________________________
My Twitch mIRC Bot Games and Stuff

Top
#265520 - 20/05/19 07:43 PM Re: Twitch Subscriber Notification Script [Re: Blas]
Greeple Offline
Nutrimatic drinks dispenser

Registered: 30/01/19
Posts: 7
Such a question, maybe you can make a script that would check the color, badges and so on in the event raw USERSTATE
You can of course check the subscriber or not in the api-twitch, but the tags should also work
And besides, I want the colors of the nicknames to be painted in the colors that the users chose to twitch, but I can't do anything cry


Edited by Greeple (20/05/19 08:34 PM)

Top
#265524 - 21/05/19 06:07 AM Re: Twitch Subscriber Notification Script [Re: Greeple]
Blas Offline
Vogon poet

Registered: 27/10/15
Posts: 111
Originally Posted By: Greeple
Such a question, maybe you can make a script that would check the color, badges and so on in the event raw USERSTATE

Exactly, using the Twitch documentation for msgtags it is very easy to have your bot do all sorts of neat stuff on Twitch. I have special commands for users depending on their cheer badge, for example. The badges are also more reliable to detect MOD status for MOD commands (as opposed to using ISOP). Using the script above as an example, you can easily write any of those scripts that you want by yourself.

Originally Posted By: Greeple
You can of course check the subscriber or not in the api-twitch, but the tags should also work

It doesn't make sense to use the API for sub alerts IMO. All the information required is already being provided. Why add an extra step to request the information from an API?
Originally Posted By: Greeple
And besides, I want the colors of the nicknames to be painted in the colors that the users chose to twitch, but I can't do anything cry

Correct. Twitch chat doesn't allow users to change their text color (only their nick color) (yes, I realize /me colors your text your nick color). You can however write scripts that have your bot change the color of their own username (there's a thread on the forums here about it) (see doc's for more info).
_________________________
My Twitch mIRC Bot Games and Stuff

Top
#265525 - 22/05/19 01:21 AM Re: Twitch Subscriber Notification Script [Re: Blas]
Greeple Offline
Nutrimatic drinks dispenser

Registered: 30/01/19
Posts: 7
Originally Posted By: Blas
Using the script above as an example, you can easily write any of those scripts that you want by yourself.

I tried it according to your script and it does not work
example
Code:
RAW USERSTATE:*: {
set %badges. $+ $nick $msgtags(badges).key
}


variable is written
%badges.tmi.twitch.tv moderator/1

How to write a nickname if there will be a lot of people writing in a chat? and as I understand it does not work immediately, and apparently only when a message arrives in the status window
tmi.twitch.tv USERSTATE #nameChannel

but the message does not appear after the messages of people from the chat, but after the messages from mIRC, if the bot sends
Why I asked if you can make a script? because I can't do it, but you can already write it quickly and understand what's wrong frown
PS and through PRIVMSG this
%badges.tmi.twitch.tv


Edited by Greeple (22/05/19 01:40 AM)

Top
#265527 - 22/05/19 08:51 AM Re: Twitch Subscriber Notification Script [Re: Greeple]
Blas Offline
Vogon poet

Registered: 27/10/15
Posts: 111
Originally Posted By: Greeple
Originally Posted By: Blas
Using the script above as an example, you can easily write any of those scripts that you want by yourself.

I tried it according to your script and it does not work
example
Code:
RAW USERSTATE:*: {
set %badges. $+ $nick $msgtags(badges).key
}


variable is written
%badges.tmi.twitch.tv moderator/1

How to write a nickname if there will be a lot of people writing in a chat? and as I understand it does not work immediately, and apparently only when a message arrives in the status window
tmi.twitch.tv USERSTATE #nameChannel

but the message does not appear after the messages of people from the chat, but after the messages from mIRC, if the bot sends
Why I asked if you can make a script? because I can't do it, but you can already write it quickly and understand what's wrong frown
PS and through PRIVMSG this
%badges.tmi.twitch.tv


I've read your message and I cannot seem to understand what you are trying to accomplish. You are confusing RAW with capturing ON:TEXT for example, where $nick would actually be the users name. You can get the persons name from the Twitch $msgtags. It's all in the docs. Good luck. smile
_________________________
My Twitch mIRC Bot Games and Stuff

Top
#265529 - 22/05/19 11:25 AM Re: Twitch Subscriber Notification Script [Re: Blas]
Greeple Offline
Nutrimatic drinks dispenser

Registered: 30/01/19
Posts: 7
that is, I can from on TEXT get $msgtags? I thought they only work in RAW, sorry and good luck to you grin

Top
#265616 - 14/06/19 09:40 PM Re: Twitch Subscriber Notification Script [Re: Blas]
Blas Offline
Vogon poet

Registered: 27/10/15
Posts: 111
Oops, looks like I forgot a space in the $calc function for getting the sub tier. Anyways, I didn't realize that there is no option for editing my original post, so I will just keep the updated script on GitHub here.
_________________________
My Twitch mIRC Bot Games and Stuff

Top