Documentazione mIRC

operators

operators

Indice

By now, you should have a pretty good idea of what variables are and how to use them. Now, all you need to be able to do is operate on them. That’s exactly what mIRC Operators lets you do. Operators are special symbols or keywords that perform specific operations on two or three operands in mIRC.

Contents - 1 Operators - 1.1 Arithmetic Operators - 2 Math Comparison Operators - 3 String Comparison Operators - 3.1 Lexicographical String Comparison Operators - 4 Logical Operators - 4.1 Short-circuit evaluation - 5 Channel-related Operators - 6 List-related Operators

Operators

mIRC provides the following types of operators:

  • Arithmetic Operators
  • Math Comparison Operators
  • String Comparison Operators
  • Lexicographical String Comparison Operators
  • Logical Operators
  • Channel-related Operators
  • List-related Operators

Arithmetic Operators

OperatorSyntax
Additiona + b
Subtractiona - b
Multiplicationa * b
Divisiona / b
Moduloa % b
Powera ^ b

mIRC supports the following arithmetic operators. They can be used in conjunction with the /var or /set commands as well as using the $calc Identifier. One special feature of the $calc identifier over the /var and /set commands is that it supports combination of operators as well as parenthesis to be able to change the order of operations.

alias example {
  var %x = 5
  ;5 * 5 = 25
  %x = %x * 5
  echo -a %x
 
  ;remainder of 25 / 9 = 7
  var %y = %x % 9
  echo -a %y
 
  ;25 + 7 - 2 = 30
  %x = $calc(%x + %y - 2)
  echo -a %x
}

Math Comparison Operators

Math Comparison operators allow you to compare two values

SyntaxNameResult
%x == %yEqualTrue, if %x is equal to %y.
%x != %yNot equalTrue, if %x is not equal to %y.
%x < %yLess thanTrue, if %x is strictly less than %y.
%x > %yGreater thanTrue, if %x is strictly greater than %y.
%x <= %yLess than or equal toTrue, if %x is less than or equal to %y.
%x >= %yGreater than or equal toTrue, if %x is greater than or equal to %y.
%x // %yMultiple Of (Divides)True, if %x divides %y.
%x \ %yNot Multiple Of (Not Divides)True, if %x does not divides %y.
%x & %yBitwise AndTrue, if (bit representation of) %x AND %y is a none zero.

Example:

