1# by Uwe 'duden' Dudenhoeffer
2#
3# chansync.pl
4
5
6use strict;
7
8use vars qw($VERSION %IRSSI);
9$VERSION = '0.22';
10%IRSSI = (
11    authors     => 'Uwe \'duden\' Dudenhoeffer',
12    contact     => 'script@duden.eu.org',
13    name        => 'chansync',
14    description => '/who a channel and optionaly executes a command',
15    license     => 'GPLv2',
16    url         => '',
17    changed     => 'Sun Feb  9 18:27:51 CET 2003',
18    commands	=> 'chansync',
19);
20
21# Changelog
22#
23# 0.22
24#   - added "commands => chansync"
25#
26# 0.21
27#   - some design issues
28#
29# 0.2
30#   - used "silent event who" instead of stopping "print text"
31#
32# 0.1
33#   - first working version
34
35use Irssi 20020324;
36use POSIX;
37
38my(%arguments,%items);
39
40# Usage: /chansync [command]
41sub cmd_chansync {
42  my($args, $server, $item) = @_;
43  return if not ($item && $item->{type} eq "CHANNEL");
44  my($chan) = $item->{name};
45  $server->redirect_event('who', 1, $chan, -1, undef,
46                         {
47                          "event 315" => "redir chansync endwho",
48                          "event 352" => "redir chansync who",
49                          "" => "event empty",
50                         });
51  $server->send_raw("WHO $chan");
52  $arguments{lc $chan} = $args;
53  $items{lc $chan} = $item;
54}
55
56sub sig_event_block {
57  Irssi::signal_stop();
58}
59
60sub sig_redir_chansync_who {
61  Irssi::signal_emit('silent event who', @_);
62}
63
64sub sig_redir_chansync_endwho {
65  my($server) = shift;
66  my(@text) = split " ", shift;
67  my($cmd) = $arguments{lc @text[1]};
68  $items{lc @text[1]}->command("$cmd");
69  delete $arguments{lc @text[1]};
70  delete $items{lc @text[1]};
71}
72
73Irssi::command_bind("chansync", "cmd_chansync");
74Irssi::signal_add('redir chansync who', 'sig_redir_chansync_who');
75Irssi::signal_add('redir chansync endwho', 'sig_redir_chansync_endwho');
76