diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2015-09-15 15:07:31 +0000 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2015-09-24 20:29:46 +0000 |
commit | 8639f7af5db3ff3e6a6b7f5e7ceb1fc2405d33d5 (patch) | |
tree | 81877e56e57cc9896423b7abe31774f4b666f8ce /.irssi | |
parent | ab6694a9e28e0ed5c3c697cbe4a2e095f0022369 (diff) | |
download | dotfiles-8639f7af5db3ff3e6a6b7f5e7ceb1fc2405d33d5.tar.gz |
fix auto_bleh and add format_identify
Diffstat (limited to '.irssi')
-rw-r--r-- | .irssi/default.theme | 25 | ||||
-rw-r--r-- | .irssi/scripts/autobleh.pl | 732 | ||||
-rw-r--r-- | .irssi/scripts/autorun/auto_bleh.pl | 293 | ||||
-rw-r--r-- | .irssi/scripts/autorun/format_identify.pl | 440 |
4 files changed, 758 insertions, 732 deletions
diff --git a/.irssi/default.theme b/.irssi/default.theme index ac99356a..29d48ba9 100644 --- a/.irssi/default.theme +++ b/.irssi/default.theme @@ -292,3 +292,28 @@ abstracts = { # hilight with specified color, $0 = color, $1 = text sb_act_hilight_color = "$0$1-%n"; }; +formats = { + "fe-common/core" = { + pubmsg_me = "{pubmsgmenick $2 {menick $0}}$1"; + pubmsg_me_channel = "{pubmsgmenick $3 {menick $0}{msgchannel $1}}$2"; + pubmsg_hilight = "{pubmsghinick $0 $3 $1}$2"; + pubmsg_hilight_channel = "{pubmsghinick $0 $4 $1{msgchannel $2}$3"; + pubmsg = "{pubmsgnick $2 {pubnick $0}}$1"; + pubmsg_channel = "{pubmsgnick $3 {pubnick $0}{msgchannel $1}}$2"; + msg_private = "{privmsg $0 $1 }$2"; + msg_private_query = "{privmsgnick $0}$2"; + }; + "fe-common/irc" = { + notice_public = "{notice $0{pubnotice_channel $1}}$2"; + notice_private = "{notice $0{pvtnotice_host $1}}$2"; + action_private = "{pvtaction $0}$2"; + action_private_query = "{pvtaction_query $0}$2"; + action_public = "{pubaction $0}$1"; + action_public_channel = "{pubaction $0{msgchannel $1}}$2"; + ctcp_reply = "CTCP {hilight $0} reply from {nick $1}: $2"; + ctcp_reply_channel = "CTCP {hilight $0} reply from {nick $1} in channel {channel $3}: $2"; + ctcp_ping_reply = "CTCP {hilight PING} reply from {nick $0}: $1.$[-3.0]2 seconds"; + ctcp_requested = "{ctcp {hilight $0} {comment $1} requested CTCP {hilight $2} from {nick $4}}: $3"; + ctcp_requested_unknown = "{ctcp {hilight $0} {comment $1} requested unknown CTCP {hilight $2} from {nick $4}}: $3"; + }; +}; diff --git a/.irssi/scripts/autobleh.pl b/.irssi/scripts/autobleh.pl deleted file mode 100644 index cfca1711..00000000 --- a/.irssi/scripts/autobleh.pl +++ /dev/null @@ -1,732 +0,0 @@ -use Irssi; -use Irssi::Irc; -use strict; -use vars qw( $VERSION %IRSSI $DEBUG ); -use LWP::Simple; - -# -# autobleh is an irssi helper script for IRC Channel OPs -# and IRC Network Staff. -# -# Version: -# $Id: autobleh.pl 33 2012-01-19 14:52:21Z sysdef $ -# -# Contact: -# email: sysdef@projectnet.org -# project website: http://autobleh.projectnet.org/ -# support channel: irc://chat.freenode.net/#autobleh -# repository: https://guest:guest@svn.projectnet.org/svn/autobleh/ -# -# This script is licensed under GPL Version 3 -# License - http://www.gnu.org/licenses/gpl.html -# -# Please send all your thanks, money, donations, coffee, code, suggestions, -# fixes and patches or hardware to the projects main contact but please -# write an email first. -# -# Sometimes it's possible to directly send gifts to the developer who needs -# the part you want to give away so we can save additional shipment fees. -# -# You will find your thanks and contributions in-kind listed on the project -# website and details on how it was shared and helped our development or -# developers. -# - -$VERSION = q$Rev: 33 $; -%IRSSI = ( - authors => 'Juergen (sysdef) Heine, Tom (tomaw) Wesley, Nathan (nhandler) Handler. Based on auto_bleh.pl by Don Armstrong', - name => 'autobleh', - description => 'Provides /ak /aq /ab /abr /abrn /arn /amb /amr /at /op /topicset /modeset /af', - license => 'GPL3', - changed => q$Id: autobleh.pl 33 2012-01-19 14:52:21Z sysdef $, -); - -# CHANGELOG -# 2012-01-19 - sysdef - renamed example config file; fixed comment char(;) in config ini file -# 2011-02-02 - nhandler - Allow using $nick and $channel in bleh_remove_message -# 2010-12-13 - nhandler - Remove extra space to fix kick command (Thanks rww) -# 2010-12-04 - nhandler - Change bleh_at_stay_opped from 10 to 300 seconds (5 minutes) -# 2010-07-24 - nhandler - Don't hardcode the path to the irssi directory -# 2010-07-23 - nhandler - Add check for updates and bleh_updates setting -# 2010-07-23 - nhandler - Use new ban forward syntax -# 2010-07-23 - nhandler - Turn $DEBUG insto a setting, bleh_debug -# 2010-07-23 - nhandler - Update quiet/ban exceptions -# 2010-07-23 - nhandler - Fix TIMEOUT default to really be 10 minutes -# 2010-07-23 - nhandler - add '/help autobleh' command -# ????-??-?? - tomaw - add irssi setting bleh_deop_after_action -# 2008-01-08 - sysdef - add irssi setting bleh_remove_message -# 2008-01-08 - sysdef - add command op -# 2008-01-08 - sysdef - add command topicset -# 2008-01-08 - sysdef - add command modeset -# 2008-01-22 - sysdef - solve the 'Unable to find nick: CHANSERV' error -# 2008-01-22 - sysdef - add aliases /remove -# 2008-01-25 - sysdef - add command af (auto forward / forward ban) - -# read the config file -open ( CONF, Irssi::get_irssi_dir()."/autobleh.conf" ) or Irssi::print( "warning: '".Irssi::get_irssi_dir()."/autobleh.conf' doesn't exist. Note there is 'autobleh.conf.example'."); -Irssi::print("loading autobleh config ..."); -my $category; -my $config; -my $val; -my $key; -my $linecount; -foreach my $line ( <CONF> ) { - chomp $line; - $linecount++; - # filter empty lines - if ( $line =~ /^\s*$/ ) { - # Irssi::print("empty: $line"); - } - # new category - elsif ( $line =~ /^\[/ ) { - $line =~ /\[(.*)\]/; - $category = $1; - Irssi::print("category: $category"); - } - # filter comments - elsif ( $line =~ /^;\s+/ ) { - # Irssi::print("comment: $line"); - } - # get key/value pair - elsif ( $line =~ /^([^ ]+)\s*=\s*([^ ]+)$/ && $category ) { - Irssi::print( "by config.$linecount: $category '$1' => '$2'" ); - $config->{$category}{$1} = $2; - } - # crap line - else { - Irssi::print( "PLEASE FIX YOUR CONFIG, LINE $linecount: '$line'" ); - } -} -close CONF; - -# unless defined $DEBUG; -Irssi::settings_add_bool( $IRSSI{name}, 'bleh_debug', 1 ); -$DEBUG = Irssi::settings_get_bool( 'bleh_debug' ); - -# Check for updates by default -Irssi::settings_add_bool( $IRSSI{name}, 'bleh_updates', 1 ), -check_updates(); - -my ( $actions, %defaults ); - -%defaults = ( - GET_OP => 1, # Should we try to get opped when we bleh? - USE_CHANSERV => 1, # Should we use chanserv to get opped? - EXPIRE => 6000, # Do not try to do anything if the action is more than 6000 seconds old. - TIMEOUT => 600, # Timeout /at bans after 600 seconds (10 minutes) - DEOP => 1, # We want to deop after action -); - -my %command_bindings = ( - - op => 'cmd_op', - - ams => 'cmd_modeset', - modeset => 'cmd_modeset', - - ats => 'cmd_topicset', - topicset => 'cmd_topicset', - - af => 'cmd_af', - forward => 'cmd_af', - - ak => 'cmd_ak', - kick => 'cmd_ak', - - ab => 'cmd_ab', - ban => 'cmd_ab', - - aq => 'cmd_aq', - quit => 'cmd_aq', - - ar => 'cmd_ar', - remove => 'cmd_ar', - - abr => 'cmd_abr', - removeban => 'cmd_abr', - - abk => 'cmd_abk', - kickban => 'cmd_abk', - - abrn => 'cmd_abrn', - removeban_notice => 'cmd_abrn', - - abkn => 'cmd_abkn', - kickban_notice => 'cmd_abkn', - - arn => 'cmd_arn', - remove_notice => 'cmd_arn', - - amb => 'cmd_amb', - massban => 'cmd_amb', - - amr => 'cmd_amr', - massremove => 'cmd_amr', - - at => 'cmd_at', - quiet_temp => 'cmd_at', - - help => 'cmd_help', - -); - -my %bans_to_remove; - - -sub cmd_help{ - my ( $data, $server, $witem ) = @_; - if( $data =~ m/^autobleh$/i ) { - Irssi::print( "/op: Ops teh user given as argument, e.g. /op bofh" ); - Irssi::print( "/ams, /modeset: Sets any mode you want. This is useful for removing bans, e.g. /modeset -b *!*\@trollhost" ); - Irssi::print( "/ats, /topicset: Sets the topic, e.g. /topicset no trolls allowed in here" ); - Irssi::print( "/af, /forward: Sets a forward ban if defined in the config file, e.g. /af sometroll" ); - Irssi::print( "/ak, /kick: Kicks a user, e.g. /ak sometroll" ); - Irssi::print( "/ab, /ban: Sets up a ban on a user's host: /ab sometroll." ); - Irssi::print( "/aq, /quiet: Quiets a user e.g. /aq sometroll" ); - Irssi::print( "/ar, /remove: Remove a user" ); - Irssi::print( "/abr, /removeban: Bans and removes a user from a channel." ); - Irssi::print( "/abk, /kickban: Kickban a user" ); - Irssi::print( "/abrn, /removeban_notice: Bans, removes and sends the user a notice" ); - Irssi::print( "/arn, /remove_notice: Removes the user and sends a notice" ); - Irssi::print( "/amb, /massban: Bans more than one user with one command, e.g. /amb sometroll sometroll2" ); - Irssi::print( "/amr, /massremove: Removes more than one user with one command, e.g. /amr sometroll sometroll2" ); - Irssi::print( "/at, /quiet_temp: Quiets a user for 10 minutes." ); - } -} - - -sub cmd_op{ - my ( $data, $server, $witem ) = @_; - # return get_op($data,$server,$witem); - return do_bleh( 'op', $data, $server, $witem ); -} - - -sub cmd_modeset{ - my ( $data, $server, $witem ) = @_; - return do_bleh( 'modeset', $data, $server, $witem ); -} - - -sub cmd_topicset{ - my ( $data, $server, $witem ) = @_; - return do_bleh( 'topicset', $data, $server, $witem ); -} - - -sub cmd_at{ - my ( $data, $server, $witem ) = @_; - return do_bleh( 'timeout', $data, $server, $witem ); -} - - -sub cmd_ak{ - my ( $data, $server, $witem ) = @_; - return do_bleh( 'kick', $data, $server, $witem ); -} - - -sub cmd_af{ - my ( $data, $server, $witem ) = @_; - - if ( defined $config->{forwardban}{$witem->{name}} ) { - # channel -> $config->{forwardban}{ $witem->{name}} - my $targetchannel = $witem; - my $channel = $server->channel_find( $config->{forwardban}{$witem->{name}} ); - if (!$channel) { - Irssi::print( "Error: i'm not in channel " . $config->{forwardban}{$witem->{name}} . " right now." ); - return; - } - # TODO: Check if channel is +i and not +Q - do_bleh( 'modeset', "+I " . $data, $server, $channel ); - return do_bleh( 'forward, kick', $data, $server, $witem ); - } - else { - Irssi::print( 'Error: forward channel for ' . $witem->{name} .' was not set. Please edit section [forwardban] in ~/.irssi/autobleh.conf'); - } -} - - -sub cmd_abk{ - my ( $data, $server, $witem ) = @_; - return do_bleh( 'kick,ban', $data, $server, $witem ); -} - - -sub cmd_abkn{ - my ( $data, $server, $witem ) = @_; - return do_bleh( 'kick,ban,notice', $data, $server, $witem ); -} - - -sub cmd_amb{ - my ( $data, $server, $witem ) = @_; - my @nicks = split /\s+/, $data; - for ( @nicks ) { - next unless /\w/; - do_bleh( 'ban', $_, $server, $witem ); - } -} - - -sub cmd_ab{ - my ( $data, $server, $witem ) = @_; - return do_bleh( 'ban', $data, $server, $witem ); -} - - -sub cmd_aq{ - my ( $data, $server, $witem ) = @_; - return do_bleh( 'quiet', $data, $server, $witem ); -} - - -sub cmd_amr{ - my ( $data, $server, $witem ) = @_; - my @nicks = split /\s+/, $data; - for ( @nicks ) { - next unless /\w/; - do_bleh( 'remove', $_, $server, $witem ); - } -} - - -sub cmd_ar{ - my ( $data, $server, $witem ) = @_; - return do_bleh( 'remove', $data, $server, $witem ); -} - - -sub cmd_abr{ - my ( $data, $server, $witem ) = @_; - return do_bleh( 'remove,ban', $data, $server, $witem ); -} - - -sub cmd_abrn{ - my ( $data, $server, $witem ) = @_; - return do_bleh( 'remove,ban,notice', $data, $server, $witem ); -} - - -sub cmd_arn{ - my ( $data, $server, $witem ) = @_; - return do_bleh( 'remove,notice', $data, $server, $witem ); -} - - -sub do_bleh{ - my ( $cmd, $data, $server, $witem, $duration ) = @_; - - if ( !$server || !$server->{connected} ) { - Irssi::print( 'Not connected to server' ); - return; - } - - # fix the error: "Can't use string ("0") as a HASH ref while "strict refs" in use at..." - if ( $witem eq 0 ) { - Irssi::print( 'Can\'t autokick on a non-channel.' ); - return; - } - - if ( $witem->{type} ne 'CHANNEL' ) { - Irssi::print( 'Can\'t autokick on a non-channel. [' . $witem->{type} . ']' ); - return; - } - - # set the network that we're on, the channel and the nick to kick - # once we've been opped - $data =~ /^\s*([^\s]+)\s*(\d+)?\s*(.+?|)\s*$/; - my $nick = $1; - my $timeout = $2; - my $reason = $3; - $timeout = $defaults{TIMEOUT} if not defined $timeout or $timeout eq ''; - - if ( $cmd =~ /^(topicset|modeset)$/ ) { - $reason = $nick . ' ' . $reason; - $nick = "CHANSERV"; - } - else { - $reason = Irssi::settings_get_str( 'bleh_remove_message' ) if not defined $reason or $reason eq ''; - } - - $reason =~ s/\$nick/$nick/g; - $reason =~ s/\$channel/$witem->{name}/g; - - my $nick_rec = $witem->nick_find( $nick ); - if ( $nick ne 'CHANSERV' ) { - if ( not defined $nick_rec ) { - Irssi::print( 'Unable to find nick: ' . $nick); - return; - } - } - - my $hostname = $nick_rec->{host} if defined $nick_rec; - if ( $nick ne 'CHANSERV' ) { - Irssi::print( 'Unable to find hostname for ' . $nick ) if not defined $hostname or $hostname eq ''; - } - my $username = $hostname; - $hostname =~ s/.+\@//; - $username =~ s/@.*//; - $username =~ s/.*=//; - - Irssi::print( 'Nick set to \'' . $nick . '\' from \'' . $data . '\', reason set to \'' . $reason . '\'.' ) if $DEBUG; - - my $action = { - type => $cmd, - nick => $nick, - nick_rec => $nick_rec, - network => $witem->{server}->{chatnet}, - server => $witem->{server}, - completed => 0, - inserted => time, - channel => $witem->{name}, - reason => $reason, - hostname => $hostname, - username => $username, - timeout => $timeout, - }; - - Irssi::print( i_want( $action ) ) if $DEBUG; - - if ( $witem->{chanop} ) { - Irssi::print( 'DEBUG: take action ' . $action ) if $DEBUG; - take_action( $action, $server, $witem ); - } - else { - Irssi::print( 'DEBUG: try to get op in ' . $action->{channel} ) if $DEBUG; - $actions->{$data . $action->{inserted}}=$action; - get_op( $server, $action->{channel} ) if $defaults{GET_OP}; - } - -} - - -sub get_op{ - my ( $server,$channel) = @_; - Irssi::print("QUOTE CS op $channel") if $DEBUG; - $server->command("QUOTE CS op $channel") if $defaults{USE_CHANSERV}; -} - - -sub i_want{ - my $action = shift; - return 'I\'ve wanted to ' - . $action->{type} . ' ' - . $action->{nick} . ' in ' - . $action->{channel} . ' on ' - . $action->{network} . ' since ' - . $action->{inserted}; -} - - -sub take_action { - my ( $action, $server, $channel ) = @_; - - local $_ = $action->{type}; - # Now support multiple actions against a single nick (to FE, kick ban, or remove ban). See /abr foo - - if ( /op/ ) { - Irssi::print( 'Give OP only' ) if $DEBUG; - %defaults->{DEOP} = 0; - } - - if ( /modeset/ ) { - Irssi::print( 'Setmode on ' . $action->{channel} ) if $DEBUG; - # Set channel mode - $channel->command( '/mode ' . $action->{reason} ); - } - - if ( /topicset/ ) { - Irssi::print( 'Settopic on ' . $action->{channel} ) if $DEBUG; - # Set topic - $channel->command( '/topic ' . $action->{reason} ); - # we have to deop us here becaue we receive no modechange - if ( Irssi::settings_get_bool( 'bleh_deop_after_action' ) ) { - Irssi::print( 'MODE ' . $channel->{name} . ' -o ' . $channel->{ownnick}->{nick} ) if $DEBUG; - $channel->command( '/deop ' . $channel->{ownnick}->{nick} ); - } - } - - if ( /timeout/ ) { - if ( $action->{hostname} =~ /(gateway\/shell\/.+\/)x-.+/ || $action->{hostname} =~ /((?:conference|nat)\/.+\/)x-.+/ ) { - Irssi::print( 'Quieting ' - . $action->{nick} . ' on ' - . $action->{channel} . ' with username ' - . $action->{username} . ' for ' - . $action->{timeout} . ' seconds') if $DEBUG; - #quiet username - $channel->command( '/quote MODE ' . $action->{channel} . ' +q *!' . $action->{username} . '@' . $1 . '*' ) - if $action->{username} ne ''; - } - else { - Irssi::print( 'Quieting ' - . $action->{nick} . ' on ' - . $action->{channel} . ' with hostname ' - . $action->{hostname} . ' for ' - . $action->{timeout} . ' seconds' ) if $DEBUG; - #quiet hostname - $channel->command( '/quote MODE ' . $action->{channel} . ' +q *!*@' . $action->{hostname} ) - if $action->{hostname} ne ''; - } - $bans_to_remove{"$action->{nick}$action->{inserted}"} = $action; - # don't deop on a short time - if ( $action->{timeout} < Irssi::settings_get_str( 'bleh_at_stay_opped' ) ) { - Irssi::print( 'I\'ll stay opped until unquiet because ' . $action->{timeout} . ' < ' . Irssi::settings_get_str( 'bleh_at_stay_opped' ) ) if $DEBUG; - %defaults->{DEOP} = 0; - } - else { - Irssi::print( 'I\'ll NOT stay opped until unquiet because ' . $action->{timeout} . ' < ' . Irssi::settings_get_str( 'bleh_at_stay_opped' ) ) if $DEBUG; - } - } - - if ( /quiet/ ) { - if ( $action->{hostname} =~ /(gateway\/shell\/.+\/)x-.+/ || $action->{hostname} =~ /((?:conference|nat)\/.+\/)x-.+/ ) { - Irssi::print( 'Quieting ' - . $action->{nick} . ' on ' - . $action->{channel} . ' with username ' - . $action->{username} ) if $DEBUG; - # Find hostname and quiet username - $channel->command( '/quote MODE ' . $action->{channel} . ' +q *!' . $action->{username} . '@' . $1 . '*' ) - if $action->{username} ne ''; - } - else { - Irssi::print( 'Quieting ' - . $action->{nick} . ' on ' - . $action->{channel} . ' with hostname ' - . $action->{hostname} ) if $DEBUG; - # Find hostname and quiet hostname - $channel->command( '/quote MODE ' . $action->{channel} . ' +q *!*@' . $action->{hostname} ) - if $action->{hostname} ne ''; - } - } - - if ( /ban/ ) { - if ( $action->{hostname} =~ /(gateway\/shell\/.+\/)x-.+/ || $action->{hostname} =~ /((?:conference|nat)\/.+\/)x-.+/ ) { - Irssi::print( 'Banning ' - . $action->{nick} . ' from ' - . $action->{channel} . ' with username ' - . $action->{username} ) if $DEBUG; - # ban username - $channel->command( '/quote MODE ' . $action->{channel} . ' +b *!' . $action->{username} . '@' . $1 . '*' ) - if $action->{username} ne ''; - } - else { - Irssi::print( 'Banning ' - . $action->{nick}. ' from ' - . $action->{channel} . ' with hostname ' - . $action->{hostname} ) if $DEBUG; - # ban hostname - $channel->command( '/quote MODE ' . $action->{channel} . ' +b *!*@' . $action->{hostname} ) - if $action->{hostname} ne ''; - } - } - - if ( /set_invite/ ) { - Irssi::print( 'Set +I for ' - . $action->{nick} . ' in ' - . $action->{channel} . ' with hostname ' - . $action->{hostname} ) if $DEBUG; - $channel->command( '/quote MODE ' . $action->{channel} . ' +I ' . $action->{nick} . '!*@' . $action->{hostname} ) - if $action->{hostname} ne ''; - } - - - if ( /forward/ ) { - if ( defined $config->{forwardban}{$action->{channel}} ) { - my $fwchan = $config->{forwardban}{$action->{channel}}; - Irssi::print( 'Forward ' - . $action->{nick} . ' from ' - . $action->{channel} . ' to ' - . $fwchan . ' with hostname ' - . $action->{hostname} ) if $DEBUG; - # ban hostname - $channel->command( '/quote MODE ' . $action->{channel} . ' +b ' . $action->{nick} . '!*@' . $action->{hostname} . '$' . ${fwchan} ) - if $action->{hostname} ne ''; - - # # invite user to fwchan - # Irssi::print("INVITE user to $fwchan") if $DEBUG; - # $channel->command("/quote invite $action->{nick} $fwchan"); - - # notice user - $channel->command( '/NOTICE ' - . $action->{nick} . ' You got a FORWARD BAN from ' - . $action->{channel} . ' to ' - . $fwchan . '. Please rejoin channel ' - . $action->{channel} ); - } - else { - Irssi::print( 'ATTENTION: add line \'' . $action->{channel} . ' <targetchannel>\' to [forwardban] section in ./irssi/autobleh.conf' ); - return; - } - } - - if ( /kick/) { - Irssi::print( 'Kicking ' - . $action->{nick} . ' from ' - . $action->{channel} ) if $DEBUG; - #wtf? -> if ($action->{reason} =~ /\s/) { - $channel->command( '/quote KICK ' . $action->{channel} . ' ' . $action->{nick} . ' :' . $action->{reason} ); - #} - #else { - # $channel->command("/quote REMOVE $action->{channel} $action->{nick} $action->{reason}"); - #} - } - - if ( /remove/ ) { - Irssi::print( 'Removing ' - . $action->{nick} . ' from ' - . $action->{channel} ) if $DEBUG; - if ( $action->{reason} =~ /\s/ ) { - $channel->command( '/quote REMOVE ' . $action->{channel} . ' ' . $action->{nick} . ' :' . $action->{reason} ); - } else { - $channel->command( '/quote REMOVE ' . $action->{channel} . ' ' . $action->{nick} . ' ' . $action->{reason}); - } - } - - if ( /notice/ ) { - Irssi::print( 'Noticing ' - . $action->{nick} . ' with ' - . $action->{reason} ) if $DEBUG; - $channel->command( '/NOTICE ' . $action->{nick} . ' ' . $action->{reason} ); - } - - if ( /teiuq/ ) { - if ( $action->{hostname} =~ /(gateway\/shell\/.+\/)x-.+/ || $action->{hostname} =~ /((?:conference|nat)\/.+\/)x-.+/ ) { - Irssi::print( 'Unquieting ' - . $action->{nick} . ' on ' - . $action->{channel} . ' with username ' - . $action->{username} ) if $DEBUG; - $channel->command( '/quote MODE ' . $action->{channel} . ' -q *!' . $action->{username} . '@' . $1 . '*' ); - } - else { - Irssi::print( 'Unquieting ' - . $action->{nick} . ' on ' - . $action->{channel} . ' with hostname ' - . $action->{hostname} ) if $DEBUG; - $channel->command("/quote MODE $action->{channel} -q *!*@".$action->{hostname}); - } - } - return; #for now. -} - - -sub deop_us{ - my ($rec) = @_; - my $channel = $rec->{channel}; - my $server = $rec->{server}; - - Irssi::print( 'MODE ' . $channel->{name} . ' -o ' . $channel->{ownnick}->{nick} ) if $DEBUG; - $channel->command( '/deop ' . $channel->{ownnick}->{nick} ); -} - - -sub sig_mode_change{ - my ( $channel, $nick ) = @_; - - # Are there any actions to process? - # See if we got opped. - return if scalar( keys %$actions ) eq 0; - - my @deop_array; - if ( $channel->{server}->{nick} eq $nick->{nick} and $nick->{op} ) { - Irssi::print( 'We\'ve been opped' ) if $DEBUG; - foreach ( keys %$actions ) { - # See if this action is too old - if ( time - $actions->{$_}->{inserted} > $defaults{EXPIRE} ) { - Irssi::print( 'Expiring action: "' . i_want( $actions->{$_} ) . '" because of timeout' ) if $DEBUG; - delete $actions->{$_}; - next; - } - Irssi::print( i_want( $actions->{$_} ) ) if $DEBUG; - # Find the server to take action on - my $server = $actions->{$_}->{server}; - Irssi::print( 'Unable to find server for chatnet: ' . $actions->{$_}->{network} ) and return if not defined $server; - Irssi::print( 'Found server for chatnet: ' . $actions->{$_}->{network} ) if $DEBUG; - # Find the channel to take action on - my $channel = $server->channel_find( $actions->{$_}->{channel} ); - Irssi::print( 'Unable to find channel for channel: ' . $actions->{$_}->{channel} ) and return if not defined $channel; - Irssi::print( 'Found channel for channel: ' . $actions->{$_}->{channel} ) if $DEBUG; - Irssi::print( 'We are opped on the channel!' ) if $DEBUG; - take_action( $actions->{$_}, $server, $channel ); - if ( Irssi::settings_get_bool( 'bleh_deop_after_action' ) and %defaults->{DEOP} eq 1 ) { - push @deop_array, {server=>$server,channel=>$channel}; - } - %defaults->{DEOP} = 1; - # Do not repeat this action. - delete $actions->{$_}; - } - foreach ( @deop_array ) { - deop_us( $_ ); - } - } else { - Irssi::print( 'Fooey. Not opped.' ) if $DEBUG; - } -} - - -sub try_to_remove_bans{ - return unless keys %bans_to_remove; - for my $key ( keys %bans_to_remove ) { - if ( ( $bans_to_remove{$key}{inserted} + $bans_to_remove{$key}{timeout} ) < time ) { - $bans_to_remove{$key}{type} = 'teiuq'; - $actions->{$key} = $bans_to_remove{$key}; - delete $bans_to_remove{$key}; - - # TODO: only try to get op if we're not opped - # if ($witem->{chanop}) { - # Irssi::print("DEBUG: take action $action") if $DEBUG; - # take_action($action,$server,$witem); - # } - # else { - # Irssi::print("DEBUG: try to get op in $action->{channel}") if $DEBUG; - # $actions->{$data.$action->{inserted}}=$action; - # get_op($server, $action->{channel}) if $defaults{GET_OP}; - # } - - get_op( $actions->{$key}{server}, $actions->{$key}{channel} ) if $defaults{GET_OP}; - } - } -} - - -sub check_updates{ - return unless Irssi::settings_get_bool( 'bleh_updates' ); - my $url = 'http://autobleh.projectnet.org/version'; - my $latest = get( $url ); - chomp $latest; - my( $current ) = $VERSION =~ m/(\d+)/; - $current = sprintf( "%4.2f", $current / 100 ); - if( defined $latest ) { - if( $latest > $current ) { - Irssi::print( 'A new version of autobleh (' . $latest . ') is available at http://autobleh.projectnet.org/downloads/autobleh-' . $latest . '.tar.gz' ); - Irssi::print( 'autobleh ' . $current . ' is currently installed.' ); - } - else { - Irssi::print( 'autobleh (' . $current . ') is up-to-date.' ); - } - } - else { - Irssi::print( 'Failed to check for updates to autobleh.' ); - } -} - - -# call the try to remove bans function every minute -Irssi::timeout_add( 1000 * 5, 'try_to_remove_bans', undef ); -Irssi::signal_add_last( 'nick mode changed', 'sig_mode_change' ); -my ( $command, $function ); - -while ( ( $command, $function ) = each %command_bindings ) { - Irssi::command_bind( $command, $function, 'bleh' ); -} - -Irssi::settings_add_bool( $IRSSI{name}, 'bleh_deop_after_action', 1 ); -Irssi::settings_add_str( $IRSSI{name}, 'bleh_remove_message', 'you should know better' ); -Irssi::settings_add_str( $IRSSI{name}, 'bleh_at_stay_opped', 300 ); # 5 minutes - -# find text for antispam -#Irssi::signal_add_last( "message public", "msg_public" ); - -1; - diff --git a/.irssi/scripts/autorun/auto_bleh.pl b/.irssi/scripts/autorun/auto_bleh.pl new file mode 100644 index 00000000..9c00b2fa --- /dev/null +++ b/.irssi/scripts/autorun/auto_bleh.pl @@ -0,0 +1,293 @@ +use Irssi; +use Irssi::Irc; +use strict; +use vars qw($VERSION %IRSSI $DEBUG); + +$VERSION = q$Revision: 1.1 $; +%IRSSI = (authors => 'tomaw, based on auto_bleh.pl by Don Armstrong', + name => 'auto_bleh', + description => 'Provides /ak /aq /ab /abr /abrn /arn /amb /amr /at', + license => 'GPL', + changed => q$Id: auto_bleh.pl,v 1.1 2005/03/17 08:19:53 don Exp $, +); + +#$DEBUG = 1 unless defined $DEBUG; + +my ($actions, %defaults); + +%defaults = (GET_OP => 1, # Should we try to get opped when we auto_bleh? + USE_CHANSERV => 1, # Should we use chanserv to get opped? + EXPIRE => 6000, # Do not try to do anything if the action is more than 6000 seconds old. + TIMEOUT => 10, # Timeout /at bans after 10 minutes +); + +my %command_bindings = (ak => 'cmd_ak', + ab => 'cmd_ab', + aq => 'cmd_aq', + ar => 'cmd_ar', + abr => 'cmd_abr', + abk => 'cmd_abk', + abrn => 'cmd_abrn', + abk => 'cmd_abkn', + arn => 'cmd_arn', + amb => 'cmd_amb', + amr => 'cmd_amr', + at => 'cmd_at', +); + +my %bans_to_remove; + +sub cmd_at { + my ($data, $server, $witem) = @_; + return do_auto_bleh('timeout',$data,$server,$witem); +} + +sub cmd_ak { + my ($data, $server, $witem) = @_; + return do_auto_bleh('kick',$data,$server,$witem); +} + +sub cmd_abk { + my ($data, $server, $witem) = @_; + return do_auto_bleh('kick,ban',$data,$server,$witem); +} +sub cmd_abkn { + my ($data, $server, $witem) = @_; + return do_auto_bleh('kick,ban,notice',$data,$server,$witem); +} + +sub cmd_amb{ + my ($data, $server, $witem) = @_; + my @nicks = split /\s+/, $data; + for (@nicks) { + next unless /\w/; + do_auto_bleh('ban',$_,$server,$witem); + } +} + +sub cmd_ab { + my ($data, $server, $witem) = @_; + return do_auto_bleh('ban',$data,$server,$witem); +} + +sub cmd_aq { + my ($data, $server, $witem) = @_; + return do_auto_bleh('quiet',$data,$server,$witem); +} + + +sub cmd_amr{ + my ($data, $server, $witem) = @_; + my @nicks = split /\s+/, $data; + for (@nicks) { + next unless /\w/; + do_auto_bleh('remove',$_,$server,$witem); + } +} + +sub cmd_ar { + my ($data, $server, $witem) = @_; + return do_auto_bleh('remove',$data,$server,$witem); +} +sub cmd_abr{ + my ($data, $server, $witem) =@_; + return do_auto_bleh('remove,ban',$data,$server,$witem); +} +sub cmd_abrn{ + my ($data, $server, $witem) =@_; + return do_auto_bleh('remove,ban,notice',$data,$server,$witem); +} +sub cmd_arn{ + my ($data, $server, $witem) =@_; + return do_auto_bleh('remove,notice',$data,$server,$witem); +} + + +sub do_auto_bleh { + my ($cmd, $data, $server, $witem, $duration) = @_; + + if (!$server || !$server->{connected}) { + Irssi::print("Not connected to server"); + return; + } + + if ($witem->{type} ne 'CHANNEL') { + Irssi::print("Can't autokick on a non-channel. [$witem->{type}]"); + return; + } + + # set the network that we're on, the channel and the nick to kick + # once we've been opped + + $data =~ /^\s*([^\s]+)\s*(\d+)?\s*(.+?|)\s*$/; + my $nick = $1; + my $timeout = $2; + my $reason = $3; + $timeout = $defaults{TIMEOUT} if not defined $timeout or $timeout eq ''; + $reason = 'you should know better' if not defined $reason or $reason eq ''; + + my $nick_rec = $witem->nick_find($nick); + if (not defined $nick_rec) { + Irssi::print("Unable to find nick: $nick"); + return; + } + + my $hostname = $nick_rec->{host} if defined $nick_rec; + Irssi::print("Unable to find hostname for $nick") if not defined $hostname or $hostname eq ''; + $hostname =~ s/.+\@//; + + Irssi::print("Nick set to '$nick' from '$data', reason set to '$reason'.") if $DEBUG; + my $action = {type => $cmd, + nick => $nick, + nick_rec => $nick_rec, + network => $witem->{server}->{chatnet}, + server => $witem->{server}, + completed => 0, + inserted => time, + channel => $witem->{name}, + reason => $reason, + hostname => $hostname, + timeout => $timeout, + }; + Irssi::print(i_want($action)) if $DEBUG; + if ($witem->{chanop}) { + take_action($action,$server,$witem); + } + else { + $actions->{$data.$action->{inserted}}=$action; + get_op($server, $action->{channel}) if $defaults{GET_OP}; + } +} + +sub get_op { + my ($server,$channel) = @_; + + Irssi::print("QUOTE CS op $channel") if $DEBUG; + $server->command("QUOTE CS op $channel") if $defaults{USE_CHANSERV}; +} + +sub i_want { + my $action = shift; + return "I've wanted to $action->{type} $action->{nick} off $action->{channel} on $action->{network} since $action->{inserted}"; +} + +sub take_action { + my ($action,$server,$channel) = @_; + + local $_ = $action->{type}; + # Now support multiple actions against a single nick (to FE, kick ban, or remove ban). See /abr foo + if (/timeout/) { + Irssi::print("Quieting $action->{nick} on $action->{channel} with hostname $action->{hostname} for $action->{timeout} minutes") if $DEBUG; + $channel->command("/quote MODE $action->{channel} +q *!*@".$action->{hostname}) if $action->{hostname} ne ''; #quiet hostname + $bans_to_remove{"$action->{nick}$action->{inserted}"} = $action; + } + if (/quiet/) { + Irssi::print("Quieting $action->{nick} on $action->{channel} with hostname $action->{hostname}") if $DEBUG; + # Find hostname + $channel->command("/quote MODE $action->{channel} +q *!*@".$action->{hostname}) if $action->{hostname} ne ''; #quiet hostname + } + if (/ban/) { + Irssi::print("Banning $action->{nick} from $action->{channel} with hostname $action->{hostname}") if $DEBUG; + $channel->command("/quote MODE $action->{channel} +b *!*@".$action->{hostname}) if $action->{hostname} ne ''; # ban hostname + } + if (/kick/) { + Irssi::print("Kicking $action->{nick} from $action->{channel}") if $DEBUG; + if ($action->{reason} =~ /\s/) { + $channel->command("/quote KICK $action->{channel} $action->{nick} :$action->{reason}"); + } + else { + $channel->command("/quote REMOVE $action->{channel} $action->{nick} $action->{reason}"); + } + } + if (/remove/) { + Irssi::print("Removing $action->{nick} from $action->{channel}") if $DEBUG; + if ($action->{reason} =~ /\s/) { + $channel->command("/quote REMOVE $action->{channel} $action->{nick} :$action->{reason}"); + } else { + $channel->command("/quote REMOVE $action->{channel} $action->{nick} $action->{reason}"); + } + } + if (/notice/) { + Irssi::print("Noticing $action->{nick} with $action->{reason}") if $DEBUG; + $channel->command("/NOTICE $action->{nick} $action->{reason}"); + } + if (/teiuq/) { + Irssi::print("Unquieting $action->{nick} on $action->{channel} with hostname $action->{hostname}") if $DEBUG; + $channel->command("/quote MODE $action->{channel} -q *!*@".$action->{hostname}); + } + return; #for now. +} + +sub deop_us { + my ($rec) = @_; + my $channel = $rec->{channel}; + my $server = $rec->{server}; + + Irssi::print("MODE $channel->{name} -o $channel->{ownnick}->{nick}") if $DEBUG; + $channel->command("/deop $channel->{ownnick}->{nick}"); +} + +sub sig_mode_change { + my ($channel,$nick) = @_; + + # Are there any actions to process? + # See if we got opped. + return if scalar(keys %$actions) eq 0; + + my @deop_array; + if ($channel->{server}->{nick} eq $nick->{nick} and $nick->{op}) { + Irssi::print("We've been opped") if $DEBUG; + foreach (keys %$actions) { + # See if this action is too old + if (time - $actions->{$_}->{inserted} > $defaults{EXPIRE}) { + Irssi::print("Expiring action: \"".i_want($actions->{$_})."\" because of time") if $DEBUG; + delete $actions->{$_}; + next; + } + Irssi::print(i_want($actions->{$_})) if $DEBUG; + # Find the server to take action on + my $server = $actions->{$_}->{server}; + Irssi::print("Unable to find server for chatnet: $actions->{$_}->{network}") and return if not defined $server; + Irssi::print("Found server for chatnet: $actions->{$_}->{network}") if $DEBUG; + # Find the channel to take action on + my $channel = $server->channel_find($actions->{$_}->{channel}); + Irssi::print("Unable to find channel for channel: $actions->{$_}->{channel}") and return if not defined $channel; + Irssi::print("Found channel for channel: $actions->{$_}->{channel}") if $DEBUG; + Irssi::print("We are opped on the channel!") if $DEBUG; + take_action($actions->{$_},$server,$channel); + push @deop_array,{server=>$server,channel=>$channel} if Irssi::settings_get_bool('auto_bleh_deop_after_action'); + delete $actions->{$_}; # Do not repeat this action. + } + foreach (@deop_array) { + deop_us($_); + } + } else { + Irssi::print("Fooey. Not opped.") if $DEBUG; + } +} + +sub try_to_remove_bans { + return unless keys %bans_to_remove; + for my $key (keys %bans_to_remove) { + if (($bans_to_remove{$key}{inserted} + $bans_to_remove{$key}{timeout}*60) < time) { + $bans_to_remove{$key}{type} = 'teiuq'; #unquiet + $actions->{$key} = $bans_to_remove{$key}; + delete $bans_to_remove{$key}; + get_op($actions->{$key}{server}, $actions->{$key}{channel}) if $defaults{GET_OP}; + } + } +} + +# call the try to remove bans function every minute +Irssi::timeout_add(1000*60,'try_to_remove_bans',undef); +Irssi::signal_add_last('nick mode changed','sig_mode_change'); +my ($command,$function); + +while (($command,$function) = each %command_bindings) { + Irssi::command_bind($command,$function, 'auto_bleh'); +} + +Irssi::settings_add_bool($IRSSI{name}, 'auto_bleh_deop_after_action', 1); + +1; + diff --git a/.irssi/scripts/autorun/format_identify.pl b/.irssi/scripts/autorun/format_identify.pl new file mode 100644 index 00000000..0b19c445 --- /dev/null +++ b/.irssi/scripts/autorun/format_identify.pl @@ -0,0 +1,440 @@ + +#!/usr/bin/perl +# ^ to make vim know this is a perl script so I get syntax hilighting. + +##################################################################### +### WARNING: This version was restored from google cache ### +### by Wouter Coekaerts <coekie@irssi.org>. ### +### Syntax might not be exactly the same as the original ### +##################################################################### + +# $Id$ +use strict; +use vars qw($VERSION %IRSSI); +use Irssi qw(signal_stop signal_emit signal_remove + signal_add signal_add_first + settings_add_str settings_get_str settings_add_bool + settings_get_bool + print ); +$VERSION = '1.5-dev-coekie'; +%IRSSI = ( + authors => 'ResDev (Ben Reser)', + contact => 'ben@reser.org', + name => 'format_identify', + description => 'Formats msgs and notices when the identify-msg and/or ' . + 'identify-ctcp capability is available.', + license => 'GPL2', + url => 'http://ben.reser.org/irssi/', +); + +# Additional credit to ch for his wash-imsg script which was a starting place +# for this; coekie for pointing me towards the nickcolor script and its +# technique for doing this; Timo Sirainen and Ian Peters for writing nickcolor. + +# This script takes advantage of the identify-msg and identify-ctcp +# capabilities of the new dancer ircd. The identify-msg capability causes the +# first character of a msg or notice to be set to a + if the user is identified +# with nickserve and a - if not. identify-ctcp does similar for CTCP messages. +# This script removes the tagging and then allows you to configure a +# modification to the formating of the nickname. + +# Installation instructions: Drop this in ~/.irssi/scripts and run +# /script load format_identify. To make it autorun on startup place it in +# ~/.irssi/scripts/autorun. This script will detect if the IRC server has +# the identify-msg and identify-ctcp capability. If it is available it will +# use it. Messages on servers without support for these capabilities will +# be tagged as unknown. +# +# While you can unload this script. Any servers that you are connected to +# with identify-msg/identify-ctcp turned on will continue to send data +# encoded that way. This means messages and notices will have a + or - +# appended to the front of them. CTCPs will be broken. Unfortunately, there +# is no way to turn off a capability once it is turned on. You will have to +# disconnect and reconnect to these servers. This script will warn you when +# unloading the script of this situation. + +# +# Configuration: You can control the formating of the nickname with the +# format_identified_nick, format_unidentified_nick, and format_unknown_nick +# variables. The default is to do nothing to identified nicks and unknown +# nicks. while unidentified nicks have a ~ to the beginning of nick. An +# unknown nick means anytime a message or notice doesn't start with a + or -, +# which will occur when identify-msg isn't enabled. The format_unknown_nick +# can be really handy to alert you that you don't have identify-msg or +# identify-ctcp set, but is set by default to do nothing since most servers do +# not have identify-msg yet. In these variables $0 stands for the nick. You +# can use the standard formating codes or just text in it. See formats.txt for +# more information on the codes you can use. Warning about colors. Using +# colors in this formating will likely break other formating scripts and +# features, in particular the hilight feature of irssi or vice versa. Remember +# that %n has a different meaning here as explamined in the default.theme file +# that comes with irssi. +# +# Some examples: +# +# Make unidentified nicks have a ? after the nick: /set +# format_unidentified_nick $0? +# +# Make unidentified nicks red and identified nicks green: /set +# format_identified_nick %G$0 /set format_unidentified_nick %R$0 Note that the +# above will not do the tagging if a message gets hilighted. Since a hilight +# (line or nick) will override the colors. +# +# So I recommend doing something like this: /set format_identified_nick %G$0 +# /set format_unidentified_nick %R~$0 +# +# Make unidentified nicks be unmodified but add a * before identified nicks: +# /set format_identified_nick *$0 /set format_unidentified_nick $0 +# +# This script works by modifying the formats irssi uses to display various +# things. Therefore it is highly recommended that you do not change any of the +# following format variables except through this script: pubmsg pubmsg_channel +# msg_private msg_private_query pubmsg_hilight pubmsg_hilight_channel pubmsg_me +# pubmsg_me_channel action_private action_private_query action_public +# action_public_channel ctcp_requested ctcp_requested_unknown notice_public +# notice_private ctcp_reply ctcp_reply_channel ctcp_ping_reply + +# +# To change these formats you need to set the variable (with the set command +# not the format command as usual) of the same name as the format but with +# _identify on the end. This format has an additional special purpose +# "abstract" that is only used by this script and is parsed and replaced before +# setting the format and giving it to irssi. It is called format_identify. +# Any format you use with this script should have a {format_identify $0} in it +# to replace where the $0 usually is in the format. Sometimes it will be $1 +# for the nick in the format, in which case you should replace the $1 with +# {format_identify $1}. For more examples take a look at the defaults at the +# bottom of this script. +# +# +# If you wish to disable the module from applying a change to the nickname in a +# particular place the best way to do it is to simply remove the +# {format_identify $0} from the format that applies. E.G. to disable the +# format change for a CTCP reply one would do: /set ctcp_reply_identify CTCP +# {hilight $0} reply from {nick $1}: $2 +# + +# TODO +# * Implement DCC formats, which means figuring out which ones are appropriate +# to try and format. +# * Allow different formating on the nick for different types of messages. I'm +# not sure if this is useful... +# +# It should not be necessary to modify anything in this script. Everything +# should be able to be modified via the variables it exports as described +# above. +# + +my(@format_identify_message_formats) = qw(pubmsg pubmsg_channel msg_private + msg_private_query pubmsg_hilight + pubmsg_hilight_channel action_private + action_private_query action_public + action_public_channel ctcp_requested + ctcp_requested_unknown pubmsg_me + pubmsg_me_channel + ); + +my(@format_identify_notice_formats) = qw(notice_public notice_private ctcp_reply + ctcp_reply_channel ctcp_ping_reply); + + +my %servers; + +# Replace the {format_identify $0} place holder with +# whatever the user has setup for their nick formats... +sub replace_format_identify { + my ($format, $entry) = @_; + + my ($nickarg) = $format =~ /{\s*format_identify\s+?([^\s]+?)\s*}/; + $entry =~ s/\$0/$nickarg/; + $format =~ s/{\s*format_identify\s+?[^\s]+?\s*}/$entry/g; + return $format; +} + +# rewrite the message now that we've updated the formats +sub format_identify_rewrite { + my $signal = shift; + my $proc = shift; + + signal_stop(); + signal_remove($signal,$proc); + signal_emit($signal, @_); + signal_add($signal,$proc); +} + + +# Issue the format update after generating the new format. +sub update_format_identify { + my ($server,$entry,$nick) = @_; + + my $identify_format = settings_get_str("${entry}_identify"); + my $replaced_format = replace_format_identify($identify_format,$nick); + $server->command("^format $entry " . $replaced_format); +} + +my %saved_colors; +my %session_colors = {}; +my @colors = qw/2 3 4 5 6 7 9 10 11 12 13/; + +sub simple_hash { + my ($string) = @_; + chomp $string; + my @chars = split //, $string; + my $counter; + + foreach my $char (@chars) { + $counter += ord $char; + } + + $counter = $colors[($counter % @colors)]; + return $counter; +} + +sub colourise { + return if(!settings_get_bool('format_colour')); + my ($nick) = @_; + my $color = $saved_colors{$nick}; + if (!$color) { + $color = $session_colors{$nick}; + } + if (!$color) { + $color = simple_hash $nick; + $session_colors{$nick} = $color; + } + $color = "0".$color if ($color < 10); + return chr(3).$color; +} + + +# catches the signal for a message removes the + or -, updates the +# formats and then resends the message event. +sub format_identify_message { + my ($server, $data, $nick, $address) = @_; + my ($channel, $msg) = split(/ :/, $data,2); + + if (!$servers{$server->{'real_address'}}->{'IDENTIFY-CTCP'} && + !$servers{$server->{'real_address'}}->{'IDENTIFY-MSG'}) { + my $unknown_nick = settings_get_str('format_unknown_nick'); + foreach my $format (@format_identify_message_formats) { + update_format_identify($server,$format,colourise($nick).$unknown_nick); + } + } elsif(($msg =~ /^\+(.*)/)){ + my $newdata = "$channel :$1"; + my $identified_nick = settings_get_str('format_identified_nick'); + foreach my $format (@format_identify_message_formats) { + update_format_identify($server,$format,colourise($nick).$identified_nick); + } + format_identify_rewrite('event privmsg','format_identify_message', $server,$newdata,$nick,$address); + } elsif(($msg =~ /^-(.*)/)){ + my $newdata = "$channel :$1"; + my $unidentified_nick = settings_get_str('format_unidentified_nick'); + foreach my $format (@format_identify_message_formats) { + update_format_identify($server,$format,colourise($nick).$unidentified_nick); + } + format_identify_rewrite('event privmsg','format_identify_message', $server,$newdata,$nick,$address); + } else { + my $unknown_nick = settings_get_str('format_unknown_nick'); + foreach my $format (@format_identify_message_formats) { + update_format_identify($server,$format,colourise($nick).$unknown_nick); + } + } +} + +# catches the signal for a notice removes the + or -, updates the +# formats and resends the notice event. +sub format_identify_notice { + my ($server, $data, $nick, $address) = @_; + my ($channel, $msg) = split(/ :/, $data,2); + + if (!$servers{$server->{'real_address'}}->{'IDENTIFY-CTCP'} && + !$servers{$server->{'real_address'}}->{'IDENTIFY-MSG'}) { + my $unknown_nick = settings_get_str('format_unknown_nick'); + foreach my $format (@format_identify_notice_formats) { + update_format_identify($server,$format,colourise($nick).$unknown_nick); + } + } elsif(($msg =~ /^\+(.*)/)){ + my $newdata = "$channel :$1"; + my $identified_nick = settings_get_str('format_identified_nick'); + foreach my $format (@format_identify_notice_formats) { + update_format_identify($server,$format,colourise($nick).$identified_nick); + } + format_identify_rewrite('event notice','format_identify_notice', $server,$newdata,$nick,$address); + } elsif(($msg =~ /^-(.*)/)){ + my $newdata = "$channel :$1"; + my $unidentified_nick = settings_get_str('format_unidentified_nick'); + foreach my $format (@format_identify_notice_formats) { + update_format_identify($server,$format,colourise($nick).$unidentified_nick); + } + format_identify_rewrite('event notice','format_identify_notice', $server,$newdata,$nick,$address); + } else { + my $unknown_nick = settings_get_str('format_unknown_nick'); + foreach my $format (@format_identify_notice_formats) { + update_format_identify($server,$format,colourise($nick).$unknown_nick); + } + } +} + +# Handle CTCP messages. Note that messages tagged with identify-ctcp will +# not be seen as CTCPs and will go through event privmsg first. This script +# will generate new events and send them on through to here. However CTCPs +# that are not tagged at all will go here first. So we need to test here +# to see if the message is from a server that does not support identify-ctcp +# and update the format accordingly. +sub format_identify_ctcp_msg { + my ($server) = @_; + + if (!$servers{$server->{'real_address'}}->{'IDENTIFY-CTCP'}) { + my $unknown_nick = settings_get_str('format_unknown_nick'); + foreach my $format (@format_identify_message_formats) { + update_format_identify($server,$format,$unknown_nick); + } + } +} + +# Handle CTCP replies. Note that messages tagged with identify-ctcp will +# not be seen as CTCPs and will go through event notice first. This script +# will generate new events and send them on through to here. However CTCPs +# that are not tagged at all will go here first. So we need to test here +# to see if the message is from a server that does not support identify-ctcp +# and update the format accordingly. +sub format_identify_ctcp_reply { + my ($server) = @_; + + if (!$servers{$server->{'real_address'}}->{'IDENTIFY-CTCP'}) { + my $unknown_nick = settings_get_str('format_unknown_nick'); + foreach my $format (@format_identify_notice_formats) { + update_format_identify($server,$format,$unknown_nick); + } + } +} + +# If we're getting unloaded reset the formats back to their defaults +# so that it doesn't wrongly show people being unidentifed or vice versa. +# Also issue a warning about CTCPs etc being broken. +sub format_identify_unload { + my ($script,$server,$witem) = @_; + my @warning_servers = (); + + if ($script =~ /^format_identify(?:\.pl|\.perl)?$/) { + foreach my $format (@format_identify_message_formats, + @format_identify_notice_formats) { + $server->command("^format -reset $format"); + } + foreach my $server_name (keys %servers) { + if ( $servers{$server_name}->{'IDENTIFY-MSG'} + || $servers{$server_name}->{'IDENTIFY-CTCP'}) + { + if($servers{$server_name}->{'USES-CAP'}) { + $server->command("^quote cap req :-identify-msg"); + } else { + push @warning_servers, $server_name; + } + } + } + print('Warning: Unloading format_identify will leave your messages '. + 'and notices modified and will break CTCPs on the following '. + 'servers: ' . join (',',@warning_servers)); + } +} + +# Server responded to capab request. We want to capture the reply +# and mark it in a hash so we can keep track of which servers have +# the capabilities. This style of reply will come from dancer or +# hyperion. +sub format_identify_capab_reply { + my ($server, $data, $server_name) = @_; + unless (ref($servers{$server_name}) eq 'HASH') { + $servers{$server_name} = {}; + $servers{$server_name}->{'IDENTIFY-MSG'} = 0; + $servers{$server_name}->{'IDENTIFY-CTCP'} = 0; + $servers{$server_name}->{'USES-CAP'} = 0; + } + if ($data =~ /:IDENTIFY-MSG$/) { + $servers{$server_name}->{'IDENTIFY-MSG'} = 1; + $servers{$server_name}->{'USES-CAP'} = 0; + Irssi::signal_stop(); + return; + } + if ($data =~ /:IDENTIFY-CTCP$/) { + $servers{$server_name}->{'IDENTIFY-CTCP'} = 1; + $servers{$server_name}->{'USES-CAP'} = 0; + Irssi::signal_stop(); + return; + } +} + +# The same as above. This style of reply comes from ircd-seven. +sub format_identify_cap_reply { + my ($server, $data, $server_name) = @_; + unless (ref($servers{$server_name}) eq 'HASH') { + $servers{$server_name} = {}; + $servers{$server_name}->{'IDENTIFY-MSG'} = 0; + $servers{$server_name}->{'IDENTIFY-CTCP'} = 0; + $servers{$server_name}->{'USES-CAP'} = 0; + } + if ($data =~ /ACK :.*identify-msg/) { + $servers{$server_name}->{'IDENTIFY-MSG'} = 1; + $servers{$server_name}->{'IDENTIFY-CTCP'} = 1; + $servers{$server_name}->{'USES-CAP'} = 1; + return; + } +} + +# Handles connections to new (to this script) servers and +# attempts to turn on the capabilities it supports. +# We send the request in both formats, for hyperion and ircd-seven. +sub format_identify_connected { + my $server = shift; + $server->command("^quote capab IDENTIFY-MSG"); + $server->command("^quote capab IDENTIFY-CTCP"); + $server->command("^quote cap req :identify-msg"); +} + +# signals to handle the events we need to intercept. +signal_add('event privmsg', 'format_identify_message'); +signal_add('event notice', 'format_identify_notice'); +signal_add('ctcp msg', 'format_identify_ctcp_msg'); +signal_add('ctcp reply', 'format_identify_ctcp_reply'); +signal_add('event 290', 'format_identify_capab_reply'); +signal_add('event cap', 'format_identify_cap_reply'); +signal_add('event connected', 'format_identify_connected'); + +# On load enumerate the servers and try to turn on +# IDENTIFY-MSG and IDENTIFY-CTCP +foreach my $server (Irssi::servers()) { + %servers = (); + format_identify_connected($server); +} + +# signal needed to catch the unload... Be sure to be the first to +# get it too... +signal_add_first('command script unload', 'format_identify_unload'); + +settings_add_bool('format_identify', 'format_colour', 1); + +# How we format the nick. $0 is the nick we'll be formating. +settings_add_str('format_identify','format_identified_nick','$0'); +settings_add_str('format_identify','format_unidentified_nick','~$0'); +settings_add_str('format_identify','format_unknown_nick','$0'); + +# What we use for the formats... +# Don't modify here, use the /set command or modify in the ~/.irssi/config file. +settings_add_str('format_identify','pubmsg_identify','{pubmsgnick $2 {pubnick {format_identify $0}}}$1'); +settings_add_str('format_identify','pubmsg_channel_identify','{pubmsgnick $3 {pubnick {format_identify $0}}{msgchannel $1}}$2'); +settings_add_str('format_identify','msg_private_identify','{privmsg {format_identify $0} $1 }$2'); +settings_add_str('format_identify','msg_private_query_identify','{privmsgnick {format_identify $0}}$2'); +settings_add_str('format_identify','pubmsg_hilight_identify','{pubmsghinick {format_identify $0} $3 $1}$2'); +settings_add_str('format_identify','pubmsg_hilight_channel_identify','{pubmsghinick {format_identify $0} $4 $1{msgchannel $2}$3'); +settings_add_str('format_identify','action_private_identify','{pvtaction {format_identify $0}}$2'); +settings_add_str('format_identify','action_private_query_identify','{pvtaction_query {format_identify $0}}$2'); +settings_add_str('format_identify','action_public_identify','{pubaction {format_identify $0}}$1'); +settings_add_str('format_identify','action_public_channel_identify', '{pubaction {format_identify $0}{msgchannel $1}}$2'); +settings_add_str('format_identify','ctcp_requested_identify','{ctcp {hilight {format_identify $0}} {comment $1} requested CTCP {hilight $2} from {nick $4}}: $3'); +settings_add_str('format_identify','ctcp_requested_unknown_identify','{ctcp {hilight {format_identify $0}} {comment $1} requested unknown CTCP {hilight $2} from {nick $4}}: $3'); +settings_add_str('format_identify','pubmsg_me_identify','{pubmsgmenick $2 {menick {format_identify $0}}}$1'); +settings_add_str('format_identify','pubmsg_me_channel_identify','{pubmsgmenick $3 {menick {format_identify $0}}{msgchannel $1}}$2'); +settings_add_str('format_identify','notice_public_identify','{notice {format_identify $0}{pubnotice_channel $1}}$2'); +settings_add_str('format_identify','notice_private_identify','{notice {format_identify $0}{pvtnotice_host $1}}$2'); +settings_add_str('format_identify','ctcp_reply_identify','CTCP {hilight $0} reply from {nick {format_identify $1}}: $2'); +settings_add_str('format_identify','ctcp_reply_channel_identify','CTCP {hilight $0} reply from {nick {format_identify $1}} in channel {channel $3}: $2'); +settings_add_str('format_identify','ctcp_ping_reply_identify','CTCP {hilight PING} reply from {nick {format_identify $0}}: $1.$[-3.0]2 seconds'); |