summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-03-15 20:49:44 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-03-15 20:49:44 +0000
commit2799d200cb28fee39a8b621e60fa71ac943f504f (patch)
tree864f7a2a227ff2b7275fb57cac5cef7e4f0e045b
parentbefd35e710bec8af72865b1e670e8a15f9342a45 (diff)
downloadirssi-2799d200cb28fee39a8b621e60fa71ac943f504f.zip
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
-rw-r--r--Makefile.am2
-rw-r--r--scripts/.cvsignore (renamed from examples/.cvsignore)0
-rw-r--r--scripts/Makefile.am (renamed from examples/Makefile.am)0
-rw-r--r--scripts/autorejoin.pl (renamed from examples/autorejoin.pl)0
-rw-r--r--scripts/hello.pl (renamed from examples/hello.pl)0
-rw-r--r--scripts/mlock.pl114
-rw-r--r--scripts/privmsg.pl (renamed from examples/privmsg.pl)0
-rw-r--r--scripts/quitmsg.pl (renamed from examples/quitmsg.pl)0
-rw-r--r--scripts/realname.pl (renamed from examples/realname.pl)0
9 files changed, 115 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 61468396..861b3d2f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,7 +11,7 @@ if BUILD_SERVERTEST
SERVERTEST=servertest
endif
-SUBDIRS = po intl macros src $(PLUGINS) $(SERVERTEST) docs examples
+SUBDIRS = po intl macros src $(PLUGINS) $(SERVERTEST) docs scripts
## to automatically rebuild aclocal.m4 if any of the macros in
## `macros/' change
diff --git a/examples/.cvsignore b/scripts/.cvsignore
index 282522db..282522db 100644
--- a/examples/.cvsignore
+++ b/scripts/.cvsignore
diff --git a/examples/Makefile.am b/scripts/Makefile.am
index 409ff8dd..409ff8dd 100644
--- a/examples/Makefile.am
+++ b/scripts/Makefile.am
diff --git a/examples/autorejoin.pl b/scripts/autorejoin.pl
index d49dac3f..d49dac3f 100644
--- a/examples/autorejoin.pl
+++ b/scripts/autorejoin.pl
diff --git a/examples/hello.pl b/scripts/hello.pl
index de53c3ab..de53c3ab 100644
--- a/examples/hello.pl
+++ b/scripts/hello.pl
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 <channel> <mode> - for Irssi 0.7.29 and above
+#
+# Locks the channel mode to <mode>, 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/examples/privmsg.pl b/scripts/privmsg.pl
index 999bd213..999bd213 100644
--- a/examples/privmsg.pl
+++ b/scripts/privmsg.pl
diff --git a/examples/quitmsg.pl b/scripts/quitmsg.pl
index 6e296755..6e296755 100644
--- a/examples/quitmsg.pl
+++ b/scripts/quitmsg.pl
diff --git a/examples/realname.pl b/scripts/realname.pl
index 1150d5e2..1150d5e2 100644
--- a/examples/realname.pl
+++ b/scripts/realname.pl