alias example2 {
  ;true (3 a multiple of 9)
  if (3 // 9) echo yes!
  ;false
  if (4 < 4) echo no
  ;00001010 = 10
  ;00000100 = 4
  ;00000000 = 0
  ;true, we used the '!' to negate the operator
  if (10 !& 4) echo yes
}

String Comparison Operators

mIRC provides a set of operators that can be used to compare two strings. The two iswm and iswmcs operators support two wildcard characters as well, the question mark (?) substitutes for any one character and the asterisk character (”*”) substitutes for any zero or more characters.

Example:

alias example3 {
  var %x = Hello!
  if (?ell?? iswm %x) echo true
  ;false, because of '!'
  if (%x isalpha) echo no
  %x = 5
  if (%x isnum 1-10) echo true
  if (%x isnum)  echo true
}

Operators

SyntaxNameResult
%x isin %yIs InTrue, if %x is fully found inside %y.
%x isincs %yIs In (case sensitive)True, if %x is fully found inside (case sensitive) %y.
%x iswm %yWildcard MatchingTrue, if wildcard string %x matches %y.
%x iswmcs %yWildcard Matching (case sensitive)True, if wildcard string %x matches (case sensitive) %y.
%x isnum %x isnum N %x isnum N- %x isnum N-MIs Digit Is Digit, Equal to Is Digit, Greater than or equal to Is Digit, in RangeTrue, if %x is a number True, if %x is number N True, if %x is number N or greater True, if %x is a number between N and M (inclusively)
%x isletter %x isletter NIs a Letter Is a Letter In A ListTrue, if %x is a letter True, if %x is a letter in a list of letters
%x isalnumAlphanumeric CharactersTrue, if %x contains only alphabetic or numeric characters.
%x isalphaAlphabetic CharactersTrue, if %x contains only alphabetic characters.
%x islowerAll lower case lettersTrue, if %x contains only lower case letters.
%x isupperAll upper case lettersTrue, if %x contains only upper case letters.

Lexicographical String Comparison Operators

A lexicographical comparison is a comparison generally used to sort words alphabetically in dictionaries and indexes. If both strings are equal but one is shorter than the other, the shorter string is lexicographically less than the longer one.

SyntaxNameResult
a == bCase insensitive character comparisonTrue, if character a is equal to character b, case insensitive.
a === bCase sensitive character comparisonTrue, if character a is equal to character b, case sensitive.
str1 == str2Case insensitive String comparisonTrue, if str1 equals str2 in a case insensitive manner.
str1 === str2Case sensitive String comparisonTrue, if str1 equals str2 in a case insensitive manner.
a < bLexicographically Less ThanTrue, if the $asc(a) comes before $asc(b)
a > bLexicographically Greater ThanTrue, if the $asc(a) comes after $asc(b)
str1 < str2Lexicographically Less ThanTrue, if str1 comes before str2
str1 > str2Lexicographically Greater ThanTrue, if str1 comes after str2

Logical Operators

In an if statement, you are allowed to have more than one condition. Each condition has to be connected to the other using a logical operator. There are two logical operators: || meaning OR and && meaning AND.

For example:

if ((%x < 0) || (%x >  10)) {

In the if statement above, %x has to be less than 0 OR greater than 10 to make the if statement be true.

if ((%input isupper) && ($len(%input) < 10)) {

The if statement above will only be true if %a contains only upper case letters and its total length is less than 10.

Short-circuit evaluation

mIRC will only evaluate as much of the condition has it needs. Consider the AND example from above, if %input doesn’t contain only upper case letters, the second condition will never even evaluate. This is important to keep in mind when using custom identifiers inside an if statement.

mIRC also provides a set of commands to involve IRC channels.

SyntaxNameResult
%x ison %yIs OnTrue, if nick %x is on channel %y.
%x isop %yIs an OperatorTrue, if nick %x is an operators on channel %y.
%x ishop %yIs a HalfopTrue, if nick %x is a halfop on channel %y.
%x isvoice %yIs a VoiceTrue, if nick %x is a voice on channel %y.
%x isreg %yIs a RegularTrue, if nick %x is a regular user on channel %y.
%x ischanIs a ChannelTrue, if channel %x is a channel you are on.
%x isban %yIs a banTrue, if ban address %x is a ban on channel %y. (taken from IBL)

Example:

alias example4 {
  ;am I on #mIRC
  if (#mIRC ischan) echo yes
  ;is that ban on #mSL's internal ban list?
  if (*!*@example.com isban #offTopic) echo yes
  ;am I an OP on #mIRC?
  if ($me isop #mIRC) echo yes
}

mIRC has 5 additional operators to check mIRC internal lists.

SyntaxNameResult
%x isaop %x isaop %yIn Auto-Op List In Auto-Op List For ChanTrue, if host %x is in the auto-op list. True, if host %x is in the auto-op list for channel %y.
%x isavoice %x isavoice %yIn Auto-Voice List In Auto-Voice List For ChanTrue, if host %x is in the auto-voice list. True, if host %x is in the auto-voice list for channel %y.
%x isignore %x isignore %yIn Ignore List In Ignore List For TypeTrue, if host %x is in the ignore list. True, if host %x is in the ignore list for type %y.
%x isprotect
%x isprotect %yIn Protect List
In Protect List For ChanTrue, if host %x is in the protect list.
True, if host %x is in the protect list for channel %y.%x isnotifyIn Notify List

Example:

Alias example5 {
  ;is the host in the auto-op list
  if (dave101!*@* isaop) echo yes
 
  ;assume we have ignore all ctcps: /ignore -tw *!*@*
  ;check if *!*@* in the ignore list for CTCPs:
  if (*!*@* isignore ctcp) echo yes
}