1#!/usr/local/bin/perl -w 2 3## Bugreports and Licence disclaimer. 4# 5# For bugreports and other improvements contact Geert Hauwaerts <geert@hauwaerts.be> 6# 7# This program is free software; you can redistribute it and/or modify it 8# under the terms of the GNU General Public License as published by the Free 9# Software Foundation; either version 2 of the License, or (at your option) 10# any later version. 11# 12# This program is distributed in the hope that it will be useful, but WITHOUT 13# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15# more details. 16# 17# You should have received a copy of the GNU General Public License along with 18# this script; if not, write to the Free Software Foundation, Inc., 59 Temple 19# Place, Suite 330, Boston, MA 02111-1307 USA. 20## 21 22 23## Documentation. 24# 25# Versioning: 26# 27# This script uses the YEAR.FEATURE.REVISION versioning scheme and must abide 28# by the follwing rules: 29# 30# 1) when adding a new feature, you must increase the FEATURE 31# numeric by one; 32# 33# 2) when fixing a bug, you must increase the REVISION numeric 34# by one; and 35# 36# 3) the first feature or bug change in any given year must set the YEAR 37# numeric to the two digit representation of the current year, and 38# reset the FEATURE and REVISION numerics to 01. 39# 40# Settings: 41# 42# away_hilight_notice_timeout 43# 44# The default time between notices sent to the same person are 3600 45# seconds or once an hour. 46# 47# away_hilight_notice_filter 48# 49# A list of channels, separated by space, on which the script will be 50# disabled. 51## 52 53 54## 55# Load the required libraries. 56## 57 58use strict; 59use Irssi; 60use vars qw($VERSION %IRSSI); 61 62 63## 64# Declare the administrative information. 65## 66 67$VERSION = '15.01.01'; 68 69%IRSSI = ( 70 authors => 'Geert Hauwaerts', 71 contact => 'geert@hauwaerts.be', 72 name => 'away_hilight_notice.pl', 73 description => 'This script will notice your away message in response to a hilight.', 74 license => 'GNU General Public License', 75 url => 'https://github.com/GeertHauwaerts/irssi-scripts/blob/master/src/away_hilight_notice.pl', 76 changed => 'Thu Jun 25 20:46:51 UTC 2015', 77); 78 79 80## 81# Register the custom theme formats. 82## 83 84Irssi::theme_register([ 85 'away_hilight_notice_loaded', '%R>>%n %_Scriptinfo:%_ Loaded $0 version $1 by $2.', 86]); 87 88 89## 90# Declare the script variables. 91## 92 93my %lasthilight; 94 95 96## Function. 97# 98# Irssi::away_hilight_notice::away_hilight_notice() function. 99# 100# Function: away_hilight_notice() 101# Arguments: The destination. 102# The text. 103# The stripped text. 104# 105# Description: Sends a notice with your away message. 106## 107 108sub away_hilight_notice { 109 110 111 ## 112 # Parse the parameters. 113 ## 114 115 my ($dest, $text, $stripped) = @_; 116 my $server = $dest->{'server'}; 117 my $hilight = Irssi::parse_special('$;'); 118 119 120 ## 121 # Check whether the message is irrelevant. 122 ## 123 124 if (!$server || !($dest->{'level'} & MSGLEVEL_HILIGHT) || ($dest->{'level'} & (MSGLEVEL_MSGS|MSGLEVEL_NOTICES|MSGLEVEL_SNOTES|MSGLEVEL_CTCPS|MSGLEVEL_ACTIONS|MSGLEVEL_JOINS|MSGLEVEL_PARTS|MSGLEVEL_QUITS|MSGLEVEL_KICKS|MSGLEVEL_MODES|MSGLEVEL_TOPICS|MSGLEVEL_WALLOPS|MSGLEVEL_INVITES|MSGLEVEL_NICKS|MSGLEVEL_DCC|MSGLEVEL_DCCMSGS|MSGLEVEL_CLIENTNOTICE|MSGLEVEL_CLIENTERROR))) { 125 return; 126 } 127 128 129 ## 130 # Check whether we are marked as away. 131 ## 132 133 if ($server->{'usermode_away'}) { 134 135 136 ## 137 # Loop through each entry in the filter. 138 ## 139 140 foreach (split /\s+/, Irssi::settings_get_str('away_hilight_notice_filter')) { 141 142 143 ## 144 # Check if the target is filtered. 145 ## 146 147 if (lc($dest->{'target'}) eq lc($_)) { 148 return; 149 } 150 } 151 152 153 ## 154 # Check whether we need to send a notice. 155 ## 156 157 if (!$lasthilight{lc($hilight)}{'last'} || ($lasthilight{lc($hilight)}{'last'} && ((time() - $lasthilight{lc($hilight)}{'last'}) > Irssi::settings_get_int('away_hilight_notice_timeout')))) { 158 $lasthilight{lc($hilight)}{'last'} = time(); 159 $server->command('^NOTICE ' . $hilight . ' I\'m away (' . $server->{'away_reason'} . ')'); 160 } 161 } 162} 163 164 165## Function. 166# 167# Irssi::away_hilight_notice::clear_associative_array() function. 168# 169# Function: clear_associative_array() 170# Arguments: The server. 171# 172# Description: Remove the timers from the memory. 173## 174 175sub clear_associative_array { 176 177 178 ## 179 # Parse the parameters. 180 ## 181 182 my ($server) = @_; 183 184 185 ## 186 # Check whether we are marked as active. 187 ## 188 189 if (!$server->{'usermode_away'}) { 190 %lasthilight = (); 191 } 192} 193 194 195## 196# Register the signals to hook on. 197## 198 199Irssi::signal_add('print text', 'away_hilight_notice'); 200Irssi::signal_add('away mode changed', 'clear_associative_array'); 201 202 203## 204# Register the custom settings. 205## 206 207Irssi::settings_add_int('away', 'away_hilight_notice_timeout', 3600); 208Irssi::settings_add_str('away', 'away_hilight_notice_filter', '#bitlbee #twitter'); 209 210 211## 212# Display the script banner. 213## 214 215Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'away_hilight_notice_loaded', $IRSSI{name}, $VERSION, $IRSSI{authors});