Is that last event on line 23 where variables are cleaned up meant to be on *:sockclose:
instead of sockread?
I would use $+([, $nick, ]:)
to surround $nick with brackets because you will be less likely to accidentally introduce a ] bracket somewhere. Since [ ] are eval brackets in mSL, it could potentially lead to risky code in some cases. Perhaps not for twitch, but it's one of those things that's good to get in the habit of watching out for.
Is there a reason you didn't just reply to the original thread on the mIRC forums instead of posting here? This is only half of a script; it's missing the part where user data is stored. That makes it kind of useless for anyone who views it here.
!watchnicks will easily reach Twitch spam limits if more than 20 (or 100 if the bot is a mod) nicks are in the list, causing the bot to be locked out of chat for 8 hours. There is also no flood protection limit that I can see, so even if there are only 10 users in the list somebody could use the command 2-10 times in a row to get the bot banned for 8 hours.
Since the part where points/time are increased is missing I can't tell if this tracks every viewer or just specific ones, but I would assume it tracks all viewers. The system should really use something besides an ini file to store the data, because many twitch channels are VERY large and storing everything in points.ini will eventually start causing mIRC to freeze. I guarantee this will happen much more frequently than you think. You should at least use a hash table, and perhaps set up a system that periodically either removes users after a period of inactivity or archives their data to speed up operations on the table of active users.
Updated to use $servertarget (introduced in mIRC 7.34) for identifying the twitch connection. The old methods for identifying the twitch connection have been removed.
I also updated the script so that passwords for multiple nicknames can be saved. You can switch between nicknames using /twitch_nick (you will also need to reconnect). Only one can be connected at a time (this is by design).
For a while a few of the IP addresses hosting twitch chat didn't have port 6667 available, so the port can also be changed more easily in the script now. Twitch chat listens on ports 80, 443, and 6667.
A few issues:
if (ismod) { }
is ALWAYS true because 'ismod' has no special meaning (it's just a normal string). Since it's not $null, $false, or 0 the condition evaluates as $true. This means that anybody can use the !bop command, not just mods. Consider replacing with the following:
if ($nick isop $chan) { }
This is not a perfect fix because mIRC will sometimes see mods deopped due to the order in which twitch sends +o/-o messages and joins. It will, however, prevent non-mods from using the command. The only way to keep an accurate list of mods currently in the channel on twitch is to track the +o/-o messages independently and store the list separately.
msg $chan .timeout $2 1 $2-
This actually breaks the intended function of the script. The [./]timeout command doesn't accept a third parameter (the $2- after '1' is the third parameter you're sending), and sending a third parameter breaks the command for whatever reason and it defaults back to a 600 second timeout.
http://en.wikichip.org/wiki/Text_Files_-_mIRC#n_Switch
ALWAYS USE THE n SWITCH for $read() and $readini()!!!!!!!!!!!!!!!!
This link explains many of the technical differences between Twitch chat and a normal IRC server:
http://blog.bashtech.net/a-guide-to-twitch-irc/
Some of them I've already mentioned responding to comments here.
Twitch now requires using an OAuth token to connect. When connecting using this script, set your password as 'oauth:token'.
You can generate a token here for now:
http://twitchapps.com/tmi/
Nice little snippet. A few things to note:
It doesn't actually work. You have a comma inside the expression which is causing the match to fail because mIRC sees it as an argument separator. You should save the expression to a %var and then use $regex(%a, %var). Escaping dots and commas inside a character class also isn't necessary. e.g. [.\,] == [.,]
Inside $util.sanitizeNum() this is kind of difficult to read:
if (%a !isnum 48-57 && %a !isnum $iif($2 == dec,44-46,48)) {
For starters, you've used the ascii values instead of the literal characters. The conditional is also a bit confusing, because you've essentially got something like if (%a !isnum 48... && ... !isnum 48). Not to mention looping through 255 times is going to be really slow if it's used frequently (such as inside another loop).
I'm also not really sure it accomplishes the goal of sanitizing a number. If the 'dec' argument is given, it simply leaves all commas and dots regardless of the number system used. mIRC won't properly parse and calc a numbering system using dots as separators (e.g. 4.000.000) nor will it be able to do $calc(4,000,000). Commas are seen as argument separators, and even if it's inside a variable it won't be calculated properly. I'm not sure if the sanitizeNum alias was meant to work with dot separator numbering systems or not, but either way the commas should always be stripped for mIRC.
You can do the same thing with a simple $regsubex() replace:
alias util.sanitizeNum {
var %expression $iif($2 == dec, /[^\d.]/g, /[^\d]/g)
return $regsubex($1, %expression, $null)
}
which removes everything that's not a digit, or if 'dec' is specified everything that's not a digit or a dot.
$money.variations() uses the same slightly changed command three times, so it could be shortened. It also uses $regex() to check the format before anything is done, so there's really no reason to use $util.sanitizeNum() at all because you already know your numbers are in a specific format. This means you could simply $remove() the commas.
Line 6 also removes "m" when it should be removing "million", although using $util.sanitizeNum() makes all of the $remove() and all of line 6 redundant because it would strip all of the characters anyway.
alias money.variation return $regsubex($remove($1, $chr(44)), /^\$?([\d.]+)(?:(k)|([mb])(?:illion)?|(t)(?:rillion)?)?$/Si, $ $+ $bytes($calc(\1 * 10 ^ (3 * $pos(kmbt, \2))), b))
Yes, using a loop to read through hundreds of lines will be slow. You should use $read()'s built in search functions. (/help $read)
if ($nick ison $chan) {
var %relay notice $nick
var %relay2 msg $chan
goto seen
}
if ($nick !ison $chan) {
var %relay msg $nick
var %relat2 msg $nick
goto seen
}
Could be changed to something like:
if (#) {
var %relay notice $nick
var %relay2 msg $chan
}
else {
var %relay msg $nick
var %relay2 msg $nick
;I'm assuming "relat2" was a typo here.
;There's no reason to use 'goto seen'.
}
'goto seen_true' should really just be 'break' to exit the loop.
You can get rid of a lot of variables here:
var %hostname_seen $address($nick,2)
var %hostname-minus-front_seen $remove(%hostname_seen,*!*@)
var %hostname-minus-back_seen $remove(%hostname-minus-front_seen,.users.netgamers.org)
var %access_seen $readini(adata.ini,%hostname-minus-back_seen,access)
equals:
var %access_seen $remove($address($nick,2),*!*@,.users.netgamers.org)
var %access_seen $readini(adata.ini,%access_seen,access)
$chr(19) in the hostmask is strange, I don't think I've seen that before.
if (%access_seen == hc || %access_seen == bc || %access_seen == scanner || %access_seen == member) {
;could be
if ($istok(hc bc scanner member, %access_seen, 32)) {
Rather than using a bunch of halts in the main body, just use elseif (). (syntax: /help if then else)
Here's a script I wrote: http://www.hawkee.com/snippet/9960/
I'll start by saying that it's probably not what you're looking for. However, you could re-use many of the aliases I've written for it to detect links in your twitch chat. I'd suggest opening it in another tab and then using ctrl+f to find the aliases I'm about to reference.
For example:
on $*:text:$($catchURLex):#:{
This event would trigger when any URL was posted. However, it would also trigger for text like 'o.o'
To remove false matches, you would do the following:
var %urls $extractURL($1-)
if (!%urls) return
Inside $extractURL() I use an alias called $parseDomain(), which uses Mozilla's public suffix list to determine if the suffix used (such as .co.uk or .net) was valid or not. This means only valid domains are returned by $extractURL().
From there, you have the URLs posted inside %urls. You'd just need to loop through them and determine if the domain is whitelisted or not. For that, I have an alias called $trusted(). If $trusted(example.com) == $true, then the site is whitelisted.
It may be overkill for what you want, but if you're interested everything you'd need is in that script.
Using 'read' as an alias name is an ABSOLUTELY HORRIBLE IDEA because mIRC already has an identifier $read().
The same is true of /save. Just be glad you didn't call one of them /dec and then try to use it in another script inside a loop to decrease a variable (I've seen that before).
Checking if $1 is $null inside alias 'save' is redundant, because if $2 is not $null then $1 cannot be $null. Since the only valid format you have requires two parameters, you only need to check if $2 exists to know that they both exist.
$+(%,save,.,$1)
could be
$+(%,save.,$1)
because 'save' and '.' are both literal text. There's no reason to $+() them together.
There seems to be a problem when I edit with some variables (mainly %del_cost and %below) being url decoded. If there are any problems there's a raw version here: http://pastebin.com/raw.php?i=Pd5624y2