From WikiChip
Difference between revisions of "mirc/on events/on text"
< mirc‎ | on events

(Created page with "The '''on text''' event is an mIRC event that triggers when a remote user (I.E. not the local user) receives a channel or a query message. == Synopsis == on <level>:text...")
 
(Target)
 
(22 intermediate revisions by 7 users not shown)
Line 1: Line 1:
The '''on text''' event is an [[mIRC]] event that triggers when a remote user (I.E. not the local user) receives a channel or a query message.
+
{{mirc title|On Text - Events}}
 +
The '''on text''' event is a mIRC event that triggers when a remote user (I.E. not the local user) receives a channel or a query message.
  
 
== Synopsis ==
 
== Synopsis ==
on <level>:text:<matchtext>:<target>:<commands>
+
<source lang="mIRC">
 +
on <level>:text:<matchtext>:<target>:<commands>
 +
</source>
  
* '''<matchtext>''' - The match text is the text pattern that mIRC will use to compare with every user message. Once the text has been matched (and the channel if provided), the event will trigger.
+
== Level ==
* '''<level>''' - The appropriate [[access levels - mIRC|access level]] for the event.
+
* '''<level>''' - The appropriate {{mIRC|access levels|access level}} for the event.
 +
 
 +
== Matchtext ==
 +
 
 +
A '''<matchtext>''' is a text pattern that mIRC will use to compare with something. Inside the on text event, the matchtext parameter is every user message. In general, there is only one matchtext parameter per event, you can also find matchtext parameter in others area of the mIRC scripting language, like in the {{mIRC|/filter}} command for example. An event only triggers if its matchtext parameter matches the appropriate data (user message, notice and server message etc..)
 +
 
 +
=== Wildcard text pattern ===
 +
The matchtext can contain wild characters:
 +
* * - matches any text
 +
* ? - matches any single letter
 +
* & - matches any single word
 +
 
 +
For Example:
 +
* !test - the matchtext will only match if the ONLY word is "!test"
 +
* !test* - the matchtext will match if the text starts with "!test"
 +
* *!test - the matchtext will match if the text ends with the word "!test"
 +
* *!test* - the matchtext will match any text that has "!test" in it (anywhere)
 +
* !test & - the matchtext will match any text that start with the word test !test and is only followed by a second word
 +
 
 +
=== The basic text pattern ===
 +
The most basic on text event is the normal {{mirc|wildcard}} pattern:
 +
 
 +
<syntaxhighlight lang="mIRC">on *:text:!help:#:{
 +
  notice $nick For Help just state your question and pastebin any relevant code.
 +
}</syntaxhighlight>
 +
 
 +
Sometimes we want to get the user's input. We can use the & to match a single word (in this case it will be a name, although it doesn't matter)
 +
 
 +
<syntaxhighlight lang="mIRC">on *:text:!color &:?:{
 +
  var %color = $gettok(white black red blue brown yellow orange green, $rand(1, 8), 32)
 +
  msg $chan $2's random color is: %color $+ .
 +
}</syntaxhighlight>
 +
 
 +
=== RegEx text pattern ===
 +
The matchtext parameter can also be a Regular Expression Pattern by using the {{mIRC|Access levels#Level_prefixes|'$' event prefix}}.
 +
 
 +
Example:
 +
 
 +
<syntaxhighlight lang="mIRC">on $*:text:/^!test$/i:#:{
 +
  msg $chan Test Worked!
 +
}</syntaxhighlight>
 +
 
 +
=== Dynamic text pattern ===
 +
Text matched patterns can also be dynamic, for example your name at the time of the execution ($me), a variable or time. In order for mIRC to know to evaluate the expression, it must be enclosed by the $() identifier.
 +
 
 +
Example:
 +
 
 +
<syntaxhighlight lang="mIRC">on *:text:$(*slaps $me $+ *):#:{
 +
  describe $chan Slaps $nick with dried-up sandwich!
 +
}</syntaxhighlight>
 +
 
 +
Or
 +
 
 +
<syntaxhighlight lang="mIRC">on *:text:$(!example * $+ %match $+ *):#:{
 +
  describe $chan This is an example, $+ $nick $+ !
 +
}</syntaxhighlight>
 +
 
 +
If the entire match text pattern contains a SINGLE variable, the $() is not required, this technique can also be used for any other parameter of an event.
 +
 
 +
Example:
 +
 
 +
<syntaxhighlight lang="mIRC">;Assume %text is set to !cool
 +
on *:text:%text:#:{
 +
  msg $chan I am the coolest!
 +
}</syntaxhighlight>
 +
 
 +
It is also possible to use regular expressions with dynamic match text.
 +
 
 +
<syntaxhighlight lang="mIRC">on $*:text:$(/^!slaps $me $+ /Si):#:{
 +
  describe $chan Slaps $nick with dried-up sandwich!
 +
}</syntaxhighlight>
 +
 
 +
