diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 20:19:02 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 20:19:02 +0000 |
commit | 03929dac2a29664878d2c971648a4fe1fb698462 (patch) | |
tree | 02c5e2b3e006234aa29545f7a93a1ce01b291a8b /scripts/defaultchanmode.pl | |
parent | Initial commit. (diff) | |
download | irssi-scripts-03929dac2a29664878d2c971648a4fe1fb698462.tar.xz irssi-scripts-03929dac2a29664878d2c971648a4fe1fb698462.zip |
Adding upstream version 20231031.upstream/20231031upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts/defaultchanmode.pl')
-rw-r--r-- | scripts/defaultchanmode.pl | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/scripts/defaultchanmode.pl b/scripts/defaultchanmode.pl new file mode 100644 index 0000000..2fd8a8f --- /dev/null +++ b/scripts/defaultchanmode.pl @@ -0,0 +1,98 @@ +#!/usr/bin/perl -w + +# USAGE: +# +# /SET default_chanmode <modes> +# - sets the desired default chanmodes +# +# Written by Jakub Jankowski <shasta@atn.pl> +# for Irssi 0.7.98.CVS +# +# please report any bugs + +use strict; +use vars qw($VERSION %IRSSI); + +$VERSION = "1.1"; +%IRSSI = ( + authors => 'Jakub Jankowski', + contact => 'shasta@atn.pl', + name => 'Default Chanmode', + description => 'Allows your client to automatically set desired chanmode upon a join to an empty channel.', + license => 'GNU GPLv2 or later', + url => 'http://irssi.atn.pl/', +); + +use Irssi 20011211.0107 (); +use Irssi::Irc; + +# defaults +my $default_chanmode = ""; + +# str parse_mode($string) +# gets +a-e+bc-fg xyz +# returns +abc-efg xyz +sub parse_mode { + my ($string) = @_; + my ($modeStr, $rest) = split(/ +/, $string, 2); + my @modeParams = split(/ +/, $rest); + my $ptr = 0; + my ($mode, $plusmodes, $minusmodes, $args, $finalstring); + + # processing the default_chanmode setting + foreach my $char (split(//, $modeStr)) { + if ($char eq "+") { + $mode = "+"; + } elsif ($char eq "-") { + $mode = "-"; + } else { + if ($mode eq "+") { + $plusmodes .= $char; + } elsif ($mode eq "-") { + $minusmodes .= $char; + } + if ($char =~ /[beIqoOdhvk]/ || ($char eq "l" && $mode eq "+")) { + # those are modes with arguments, so increase the pointer + $args .= " ".$modeParams[$ptr++]; + } + } + } + + # concatenating results + $finalstring .= "+".$plusmodes if (length($plusmodes) > 0); + $finalstring .= "-".$minusmodes if (length($minusmodes) > 0); + $finalstring .= $args if (length($args) > 0); + + # debug stuff if you want + # Irssi::print("parse_mode($string) returning '$finalstring'"); + + return $finalstring; +} + +# void event_channel_sync($channel) +# triggered on join +sub event_channel_sync { + my ($channel) = @_; + + # return unless default_chanmode contains something valuable + my $mode = parse_mode(Irssi::settings_get_str('default_chanmode')); + return unless $mode; + + # return unless $channel is active, synced, not modeless, and we're a chanop + return unless ($channel && $channel->{synced} && $channel->{chanop} && !$channel->{no_modes}); + + # check if we're the only one visitor + my @nicks = $channel->nicks(); + return unless (scalar(@nicks) == 1); + + # final stage: issue the MODE + $channel->command("/MODE ".$channel->{name}." ".$mode); +} + +Irssi::settings_add_str('misc', 'default_chanmode', $default_chanmode); +Irssi::signal_add_last('channel sync', 'event_channel_sync'); + +# changes: +# +# 25.01.2002: Initial release (v1.0) +# 24.02.2002: splitted into two subroutines, minor cleanups (v1.1) |