mirror of
https://github.com/irssi/irssi.git
synced 2024-11-03 04:27:19 -05:00
new scripts
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2571 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
0b7ebb6adb
commit
02c9b7d1cf
@ -8,8 +8,10 @@ script_DATA = \
|
||||
buf.pl \
|
||||
dns.pl \
|
||||
kills.pl \
|
||||
mail.pl \
|
||||
mlock.pl \
|
||||
quitmsg.pl \
|
||||
splitlong.pl
|
||||
splitlong.pl \
|
||||
usercount.pl
|
||||
|
||||
EXTRA_DIST = $(script_DATA)
|
||||
|
133
scripts/mail.pl
Normal file
133
scripts/mail.pl
Normal file
@ -0,0 +1,133 @@
|
||||
# $Id: mail.pl,v 1.1 2002/03/10 21:33:46 cras Exp $
|
||||
|
||||
$VERSION = "2.0";
|
||||
%IRSSI = (
|
||||
authors => "Matti Hiljanen, Timo Sirainen",
|
||||
contact => "matti\@hiljanen.com, tss\@iki.fi",
|
||||
name => "mail",
|
||||
description => "Mail counter statusbar item with maildir support",
|
||||
license => "Public Domain",
|
||||
url => "http://matin.maapallo.org/softa/irssi, http://irssi.org, http://scripts.irssi.de",
|
||||
);
|
||||
|
||||
# Mail counter statusbar item
|
||||
# for irssi 0.8.1 by Timo Sirainen
|
||||
#
|
||||
# Maildir support added by Matti Hiljanen
|
||||
#
|
||||
# /SET maildir_mode - ON/OFF
|
||||
# /SET mail_file - specifies mbox file/Maildir location
|
||||
# /SET mail_refresh_time - in seconds, how often to check for new mail
|
||||
# /SET mail_ext_program - specify external mail checker program
|
||||
|
||||
use Irssi::TextUI;
|
||||
|
||||
my $maildirmode = 0; # maildir=1, file(spools)=0
|
||||
my $extprog;
|
||||
my ($last_refresh_time, $refresh_tag);
|
||||
|
||||
# for mbox caching
|
||||
my $last_size, $last_mtime, $last_mailcount, $last_mode;
|
||||
|
||||
sub mbox_count {
|
||||
my $mailfile = shift;
|
||||
my $count = 0;
|
||||
my $maildirmode=Irssi::settings_get_bool('maildir_mode');
|
||||
if ($extprog ne "") {
|
||||
$count = `$extprog`;
|
||||
chomp $count;
|
||||
} else {
|
||||
if (!$maildirmode) {
|
||||
if (-f $mailfile) {
|
||||
my @stat = stat($mailfile);
|
||||
my $size = $stat[7];
|
||||
my $mtime = $stat[9];
|
||||
|
||||
# if the file hasn't changed, get the count from cache
|
||||
return $last_mailcount if ($last_size == $size && $last_mtime == $mtime);
|
||||
$last_size = $size;
|
||||
$last_mtime = $mtime;
|
||||
|
||||
my $f = gensym;
|
||||
return 0 if (!open($f, $mailfile));
|
||||
|
||||
while (<$f>) {
|
||||
$count++ if (/^From /);
|
||||
$count-- if (/^Subject: .*FOLDER INTERNAL DATA/);
|
||||
}
|
||||
close($f);
|
||||
$last_mailcount = $count;
|
||||
}
|
||||
} else {
|
||||
opendir(DIR, "$mailfile/cur") or return 0;
|
||||
while (defined(my $file = readdir(DIR))) {
|
||||
next if $file =~ /S/ || $file =~ /^(.|..)$/;
|
||||
$count++;
|
||||
}
|
||||
closedir(DIR);
|
||||
|
||||
opendir(DIR, "$mailfile/new") or return 0;
|
||||
while (defined(my $file = readdir(DIR))) {
|
||||
next if $file =~ /^(.|..)$/;
|
||||
$count++;
|
||||
}
|
||||
closedir(DIR);
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
sub mail {
|
||||
my ($item, $get_size_only) = @_;
|
||||
|
||||
$count = mbox_count(Irssi::settings_get_str('mail_file'));
|
||||
if ($count == 0) {
|
||||
# no mail - don't print the [Mail: ] at all
|
||||
if ($get_size_only) {
|
||||
$item->{min_size} = $item->{max_size} = 0;
|
||||
}
|
||||
} else {
|
||||
$item->default_handler($get_size_only, undef, $count, 1);
|
||||
}
|
||||
}
|
||||
|
||||
sub refresh_mail {
|
||||
Irssi::statusbar_items_redraw('mail');
|
||||
}
|
||||
|
||||
sub read_settings {
|
||||
$extprog = Irssi::settings_get_str('mail_ext_program');
|
||||
my $time = Irssi::settings_get_int('mail_refresh_time');
|
||||
my $mode = Irssi::settings_get_bool('maildir_mode');
|
||||
unless ($time == $last_refresh_time) {
|
||||
$last_refresh_time = $time;
|
||||
Irssi::timeout_remove($refresh_tag) if ($refresh_tag);
|
||||
$refresh_tag = Irssi::timeout_add($time*1000, 'refresh_mail', undef);
|
||||
}
|
||||
return if ($mode == $last_mode);
|
||||
$last_mode = $mode;
|
||||
if (!$mode) {
|
||||
Irssi::settings_set_str('mail_file', "$ENV{'MAIL'}");
|
||||
} else {
|
||||
Irssi::settings_set_str('mail_file', "$ENV{'HOME'}/Maildir");
|
||||
}
|
||||
refresh_mail;
|
||||
}
|
||||
|
||||
if (!$maildirmode) {
|
||||
Irssi::settings_add_str('misc', 'mail_file', $ENV{'MAIL'});
|
||||
} else {
|
||||
Irssi::settings_add_str('misc', 'mail_file', "$ENV{'HOME'}/Maildir");
|
||||
}
|
||||
|
||||
Irssi::settings_add_str('misc', 'mail_ext_program', '');
|
||||
Irssi::settings_add_int('misc', 'mail_refresh_time', 60);
|
||||
Irssi::settings_add_bool('misc', 'maildir_mode', "$maildirmode");
|
||||
|
||||
Irssi::statusbar_item_register('mail', '{sb Mail: $0-}', 'mail');
|
||||
|
||||
read_settings();
|
||||
Irssi::signal_add('setup changed', 'read_settings');
|
||||
refresh_mail();
|
||||
|
||||
# EOF
|
160
scripts/usercount.pl
Normal file
160
scripts/usercount.pl
Normal file
@ -0,0 +1,160 @@
|
||||
use Irssi 20020101.0250 ();
|
||||
$VERSION = "1.14";
|
||||
%IRSSI = (
|
||||
authors => 'David Leadbeater, Timo Sirainen, Georg Lukas',
|
||||
contact => 'dgl@dgl.cx, tss@iki.fi, georg@boerde.de',
|
||||
name => 'usercount',
|
||||
description => 'Adds a usercount for a channel as a status bar item',
|
||||
license => 'GNU GPLv2 or later',
|
||||
url => 'http://irssi.dgl.yi.org/',
|
||||
);
|
||||
|
||||
# Add usercount = { }; to your statusbar config
|
||||
# /set usercount_show_zero on or off to show users when 0 users of that type
|
||||
# /set usercount_show_ircops (default off)
|
||||
# /set usercount_show_halfops (default on)
|
||||
|
||||
# you can customize the look of this item from theme file:
|
||||
# sb_usercount = "{sb %_$0%_ nicks ($1-)}";
|
||||
# sb_uc_ircops = "%_*%_$*";
|
||||
# sb_uc_ops = "%_@%_$*";
|
||||
# sb_uc_halfops = "%_%%%_$*";
|
||||
# sb_uc_voices = "%_+%_$*";
|
||||
# sb_uc_normal = "$*";
|
||||
# sb_uc_space = " ";
|
||||
|
||||
|
||||
use strict;
|
||||
use Irssi::TextUI;
|
||||
|
||||
my ($ircops, $ops, $halfops, $voices, $normal, $total);
|
||||
my ($timeout_tag, $recalc);
|
||||
|
||||
# Called to make the status bar item
|
||||
sub usercount {
|
||||
my ($item, $get_size_only) = @_;
|
||||
my $wi = !Irssi::active_win() ? undef : Irssi::active_win()->{active};
|
||||
|
||||
if(!$wi || $wi->{type} ne "CHANNEL") { # only works on channels
|
||||
$item->{min_size} = $item->{max_size} = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($recalc) {
|
||||
$recalc = 0;
|
||||
calc_users($wi);
|
||||
}
|
||||
|
||||
my $theme = Irssi::current_theme();
|
||||
my $format = $theme->format_expand("{sb_usercount}");
|
||||
if ($format) {
|
||||
# use theme-specific look
|
||||
my $ircopstr = $theme->format_expand("{sb_uc_ircops $ircops}", Irssi::EXPAND_FLAG_IGNORE_EMPTY);
|
||||
my $opstr = $theme->format_expand("{sb_uc_ops $ops}", Irssi::EXPAND_FLAG_IGNORE_EMPTY);
|
||||
my $halfopstr = $theme->format_expand("{sb_uc_halfops $halfops}", Irssi::EXPAND_FLAG_IGNORE_EMPTY);
|
||||
my $voicestr = $theme->format_expand("{sb_uc_voices $voices}", Irssi::EXPAND_FLAG_IGNORE_EMPTY);
|
||||
my $normalstr = $theme->format_expand("{sb_uc_normal $normal}", Irssi::EXPAND_FLAG_IGNORE_EMPTY);
|
||||
my $space = $theme->format_expand('{sb_uc_space}', Irssi::EXPAND_FLAG_IGNORE_EMPTY);
|
||||
$space = " " unless $space;
|
||||
|
||||
my $str = "";
|
||||
$str .= $ircopstr.$space if defined $ircops;
|
||||
$str .= $opstr.$space if defined $ops;
|
||||
$str .= $halfopstr.$space if defined $halfops;
|
||||
$str .= $voicestr.$space if defined $voices;
|
||||
$str .= $normalstr.$space if defined $normal;
|
||||
$str =~ s/\Q$space\E$//;
|
||||
|
||||
$format = $theme->format_expand("{sb_usercount $total $str}",
|
||||
Irssi::EXPAND_FLAG_IGNORE_REPLACES);
|
||||
} else {
|
||||
# use the default look
|
||||
$format = "{sb \%_$total\%_ nicks \%c(\%n";
|
||||
$format .= '*'.$ircops.' ' if (defined $ircops);
|
||||
$format .= '@'.$ops.' ' if (defined $ops);
|
||||
$format .= '%%'.$halfops.' ' if (defined $halfops);
|
||||
$format .= "+$voices " if (defined $voices);
|
||||
$format .= "$normal " if (defined $normal);
|
||||
$format =~ s/ $//;
|
||||
$format .= "\%c)}";
|
||||
}
|
||||
|
||||
$item->default_handler($get_size_only, $format, undef, 1);
|
||||
}
|
||||
|
||||
sub calc_users() {
|
||||
my $channel = shift;
|
||||
my $server = $channel->{server};
|
||||
|
||||
$ircops = $ops = $halfops = $voices = $normal = 0;
|
||||
for ($channel->nicks()) {
|
||||
if ($_->{serverop}) {
|
||||
$ircops++;
|
||||
}
|
||||
|
||||
if ($_->{op}) {
|
||||
$ops++;
|
||||
} elsif ($_->{halfop}) {
|
||||
$halfops++;
|
||||
} elsif ($_->{voice}) {
|
||||
$voices++;
|
||||
} else {
|
||||
$normal++;
|
||||
}
|
||||
}
|
||||
|
||||
$total = $ops+$halfops+$voices+$normal;
|
||||
if (!Irssi::settings_get_bool('usercount_show_zero')) {
|
||||
$ircops = undef if ($ircops == 0);
|
||||
$ops = undef if ($ops == 0);
|
||||
$halfops = undef if ($halfops == 0);
|
||||
$voices = undef if ($voices == 0);
|
||||
$normal = undef if ($normal == 0);
|
||||
}
|
||||
$halfops = undef unless Irssi::settings_get_bool('usercount_show_halfops');
|
||||
$ircops = undef unless Irssi::settings_get_bool('usercount_show_ircops');
|
||||
}
|
||||
|
||||
sub refresh {
|
||||
if ($timeout_tag > 0) {
|
||||
Irssi::timeout_remove($timeout_tag);
|
||||
$timeout_tag = 0;
|
||||
}
|
||||
Irssi::statusbar_items_redraw('usercount');
|
||||
}
|
||||
|
||||
sub refresh_check {
|
||||
my $channel = shift;
|
||||
my $wi = Irssi::active_win()->{active};
|
||||
return if $wi->{name} ne $channel->{name};
|
||||
return if $wi->{server}->{tag} ne $channel->{server}->{tag};
|
||||
|
||||
# don't refresh immediately, or we'll end up refreshing
|
||||
# a lot around netsplits
|
||||
$recalc = 1;
|
||||
Irssi::timeout_remove($timeout_tag) if ($timeout_tag > 0);
|
||||
$timeout_tag = Irssi::timeout_add(500, 'refresh', undef);
|
||||
}
|
||||
|
||||
sub refresh_recalc {
|
||||
$recalc = 1;
|
||||
refresh();
|
||||
}
|
||||
|
||||
$recalc = 1;
|
||||
$timeout_tag = 0;
|
||||
|
||||
Irssi::settings_add_bool('misc', 'usercount_show_zero', 1);
|
||||
Irssi::settings_add_bool('misc', 'usercount_show_ircops', 0);
|
||||
Irssi::settings_add_bool('misc', 'usercount_show_halfops', 1);
|
||||
|
||||
Irssi::statusbar_item_register('usercount', undef, 'usercount');
|
||||
Irssi::statusbars_recreate_items();
|
||||
|
||||
Irssi::signal_add_last('nicklist new', 'refresh_check');
|
||||
Irssi::signal_add_last('nicklist remove', 'refresh_check');
|
||||
Irssi::signal_add_last('nick mode changed', 'refresh_check');
|
||||
Irssi::signal_add_last('setup changed', 'refresh_recalc');
|
||||
Irssi::signal_add_last('window changed', 'refresh_recalc');
|
||||
Irssi::signal_add_last('window item changed', 'refresh_recalc');
|
||||
|
Loading…
Reference in New Issue
Block a user