From 2799d200cb28fee39a8b621e60fa71ac943f504f Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 15 Mar 2000 20:49:44 +0000 Subject: Directory should really be named "scripts", not "examples". Added script mlock.pl git-svn-id: http://svn.irssi.org/repos/irssi/trunk@149 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- scripts/.cvsignore | 2 + scripts/Makefile.am | 6 +++ scripts/autorejoin.pl | 20 +++++++++ scripts/hello.pl | 12 ++++++ scripts/mlock.pl | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/privmsg.pl | 17 ++++++++ scripts/quitmsg.pl | 31 ++++++++++++++ scripts/realname.pl | 34 +++++++++++++++ 8 files changed, 236 insertions(+) create mode 100644 scripts/.cvsignore create mode 100644 scripts/Makefile.am create mode 100644 scripts/autorejoin.pl create mode 100644 scripts/hello.pl create mode 100644 scripts/mlock.pl create mode 100644 scripts/privmsg.pl create mode 100644 scripts/quitmsg.pl create mode 100644 scripts/realname.pl (limited to 'scripts') diff --git a/scripts/.cvsignore b/scripts/.cvsignore new file mode 100644 index 00000000..282522db --- /dev/null +++ b/scripts/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/scripts/Makefile.am b/scripts/Makefile.am new file mode 100644 index 00000000..409ff8dd --- /dev/null +++ b/scripts/Makefile.am @@ -0,0 +1,6 @@ +EXTRA_DIST = \ + autorejoin.pl \ + hello.pl \ + privmsg.pl \ + realname.pl \ + quitmsg.pl diff --git a/scripts/autorejoin.pl b/scripts/autorejoin.pl new file mode 100644 index 00000000..d49dac3f --- /dev/null +++ b/scripts/autorejoin.pl @@ -0,0 +1,20 @@ +# automatically rejoin to channel after kicked + +# NOTE: I personally don't like this feature, in most channels I'm in it +# will just result as ban. You've probably misunderstood the idea of /KICK +# if you kick/get kicked all the time "just for fun" ... + +use Irssi; + +sub event_rejoin_kick { + my ($data, $server) = @_; + my ($channel) = split(/ +/, $data); + + # check if channel has password + $chanrec = $server->channel_find($channel); + $password = $chanrec->values()->{'key'} if ($chanrec); + + $server->send_raw("JOIN $channel $password"); +} + +Irssi::signal_add('event kick', 'event_rejoin_kick'); diff --git a/scripts/hello.pl b/scripts/hello.pl new file mode 100644 index 00000000..de53c3ab --- /dev/null +++ b/scripts/hello.pl @@ -0,0 +1,12 @@ +# "Hello, world!" script :) /hello sends "Hello, world!" to + +use Irssi; + +sub cmd_hello { + my ($data, $server, $channel) = @_; + + $server->command("/msg $data Hello, world!"); + return 1; +} + +Irssi::command_bind('hello', '', 'cmd_hello'); diff --git a/scripts/mlock.pl b/scripts/mlock.pl new file mode 100644 index 00000000..82bea7b0 --- /dev/null +++ b/scripts/mlock.pl @@ -0,0 +1,114 @@ +# /MLOCK - for Irssi 0.7.29 and above +# +# Locks the channel mode to , if someone else tries to change the mode +# Irssi will automatically change it back. +k and +l are a bit special since +# they require the parameter. If you omit the parameter, like setting the +# mode to "+ntlk", Irssi will allow all +k and +l (or -lk) mode changes. + +use Irssi; + +sub cmd_mlock { + my ($data, $server) = @_; + my ($channel, $mode) = split(/ /, $data, 2); + + $keep_channels{$channel} = $mode; + mlock_check_mode($server, $channel); + return 1; +} + +sub mlock_check_mode { + my ($server, $channame) = @_; + + $channel = $server->channel_find($channame); + return if (!channel || !$channel->values()->{'chanop'}); + + $keep_mode = $keep_channels{$channame}; + return if (!$keep_mode); + + # old channel mode + $oldmode = $channel->get_mode(); + $oldmode =~ s/^([^ ]*).*/\1/; + $oldkey = $channel->values()->{'key'}; + $oldlimit = $channel->values()->{'limit'}; + + # get the new channel key/limit + @newmodes = split(/ /, $keep_mode); $keep_mode = $newmodes[0]; + if ($keep_mode =~ /k/) { + if ($keep_mode =~ /k.*l/) { + $newkey = $newmodes[1]; + $limit = $newmodes[2]; + } elsif ($keep_mode =~ /l.*k/) { + $limit = $newmodes[1]; + $newkey = $newmodes[2]; + } else { + $newkey = $newmodes[1]; + } + } elsif ($keep_mode =~ /l/) { + $limit = $newmodes[1]; + } + + # check the differences + undef %allmodes; + $keep_mode =~ s/^\+//; + for ($n = 0; $n < length($keep_mode); $n++) { + $modechar = substr($keep_mode, $n, 1); + $allmodes{$modechar} = '+'; + } + + for ($n = 0; $n < length($oldmode); $n++) { + $modechar = substr($oldmode, $n, 1); + + if ($allmodes{$modechar} eq '+') { + next if (($modechar eq "k" && $newkey ne $oldkey) || + ($modechar eq "l" && $limit != $oldlimit)); + delete $allmodes{$modechar}; + } else { + $allmodes{$modechar} = '-'; + } + } + + # create the mode change string + $modecmd = ""; $extracmd = ""; + foreach $mode (keys %allmodes) { + Irssi::print("key = '$mode':".$allmodes{$mode}); + if ($mode eq "k") { + if ($allmodes{$mode} eq '+') { + next if ($newkey eq ""); + if ($oldkey ne "") { + # we need to get rid of old key too + $modecmd .= "-k"; + $extracmd .= " $oldkey"; + } + $extracmd .= " $newkey"; + } else { + $extracmd .= " $oldkey"; + } + } + if ($mode eq "l" && $allmodes{$mode} eq '+') { + next if ($limit <= 0); + $extracmd .= " $limit"; + } + $modecmd .= $allmodes{$mode}.$mode; + } + + if ($modecmd ne "") { + $channel->values()->{'server'}->command("/mode $channame $modecmd$extracmd"); + } +} + +sub mlock_mode_changed { + my ($data, $server) = @_; + my ($channel, $mode) = split(/ /, $data, 2); + + mlock_check_mode($server, $channel); +} + +sub mlock_synced { + my $channel = $_[0]; + + mlock_check_mode($channel->values()->{'server'}, $channel->values()->{'name'}); +} + +Irssi::command_bind('mlock', '', 'cmd_mlock'); +Irssi::signal_add_last("event mode", "mlock_mode_changed"); +Irssi::signal_add("channel synced", "mlock_synced"); diff --git a/scripts/privmsg.pl b/scripts/privmsg.pl new file mode 100644 index 00000000..999bd213 --- /dev/null +++ b/scripts/privmsg.pl @@ -0,0 +1,17 @@ +# listen PRIVMSGs - send a notice to yourself when your nick is meantioned + +use Irssi; + +sub event_privmsg { + my ($data, $server, $nick, $address) = @_; + my ($target, $text) = $data =~ /^(\S*)\s:(.*)/; + + return if (!Irssi::is_channel($target)); + + $mynick = $server->values()->{'nick'}; + return if ($text !~ /\b$mynick\b/); + + $server->command("/notice $mynick In channel $target, $nick!$address said: $text"); +} + +Irssi::signal_add("event privmsg", "event_privmsg"); diff --git a/scripts/quitmsg.pl b/scripts/quitmsg.pl new file mode 100644 index 00000000..6e296755 --- /dev/null +++ b/scripts/quitmsg.pl @@ -0,0 +1,31 @@ +# Quit with a random quit message read from ~/.irssi/irssi.quit + +use Irssi; + +$quitfile = "$ENV{HOME}/.irssi/irssi.quit"; + +sub cmd_quit { + my ($data, $server, $channel) = @_; + + open (f, $quitfile) || return; + $lines = 0; while() { $lines++; }; + + $line = int(rand($lines))+1; + + seek(f, 0, 0); $. = 0; + while() { + next if ($. != $line); + + chomp; + $quitmsg = $_; + last; + } + close(f); + + @servers = Irssi::servers; + foreach $server (@servers) { + $server->command("/disconnect ".$server->values()->{'tag'}." $quitmsg"); + } +} + +Irssi::command_bind('quit', '', 'cmd_quit'); diff --git a/scripts/realname.pl b/scripts/realname.pl new file mode 100644 index 00000000..1150d5e2 --- /dev/null +++ b/scripts/realname.pl @@ -0,0 +1,34 @@ +# /RN - display real name of nick + +use Irssi; + +sub cmd_realname { + my ($data, $server, $channel) = @_; + + $server->send_raw("WHOIS :$data"); + + # ignore all whois replies except "No such nick" or the + # first line of the WHOIS reply + $server->redirect_event($data, 2, + "event 318", "event empty", -1, + "event 402", "event 402", -1, + "event 401", "event 401", 1, + "event 311", "redir whois", 1, + "event 301", "event empty", 1, + "event 312", "event empty", 1, + "event 313", "event empty", 1, + "event 317", "event empty", 1, + "event 319", "event empty", 1); + return 1; +} + +sub event_rn_whois { + my ($num, $nick, $user, $host, $empty, $realname) = split(/ +/, $_[0], 6); + $realname =~ s/^://; + + Irssi::print("%_$nick%_ is $realname"); + return 1; +} + +Irssi::command_bind('rn', '', 'cmd_realname'); +Irssi::signal_add('redir whois', 'event_rn_whois'); -- cgit v1.2.3