trigger.pl

Version: 1.0
Download
View source
signature

Trigger is a script that execute a command or replace text, triggered by an event in irssi.
You could see it as a replacement for lots of small scripts, while it can still be used without knowing perl.

Usage

This is the documentation for the latest released version. For older versions, either upgrade or see /help trigger

TRIGGER LIST
TRIGGER SAVE
TRIGGER RELOAD
TRIGGER MOVE <number> <number>
TRIGGER DELETE <number>
TRIGGER CHANGE <number> ...
TRIGGER ADD ...

When to match:
On which types of event to trigger:
     These are simply specified by -name_of_the_type
     The normal IRC event types are:
          publics, privmsgs, pubactions, privactions, pubnotices, privnotices, joins, parts, quits, kicks, topics, invites, nick_changes, dcc_msgs, dcc_actions, dcc_ctcps
          mode_channel: a mode on the (whole) channel (like +t, +i, +b)
          mode_nick: a mode on someone in the channel (like +o, +v)
     -all is an alias for all of those.
     Additionally, there is:
          rawin: raw text incoming from the server
          send_command: commands you give to irssi
          send_text: lines you type that aren't commands
          beep: when irssi beeps
          notify_join: someone in you notify list comes online
          notify_part: someone in your notify list goes offline
          notify_away: someone in your notify list goes away
          notify_unaway: someone in your notify list goes unaway
          notify_unidle: someone in your notify list stops idling

Filters (conditions) the event has to satisfy. They all take one parameter.
If you can give a list, seperate elements by space and use quotes around the list.
     -pattern: The message must match the given pattern. ? and * can be used as wildcards
     -regexp: The message must match the given regexp. (see man perlre)
       if -nocase is given as an option, the regexp or pattern is matched case insensitive
     -tags: The servertag must be in the given list of tags
     -channels: The event must be in one of the given list of channels.
                Examples: -channels '#chan1 #chan2' or -channels 'IRCNet/#channel'
                          -channels 'EFNet/' means every channel on EFNet and is the same as -tags 'EFNet'
     -masks: The person who triggers it must match one of the given list of masks
     -hasmode: The person who triggers it must have the give mode
               Examples: '-o' means not opped, '+ov' means opped OR voiced, '-o&-v' means not opped AND not voiced
     -hasflag: Only trigger if if friends.pl (friends_shasta.pl) or people.pl is loaded and the person who triggers it has the given flag in the script (same syntax as -hasmode)
     -other_masks
     -other_hasmode
     -other_hasflag: Same as above but for the victim for kicks or mode_nick.

What to do when it matches:
     -command: Execute the given Irssi-command
                You are able to use $1, $2 and so on generated by your regexp pattern.
                For multiple commands ; (or $;) can be used as seperator
                The following variables are also expanded:
                   $T: Server tag
                   $C: Channel name
                   $N: Nickname of the person who triggered this command
                   $A: His address (foo@bar.com),
                   $I: His ident (foo)
                   $H: His hostname (bar.com)
                   $M: The complete message
                   ${other}: The victim for kicks or mode_nick
                   ${mode_type}: The type ('+' or '-') for a mode_channel or mode_nick
                   ${mode_char}: The mode char ('o' for ops, 'b' for ban,...)
                   ${mode_arg} : The argument to the mode (if there is one)
                $\X, with X being one of the above expands (e.g. $\M), escapes all non-alphanumeric characters, so it can be used with /eval or /exec. Don't use /eval or /exec without this, it's not safe.

     -replace: replaces the matching part with the given replacement in the event (requires a -regexp or -pattern)
     -once: remove the trigger if it is triggered, so it only executes once and then is forgotten.
     -stop: stops the signal. It won't get displayed by Irssi. Like /IGNORE
     -debug: print some debugging info

Other options:
     -disabled: Same as removing it, but keeps it in case you might need it later
     -name: Give the trigger a name. You can refer to the trigger with this name in add/del/change commands

Examples:
Knockout people who do a !list:
   /TRIGGER ADD -publics -channels "#channel1 #channel2" -nocase -regexp ^!list -command "KN $N This is not a warez channel!"
React to !echo commands from people who are +o in your friends-script:
   /TRIGGER ADD -publics -regexp '^!echo (.*)' -hasflag '+o' -command 'say echo: $1'
Ignore all non-ops on #channel:
   /TRIGGER ADD -publics -actions -channels "#channel" -hasmode '-o' -stop
Send a mail to yourself every time a topic is changed:
   /TRIGGER ADD -topics -command 'exec echo $\N changed topic of $\C to: $\M | mail you@somewhere.com -s topic'


