From 03c71116e044fda9d99e827a4ffb0652d508abb5 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 10 Mar 2002 21:28:38 +0000 Subject: added/removed some default scripts git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2569 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- scripts/examples/command.pl | 23 +++++++++++++++++++++++ scripts/examples/msg-event.pl | 41 +++++++++++++++++++++++++++++++++++++++++ scripts/examples/redirect.pl | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 scripts/examples/command.pl create mode 100644 scripts/examples/msg-event.pl create mode 100644 scripts/examples/redirect.pl (limited to 'scripts/examples') diff --git a/scripts/examples/command.pl b/scripts/examples/command.pl new file mode 100644 index 00000000..77a9d7fb --- /dev/null +++ b/scripts/examples/command.pl @@ -0,0 +1,23 @@ +# Example how to create your own /commands: + +# /HELLO - sends a "Hello, world!" to given nick. + +use Irssi; +use strict; +use vars qw($VERSION %IRSSI); + +$VERSION = "1.00"; +%IRSSI = ( + authors => 'Timo Sirainen', + name => 'command', + description => 'Command example', + license => 'Public Domain' +); + +sub cmd_hello { + my ($data, $server, $channel) = @_; + + $server->command("/msg $data Hello, world!"); +} + +Irssi::command_bind('hello', 'cmd_hello'); diff --git a/scripts/examples/msg-event.pl b/scripts/examples/msg-event.pl new file mode 100644 index 00000000..53174e23 --- /dev/null +++ b/scripts/examples/msg-event.pl @@ -0,0 +1,41 @@ +# Example how to react on specific messages: + +# !reverse sends back the text reversed. + +use Irssi; +use strict; +use vars qw($VERSION %IRSSI); + +$VERSION = "1.00"; +%IRSSI = ( + authors => 'Timo Sirainen', + name => 'msg-event', + description => 'Event example', + license => 'Public Domain' +); + +sub event_privmsg { + # $server = server record where the message came + # $data = the raw data received from server, with PRIVMSGs it is: + # "target :text" where target is either your nick or #channel + # $nick = the nick who sent the message + # $host = host of the nick who sent the message + my ($server, $data, $nick, $host) = @_; + + # split data to target/text + my ($target, $text) = $data =~ /^(\S*)\s:(.*)/; + + # skip lines not beginning with !reverse + return if ($text !~ /!reverse (.*)/); + $text = $1; + + if (!$server->ischannel($target)) { + # private message, $target contains our nick, so we'll need + # to change it to $nick + $target = $nick; + } + + $server->command("notice $target reversed $text = ".reverse($text)); +} + +Irssi::signal_add('event privmsg', 'event_privmsg'); diff --git a/scripts/examples/redirect.pl b/scripts/examples/redirect.pl new file mode 100644 index 00000000..6a7e94cc --- /dev/null +++ b/scripts/examples/redirect.pl @@ -0,0 +1,40 @@ +# Example how to do redirections, we'll grab the output of /WHOIS: + +# /RN - display real name of nick + +use Irssi; +use Irssi::Irc; +use strict; +use vars qw($VERSION %IRSSI); + +$VERSION = "1.00"; +%IRSSI = ( + authors => 'Timo Sirainen', + name => 'redirect', + description => 'Redirection example', + license => 'Public Domain' +); + +sub cmd_realname { + my ($data, $server, $channel) = @_; + + # ignore all whois replies except "No such nick" or the + # first line of the WHOIS reply + $server->redirect_event('whois', 1, $data, -1, '', { + 'event 402' => 'event 402', + 'event 401' => 'event 401', + 'event 311' => 'redir whois', + '' => 'event empty' }); + + $server->send_raw("WHOIS :$data"); +} + +sub event_rn_whois { + my ($num, $nick, $user, $host, $empty, $realname) = split(/ +/, $_[1], 6); + $realname =~ s/^://; + + Irssi::print("%_$nick%_ is $realname"); +} + +Irssi::command_bind('rn', 'cmd_realname'); +Irssi::signal_add('redir whois', 'event_rn_whois'); -- cgit v1.2.3