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

({{mIRC|$parseutf}})
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{mIRC Guide}}
+
{{mirc title|On Parseline - Events}}
The '''on parseline''' event triggers before incoming/outgoing IRC server lines are received/sent and allows a script to modify them
+
The '''on parseline''' event triggers before incoming/outgoing IRC server lines are received/sent and allows a script to modify them.
 +
 
 +
The incoming / outgoing lines are in IRC protocol which is very different to the terminology used in the mIRC front end. For example all messages to channels and individual users are sent / received using PRIVMSG. {{mIRC|/ctcp}} also uses PRIVMSG with a special encoding to indicate it is CTCP. {{mIRC|/me}} action messages are a specific type of CTCP message etc. '''''Use of PARSELINE should therefore be considered advanced scripting and is not for the faint-of-heart.'''''
 +
 
 +
Because PARSELINE will be called for every matching line, care should be taken to provide the best possible matchtext in order to minimise the number of times it is called, and to keep the processing undertaken to a reasonable level.
  
 
== Synopsis ==
 
== Synopsis ==
<source lang="mIRC">
+
<source lang="mIRC">on <level>:parseline:in|out|*:<matchtext>:<commands></source>
on <level>:parseline:in|out:<matchtext>:<commands>
 
</source>
 
  
== Level ==
 
 
* '''<level>''' - The appropriate {{mIRC|access levels}} for the event.
 
* '''<level>''' - The appropriate {{mIRC|access levels}} for the event.
 +
* '''<matchtext>''' - See the {{mIRC|on text}} event page for a definition of the <matchtext> parameter and related prefixes.
  
== Matchtext ==
+
== Notes ==
 +
'''Note 1:''' For ''out'' lines, the text you are matching against has a $LF as the last character that you need to account for in your match text. e.g.
 +
<source lang="mIRC">on *:parseline:out:PRIVMSG *Hello:echo -a $parseline</source>
 +
will '''not''' be triggered when you type "Hello" in a channel or query window. Instead you will need something like:
 +
<source lang="mIRC">
 +
on *:parseline:out:PRIVMSG *Hello?:echo -a $parseline
 +
on *:parseline:out:PRIVMSG *Hello*:echo -a $parseline</source>
  
See the {{mIRC|on text}} event page for a definition of the <matchtext> parameter
+
'''Note 2:''' The ":" character is used quite frequently as a separator in IRC raw messages, but it is also used as a separator in mSL's ON statements. You can either use a placeholder for a single character (?) or multiple characters (*) or you can use a calculated match text or a regular expression for the ":" e.g.
 +
<source lang="mIRC">
 +
on *:parseline:out:PRIVMSG *Hello?:echo -a $parseline
 +
on *:parseline:out:PRIVMSG & ?Hello?:echo -a $parseline
 +
on *:parseline:out:$(PRIVMSG & :Hello?):echo -a $parseline
 +
on $*:parseline:out:/^PRIVMSG [^ ]+ :Hello./:echo -a $parseline
 +
</source>
  
 
== {{mIRC|/parseline}} ==
 
== {{mIRC|/parseline}} ==
Line 20: Line 34:
 
== Local identifiers ==
 
== Local identifiers ==
  
The on parseline event expose 3 local identifiers
+
The on parseline event exposes 3 local identifiers:
  
 
=== {{mIRC|$parsetype}} ===
 
=== {{mIRC|$parsetype}} ===
Line 28: Line 42:
 
=== {{mIRC|$parseline}} ===
 
=== {{mIRC|$parseline}} ===
  
Return the line being sent/received
+
Return the line being sent/received.
 +
 
 +
'''Note:''' For ''out'' lines, $parseline is terminated with a $LF character that is not visible when viewed in mIRC. You may wish to remove this with:
 +
<source lang="mIRC">var %pl $parseline
 +
if ($asc($right(%pl,1)) == 10) %pl = $right(%pl,-1)</source>
  
 
=== {{mIRC|$parseutf}} ===
 
=== {{mIRC|$parseutf}} ===
Line 35: Line 53:
  
 
== See also==
 
== See also==
 +
* {{mIRC|/parseline}}
 +
* {{mIRC|$parseline}}
 +
* {{mIRC|$parseutf}}
 
* [[List of on events - mIRC|List of on events]]
 
* [[List of on events - mIRC|List of on events]]
 
* [[List of identifiers - mIRC|List of identifiers]]
 
* [[List of identifiers - mIRC|List of identifiers]]
Line 41: Line 62:
 
{{mIRC on event list}}
 
{{mIRC on event list}}
  
[[Category:mIRC on events|text]]
+
[[Category:mIRC on events|parseline]]

Latest revision as of 19:27, 5 October 2018

The on parseline event triggers before incoming/outgoing IRC server lines are received/sent and allows a script to modify them.

The incoming / outgoing lines are in IRC protocol which is very different to the terminology used in the mIRC front end. For example all messages to channels and individual users are sent / received using PRIVMSG. /ctcp also uses PRIVMSG with a special encoding to indicate it is CTCP. /me action messages are a specific type of CTCP message etc. Use of PARSELINE should therefore be considered advanced scripting and is not for the faint-of-heart.

Because PARSELINE will be called for every matching line, care should be taken to provide the best possible matchtext in order to minimise the number of times it is called, and to keep the processing undertaken to a reasonable level.

Synopsis[edit]

on <level>:parseline:in|out|*:<matchtext>:<commands>
  • <level> - The appropriate access levels for the event.
  • <matchtext> - See the on text event page for a definition of the <matchtext> parameter and related prefixes.

Notes[edit]

Note 1: For out lines, the text you are matching against has a $LF as the last character that you need to account for in your match text. e.g.

on *:parseline:out:PRIVMSG *Hello:echo -a $parseline

will not be triggered when you type "Hello" in a channel or query window. Instead you will need something like:

on *:parseline:out:PRIVMSG *Hello?:echo -a $parseline
on *:parseline:out:PRIVMSG *Hello*:echo -a $parseline

Note 2: The ":" character is used quite frequently as a separator in IRC raw messages, but it is also used as a separator in mSL's ON statements. You can either use a placeholder for a single character (?) or multiple characters (*) or you can use a calculated match text or a regular expression for the ":" e.g.

on *:parseline:out:PRIVMSG *Hello?:echo -a $parseline
on *:parseline:out:PRIVMSG & ?Hello?:echo -a $parseline
on *:parseline:out:$(PRIVMSG & :Hello?):echo -a $parseline
on $*:parseline:out:/^PRIVMSG [^ ]+ :Hello./:echo -a $parseline

/parseline[edit]

Inside this event, you can use /parseline without the -q switch to change the line.

Local identifiers[edit]

The on parseline event exposes 3 local identifiers:

$parsetype[edit]

Return the type of line, "in" or "out"

$parseline[edit]

Return the line being sent/received.

Note: For out lines, $parseline is terminated with a $LF character that is not visible when viewed in mIRC. You may wish to remove this with:

var %pl $parseline
if ($asc($right(%pl,1)) == 10) %pl = $right(%pl,-1)

$parseutf[edit]

Return $true if mIRC is going to decode/encode utf8 the message after the on parseline event

See also[edit]