Examples with -replace:
Replace every occurence of shit with sh*t, case insensitive:
   /TRIGGER ADD -all -nocase -regexp shit -replace sh*t
Strip all colorcodes from *!lamer@*:
   /TRIGGER ADD -all -masks *!lamer@* -regexp '\x03\d?\d?(,\d\d?)?|\x02|\x1f|\x16|\x06' -replace ''
Never let *!bot1@foo.bar or *!bot2@foo.bar hilight you
(this works by cutting your nick in 2 different parts, 'myn' and 'ick' here)
you don't need to understand the -replace argument, just trust that it works if the 2 parts separately don't hilight:
   /TRIGGER ADD -all masks '*!bot1@foo.bar *!bot2@foo.bar' -regexp '(myn)(ick)' -nocase -replace '$1\x02\x02$2'
Avoid being hilighted by !top10 in eggdrops with stats.mod (but show your nick in bold):
   /TRIGGER ADD -publics -regexp '(Top.0\(.*\): 1.*)(my)(nick)' -replace '$1\x02$2\x02\x02$3\x02'
Convert a Windows-1252 Euro to an ISO-8859-15 Euro (same effect as euro.pl):
   /TRIGGER ADD -regexp '\x80' -replace '\xA4'
Show tabs as spaces, not the inverted I (same effect as tab_stop.pl):
   /TRIGGER ADD -all -regexp '\t' -replace '    '

Changelog

current git version (1.0+)

  • ignore empty lines in triggers file
  • added pub&privflood types
  • fixed pub&privctcpreplies types
  • added -not_* for filters

1.0

  • added invites, raw_in, send_command, send_text, beep, mode_channel, mode_nick, pubctcps, privctcps, pubctcpreplies, privctcpreplies, nick_changes, notify_*, dcc_msgs, dcc_actions, dcc_ctcps trigger types
  • added other_masks, other_hasmode, other_hasflag (for the victim of kick/mode), -tag, -pattern filters
  • triggers file format totally changed, now it's in same format as trigger add/list command (old format still recognised)
  • command seperator ; instead of $;, and make \ escapes work in -command (just like in irssi's /eval)
  • added $\X so you can safely use /exec and /eval
  • added "/TRIGGER MOVE" to change the order of the triggers
  • added -name and -disabled options
  • changed -modifier i back to -nocase, made all replaces /g, removed -modifier
  • only allow types on a trigger for which all filters can apply
  • changed "/TRIGGER REPLACE" to "/TRIGGER CHANGE" and fixed error handling
  • recognise abbreviated options (like /trig a publ reg 'foo' -chan #bar com blah)
  • fixed spaces in trigger rules output
  • fixed saving settings with "/script unload trigger" by Valentin Batz (senneth)
  • compile regexps only once (faster)
  • fixed -stop stopping too much
  • no ugly (internal) eval anymore to do replaces. cleaner code and fixes some weird bugs with -replace
  • regexp with signals without message (join, invite) never matches
  • prevent triggers that obviously won't work (for example -replace without -regexp or -pattern)
  • keep triggers hashed by type and lookup in hash + bind to the signals dynamicly when triggers for it exist
  • detect broken quotes (if user forgot closing one)
  • most lines made themeable
  • fixed wrong printing of % in /trigger list
  • modular filters system

0.6

  • finally started keeping a changelog
  • added ';' as command seperator in -command
  • fixed example for avoiding hilights to keep case
  • confusing -actions and -notices params are now -pubactions and -pubnotices. triggers file is converted on load
  • -replace '' to remove something (replace with nothing) now works

todo list

  • -perl_filter ( '$0 eq $server->{nick}' for example)
  • make extention scripts possible?
  • generating simple perl-script from existing triggers
  • -noact: don't hilight the act-bar + nohilight? + -dontcreatewindow?
  • -messagemoveto: display message (the one that irssi itself prints) in another window (+-messagecopyto)
  • Warn on using $M in -command of send_command, infinite recursion
  • require -yes for triggers with warnings?
  • -priority <first|normal|last|number>
  • play with Irssi::signal_register and more signals
  • -norecursion[all]: to stop handling signals [or only the same signal] while -command is being executed
  • -context: execute command in another context?
  • replace -once with $ var meaning "number of the current trigger", and add '/trigger remove $X' to -command ?
  • match on realname, away, oper, isonchan? maybe better another script so /if $isaway($N) then ...
  • if info (like realname, host of kick victim,...) isn't available yet, request it, and delay trigger?