Scripting » History » Revision 55
« Previous |
Revision 55/246
(diff)
| Next »
Per Amundsen, 10/29/2011 12:47 AM
Notice: this is info for 1.8.8 and higher.¶
Scripting¶
In the latest beta's, I am experimenting with a little more advanced scripting features and I will use this wiki to track progress and features.
Syntax, variables and functions will probably change a lot, so don't except previous scripts to still work in the next beta and so forth.
There are 2 types of scripting at the moment, one that have been here for a long time, and a new system.
All scripting is done in Commands -> Edit Commands where one line represent a script or a custom command and its trigger is one of 3 ways:
/something<whitespace>
keys<whitespace>
OnEvent<whitespace>
Please note that variables and functions are different for these 2 types of scripts.
You can comment out a command by putting a # in front of it.
Normal custom commands:¶
Syntax = /something<whitespace>/somethingelse
Here are some variables which can be used in Custom Commands, its like creating aliases of already available commands, e.g
/hi /me says hi to $chanwill show
* kr0n says hi to #adiircwhen typing
/hi
Current variables are $1 to $9, $params, $chan and $me. $1 to $9 represents what you type after /yourcommand e.g
/sup /say whats up $1when typing
/sup kr0nit will show like this
User: whats up kr0n
$params represents everything written after /yourcommand, $chan replaces itself with current channel and $me replaces itself with your current usernick.
You can make combo commands by using | as a seperator, e.g
/hi /me says hi to $chan|/me says hi again to $chan
$file[path] returns data from a file, $frand[path] fetchs a random line from a file and $floop[path] gets one line increasingly (line1, then line2, then line3 etc).
Custom Commands by hotkeys¶
Syntax = key&key<whitespace>/something
In addition to making a custom command trigger by typing a /slash command, you make it trigger with a hotkey instead (note, these commmands will not be useable from the new scripting engine)
Useable modifies are ctrl, alt and shift and any character or number or F key.
An example
ctrl&o /msg $chan ohai i just pressed ctrl and o
Everytime you press ctrl and 'o' now, this command will be fired off.
ctrl&alt&o /msg $chan ohai i just pressed ctrl and alt and o
Everytime you press ctrl and alt and 'o' now, this command will be fired off.
Unified Scripting¶
Syntax = OnEvent<whitespace>code
The new scripting tries to combine normal client commands, your custom commands, functions and events into one scripting language.
In Commands -> Edit Commands you can enter a scripting line with the following syntax:
Followed by either an expression like this (works recursivly)
if (SOMETING == SOMETHINGELSE) { EXECUTE HERE } if (SOMETING != SOMETHINGELSE) { EXECUTE HERE } if (SOMETING ismatch SOMETHINGELSE) { EXECUTE HERE }
or by an executed command or function
You can now combine expressions with && (AND) and || (OR) like this
if (SOMETHING == SOMETHING && SOMETHINGELSE != SOMETHINGELSE) { EXECUTE HERE } if (SOMETHING == SOMETHING || SOMETHINGELSE != SOMETHINGELSE) { EXECUTE HERE }
The logic behind these expressions is not fully tested, id love any feedback on this.
It is also possible to use else if like this
if (SOMETHING == SOMETHING) { EXECUTE HERE } else if (SOMETHINGELSE == SOMETHINGELSE) { EXECUTE HERE }
In the future just "else" will be possible to.
(note: ismatch will check if SOMETHING exist inside SOMETHINGELSE e.g if something is "hello" and something else is "hello world" it would return True because "hello" exist)
Executed commands are /slash commands already in the client e.g /msg #channel hello world.
Executed functions are predefined functions in the client, only two exists for now.
An execution block can consist of both commands and functions if seperated by | (pipe) character like this
/msg #channel hello world|.function bla bla|/msg #channel2 hello world
Furthermore there is a lot of predefined variables for use with these functions, for now they are:
$event / current event, e.g PRIVMSG 001 MODE and so forth
$channel / the channel the event occurred on, if any
$msg / the message to the channel/user or the message in a raw irc line e.g whois [kr0n] is a registered nick
$nick / the nick the event was sent from, can be a irc.server.com, a nick or null
$me / my current nick
$network / the network the event occured on e.g Quakenet
$ident / the from user ident if any
$host / the from user hostname if any
$myident / my ident
$myhost / my host
$server / host from the server e.g irc.server.com
Currently predefined functions are:
.insert <nick (use null for nonick)> <where (a channel or $channel, a nick or $nick, or status)> <MsgType (MsgServer/MsgUser/MsgEmote/MsgCTCP/MsgNotice/MsgClient/MsgLog)> <$msg or message>
.eat <what (text or all)>
.insert is used for inserting a specific message type into a chat window, its intended for use in cases where you want to override how adiirc shows a given event, but can also be used for adding additional messages.
.eat is used to tell adiirc to either "eat" the text output from an event or "eat" everything and don't act on this event at all.
Putting it all togheter, here are a few examples:
OnEvent if ($event == NOTICE) { if ($msg ismatch hi there) { .insert $nick status MsgNotice $msg|.eat text } }
insert the notice into the server window and tells adiirc to "eat" its own text output from this notice
OnEvent if ($event == PRIVMSG && $msg == herp) { /msg $channel derp }
if the event is a PRIVMSG AND the $msg equals "herp", then show "derp" in the channel
OnEvent if ($event == PRIVMSG) { if ($nick == Q || $nick == $me) { /msg $channel Q or $me is speaking! } }
if the event is a PRIVMSG and the $nick equals "Q" OR $me then show "Q or $me is speaking" in the channel
OnEvent if ($event == OnOp && $nick == $me) { /msg $channel Thx for op! }
if the event is OnOp and the target nick is me, then show "Thx for op!" in the channel
A list of custom events that is also usable as $event ==
OnOwner OnDeOwner OnSpecialOp OnSpecialDeOp OnOp OnDeOp OnHop OnDeHop OnVoice OnDeVoice
Scripting changes in latest beta
This does not apply to the latest stable release!¶
New command /nmsg added for cross network output, and a new event OnSongChanged.
Combine them and you can automatically announce song changes in a channel or to a user with:
OnEvent if ($event == OnSongChanged) { /nmsg <network> <channel/Nick> $msg }
Announce to several channels with:
OnEvent if ($event == OnSongChanged) { /nmsg <network> <channel/Nick> $msg|/nmsg <network> <channel/Nick> $msg }
Network is the network name where the channel is, e.g NordicIRC, freenode, Quakenet, look at the name of the server window you are connected on, to find it.
Also added is better escaping, variables and a "null" variable, e.g
OnEvent if ($event == PRIVMSG) { if (%test == null) { %test = SOMETHING|/msg $channel test is %test } }
These variables are stored as long as the program is running, and you can change/use them in any OnEvent script.
Note also that all user set variables starts with % and client variables starts with $.
Variables is still work in progress, id love some feedback/ideas of what it can be used for.
New function is added .msgbox <message> e.g
OnEvent if ($event == JOIN) { .msgbox $nick joined $channel }
It will popup a messagebox with the message.
New events:
OnLoad - Called when all commands are loaded the first time (ie when the program starts) OnUnload - Called when all commands are unloaded (ie when the program exits) OnReload - Called when all commands are reloaded (ie when you press apply in command editor) OnConnecting - Called when a server is connecting OnLookingUp - Called when a server is looking up the hostname OnConnected - Called when a server is connected OnDisconnect - Called when a server gets disconnected OnCommand - Called whenever a user types a /slash command in the client ($msg will hold the full command, $0 will be the first word, $1 the second and so on)
A few examples using these.
OnEvent if ($event == OnLoad) { %myvariable = This was set at startup } OnEvent if ($event == OnUnLoad) { .msgbox varible set at startup was %myvariable } OnEvent if ($event == OnReLoad) { .msgbox Commands reloaded } OnEvent if ($event == OnConnecting) { .msgbox i r conecting } OnEvent if ($event == OnLookingUp ) { .msgbox i r looking up hostname } OnEvent if ($event == OnConnected ) { .msgbox i r connected } OnEvent if ($event == OnDisconnect) { .msgbox i r disconnected } OnEvent if ($event == OnCommand) { if ($0 == /me) { .msgbox i typed /me } } OnEvent if ($event == OnCommand) { .msgbox i typed $0, full command was $msg }
A complete rewrite of the parser logic is done, introducing the "else" keyword, and you can now use any nested length of "if" "else if" and "else" e.g:
OnEvent if ($event == PRIVMSG) { if (%test == null) { /msg Hello world; if (%test == null) { /msg Hello world; } } else if (%test == null) { /msg Hello world; } else (%test == null) { /msg Hello world; } if (%test == null) { /msg Hello world } }
also ; is now useable like | for line ending.
A script editor will be the next step.
Updated by Per Amundsen almost 13 years ago · 55 revisions