== Target ==
 +
The target parameter of the event defines the locations of where the event can be triggered from. For example, the on text event can be triggered by a channel message or by a query.
 +
 
 +
* ? - defines query location
 +
* # - defines channel location
 +
* * - defines both query and channel locations
 +
* %var - A variable containing a channel or a list of channels is also acceptable
 +
 
 +
Example:
 +
 
 +
<syntaxhighlight lang="mIRC">;let %chan equal #mSL,#help,#support
 +
on *:text:!hi:%chan:{
 +
  notice $nick Hello!
 +
}</syntaxhighlight>
 +
 
 +
Example 2:
 +
 
 +
<syntaxhighlight lang="mIRC">
 +
; use local identifier $channels to work
 +
alias -l channels { return #mSL,#help,#support }
 +
on *:text:!hi:$($channels):{
 +
  notice $nick Hello!
 +
}</syntaxhighlight>
 +
 
 +
== Local $identifier available in the on text event ==
 +
 
 +
The on text event support the common IRC related local identifiers
  
 
== See also==
 
== See also==
Line 12: Line 113:
 
* [[List of commands - mIRC|List of commands]]
 
* [[List of commands - mIRC|List of commands]]
  
[[Category:mIRC on events]]
+
{{DEFAULTSORT:text, on mIRC}}
 +
{{mIRC on event list}}
 +
 
 +
[[Category:mIRC on events|text]]

Latest revision as of 14:12, 26 November 2019

The on text event is a mIRC event that triggers when a remote user (I.E. not the local user) receives a channel or a query message.

Synopsis[edit]

on <level>:text:<matchtext>:<target>:<commands>

Level[edit]

Matchtext[edit]

A <matchtext> is a text pattern that mIRC will use to compare with something. Inside the on text event, the matchtext parameter is every user message. In general, there is only one matchtext parameter per event, you can also find matchtext parameter in others area of the mIRC scripting language, like in the /filter command for example. An event only triggers if its matchtext parameter matches the appropriate data (user message, notice and server message etc..)

Wildcard text pattern[edit]

The matchtext can contain wild characters:

  • * - matches any text
  •  ? - matches any single letter
  • & - matches any single word

For Example:

  •  !test - the matchtext will only match if the ONLY word is "!test"
  •  !test* - the matchtext will match if the text starts with "!test"
  • *!test - the matchtext will match if the text ends with the word "!test"
  • *!test* - the matchtext will match any text that has "!test" in it (anywhere)
  •  !test & - the matchtext will match any text that start with the word test !test and is only followed by a second word

The basic text pattern[edit]

The most basic on text event is the normal wildcard pattern:

on *:text:!help:#:{
  notice $nick For Help just state your question and pastebin any relevant code.
}

Sometimes we want to get the user's input. We can use the & to match a single word (in this case it will be a name, although it doesn't matter)

on *:text:!color &:?:{
  var %color = $gettok(white black red blue brown yellow orange green, $rand(1, 8), 32)
  msg $chan $2's random color is: %color $+ .
}

RegEx text pattern[edit]

The matchtext parameter can also be a Regular Expression Pattern by using the '$' event prefix.

Example:

on $*:text:/^!test$/i:#:{
  msg $chan Test Worked!
}

Dynamic text pattern[edit]

Text matched patterns can also be dynamic, for example your name at the time of the execution ($me), a variable or time. In order for mIRC to know to evaluate the expression, it must be enclosed by the $() identifier.

Example:

on *:text:$(*slaps $me $+ *):#:{
  describe $chan Slaps $nick with dried-up sandwich!
}

Or

on *:text:$(!example * $+ %match $+ *):#:{
  describe $chan This is an example, $+ $nick $+ !
}

If the entire match text pattern contains a SINGLE variable, the $() is not required, this technique can also be used for any other parameter of an event.

Example:

;Assume %text is set to !cool
on *:text:%text:#:{
  msg $chan I am the coolest! 
}

It is also possible to use regular expressions with dynamic match text.

on $*:text:$(/^!slaps $me $+ /Si):#:{
  describe $chan Slaps $nick with dried-up sandwich!
}

Target[edit]

The target parameter of the event defines the locations of where the event can be triggered from. For example, the on text event can be triggered by a channel message or by a query.

  •  ? - defines query location
  • # - defines channel location
  • * - defines both query and channel locations
  •  %var - A variable containing a channel or a list of channels is also acceptable

Example:

;let %chan equal #mSL,#help,#support
on *:text:!hi:%chan:{
  notice $nick Hello!
}

Example 2:

; use local identifier $channels to work
alias -l channels { return #mSL,#help,#support }
on *:text:!hi:$($channels):{
  notice $nick Hello!
}

Local $identifier available in the on text event[edit]

The on text event support the common IRC related local identifiers

See also[edit]