1# This script shows modes in parts, quits, kicks, topic changes or actions, like show_nickmode does for public messages 2# 3# Usage: 4# You must change your formats to include the $mode, for example: 5# default format for part is: 6# {channick $0} {chanhost $1} has left {channel $2} {reason $3} 7# to include the mode, do 8# /format part $mode{channick $0} {chanhost $1} has left {channel $2} {reason $3} 9# for quits: 10# /format $mode{channick $0} {chanhost $1} has quit {reason $2} 11 12# Copyright (C) 2003-2007 Wouter Coekaerts <coekie@irssi.org> 13# 14# This program is free software; you can redistribute it and/or modify 15# it under the terms of the GNU General Public License as published by 16# the Free Software Foundation; either version 2 of the License, or 17# (at your option) any later version. 18# 19# This program is distributed in the hope that it will be useful, 20# but WITHOUT ANY WARRANTY; without even the implied warranty of 21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22# GNU General Public License for more details. 23# 24# You should have received a copy of the GNU General Public License 25# along with this program; if not, write to the Free Software 26# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 27 28use strict; 29use Irssi 20021028; 30use vars qw($VERSION %IRSSI); 31 32$VERSION = "0.3"; 33%IRSSI = ( 34 authors => "Wouter Coekaerts", 35 contact => "wouter\@coekaerts.be", 36 name => "showmode", 37 description => "show modes in parts, quits, kicks, topic changes or actions, like show_nickmode does for public messages", 38 license => "GPLv2 or later", 39 changed => "2007-07-28" 40); 41 42my @lastmode; 43 44# $mode2 is 0 for $mode, 1 for $mode2 (only used for 'the kicker') 45sub setlast { 46 my ($mode2, $server, $channelname, $nickname) = @_; 47 my @channels; 48 @lastmode[$mode2] = {}; 49 if (defined($channelname)) { 50 $channels[0] = $server->channel_find($channelname); 51 if (!defined($channels[0])) { 52 return; 53 } 54 } else { 55 @channels = $server->channels(); 56 57 } 58 59 foreach my $channel (@channels) { 60 my $nick = $channel->nick_find($nickname); 61 if (defined($nick)) { 62 $lastmode[$mode2]->{$channel->{'name'}} = $nick->{'op'} ? '@' : $nick->{halfop} ? '%' : $nick->{voice} ? '+' : '' ; 63 } 64 } 65} 66 67sub expando_mode { 68 my ($server,$item,$mode2) = @_; 69 if (!defined($item) || $item->{'type'} ne 'CHANNEL' ) { 70 return ''; 71 } 72 return $lastmode[$mode2]->{$item->{'name'}}; 73} 74 75Irssi::signal_add_first('message part', sub {setlast(0,$_[0],$_[1],$_[2]);}); 76Irssi::signal_add_first('message quit', sub {setlast(0,$_[0],undef,$_[1]);}); 77Irssi::signal_add_first('message topic', sub {setlast(0,$_[0],$_[1],$_[2]);}); 78Irssi::signal_add_first('message kick', sub {setlast(0,$_[0],$_[1],$_[2]); setlast(1,$_[0],$_[1],$_[3]);}); 79Irssi::signal_add_first('message irc action', sub {setlast(0,$_[0],$_[4],$_[2]);}); 80Irssi::signal_add_first('message irc own_action', sub {setlast(0,$_[0],$_[2],$_[0]->{nick});}); 81 82Irssi::expando_create('mode', sub {expando_mode($_[0],$_[1],0)},{ 'message part' => 'None'}); 83Irssi::expando_create('mode2', sub {expando_mode($_[0],$_[1],1)},{ 'message part' => 'None'}); 84