mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2015
Posts: 112
B
Blas Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
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!
    }
  }
}

Joined: Jan 2019
Posts: 7
G
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
G
Joined: Jan 2019
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

Last edited by Greeple; 20/05/19 07:34 PM.
Joined: Oct 2015
Posts: 112
B
Blas Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
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).

Joined: Jan 2019
Posts: 7
G
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
G
Joined: Jan 2019
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

Last edited by Greeple; 22/05/19 12:40 AM.
Joined: Oct 2015
Posts: 112
B
Blas Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
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

Joined: Jan 2019
Posts: 7
G
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
G
Joined: Jan 2019
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

Joined: Oct 2015
Posts: 112
B
Blas Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
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.

Joined: Sep 2019
Posts: 1
N
Mostly harmless
Offline
Mostly harmless
N
Joined: Sep 2019
Posts: 1
Does this script handle subs with custom messages? The script I use (I think) is based off a slightly older version of your script but it fails to respond to subs that have custom user generated messages
Example being:
Code
[14:50] [Notification] (User) subscribed with Twitch Prime. They've subscribed for 2 months! [Love the content man keep it up]



The script I'm using is here, note room key was removed for privacy:

Code
RAW USERNOTICE:*: {
  IF (($msgtags(room-id).key == 00000000) && ($istok(sub resub subgift submysterygift, $msgtags(msg-id).key, 32))) {
    VAR %login $msgtags(login).key , %user_id $msgtags(user-id).key , %run_extras $true
    IF ($regex($msgtags(display-name).key, /^[a-z\d_]+$/ig)) VAR %name $msgtags(display-name).key
    ELSE VAR %name %login
    IF ($msgtags(msg-id).key == submysterygift) {
      VAR %type submysterygift , %num_of_subs $msgtags(msg-param-mass-gift-count).key , $+ %name %num_of_subs
      INC %submysterygift. $+ %name %num_of_subs
      MSG $1 @ $+ %name thank you for showering us with ice cubes! Nothing like a little hail!
    }
    ELSEIF ($msgtags(msg-id).key == sub) {
      VAR %type sub
      MSG $1 Welcome to the Ice Box, enjoy the brain freeze %name $+ !

    }
    ELSEIF ($msgtags(msg-id).key == resub) {
      VAR %type resub , %resub_streak_msg $IIF($msgtags(msg-param-streak-months).key > 1 , $msgtags(msg-param-cumulative-months).key months?! Welcome back, %name $+ $char(44) you are on $msgtags(msg-param-streak-months).key month streak! , $msgtags(msg-param-cumulative-months).key months?! Welcome back, %name $+ ! ) 
      MSG $1 Back for more? How do you not have frostbite after %resub_streak_msg
    }
    ELSEIF ($msgtags(msg-id).key == subgift) {
      VAR %type subgift , %gifted_to $msgtags(msg-param-recipient-user-name).key , %gifted_to_display_name $msgtags(msg-param-recipient-display-name).key , %gifted_to_id $msgtags(msg-param-recipient-id).key
      IF (!$($+(%,submysterygift.,%name),2)) {
        VAR %resub_msg $IIF($msgtags(msg-param-months).key > 1, Freezing for $v1 months!, $null)
        MSG $1 @ $+ %gifted_to_display_name $+ , welcome to the freezer! You have %name to thank. %resub_msg
      }
      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!
    }
  }
}



Link Copied to Clipboard