]> git.vpit.fr Git - perl/scripts/xchat.git/blob - services.pl
Switch to qw<>
[perl/scripts/xchat.git] / services.pl
1 package Xchat::VPIT::Services;
2
3 use strict;
4 use warnings;
5
6 use Xchat qw<:all>;
7
8 use lib get_info 'xchatdir';
9 use Xchat::XPI;
10
11 our $VERSION = '0.03';
12
13 my $ph;
14
15 sub get_servers_ctxt {
16  my %s;
17  return map $_->{context},
18          grep !$s{$_->{server}}++,
19           sort { $a->{type} <=> $b->{type} }
20            get_list 'channels';
21 }
22
23 hook_command 'ID', sub {
24  return EAT_PLUGIN if $_[0][1];
25  my $passwd = get_info 'nickserv';
26  return EAT_ALL unless $passwd;
27  command 'ID ' . $passwd;
28  return EAT_ALL;
29 }, {
30  help_text => 'ID [password], identify you to NickServ'
31 };
32
33 hook_command 'AID', sub {
34  my $forcepasswd = $_[0][1];
35  my $oldctxt = get_context;
36  my @contexts = get_servers_ctxt;
37  for (@contexts) {
38   set_context $_;
39   my $passwd = $forcepasswd || get_info 'nickserv';
40   next unless $passwd;
41   command 'ID ' . $passwd;
42  }
43  set_context $oldctxt;
44  return EAT_ALL;
45 }, {
46  help_text => 'AID [password], identify you on all servers'
47 };
48
49 hook_command 'GHOST', sub {
50  return EAT_PLUGIN if $_[0][2];
51  my $target = $_[0][1] || get_prefs 'irc_nick1';
52  my $passwd = get_info 'nickserv';
53  return EAT_ALL unless $target && $passwd;
54  if (nickcmp(get_info('nick'), $target)) {
55   command join ' ', 'GHOST', $target, $passwd;
56  }
57  return EAT_ALL;
58 }, {
59  help_text => 'GHOST [nick] [password], kill the client currently connected with your nickname'
60 };
61
62 hook_command 'AGHOST', sub {
63  my $target = $_[0][1] || get_prefs 'irc_nick1';
64  return EAT_ALL unless $target;
65  my $forcepasswd = $_[0][2];
66  my $oldctxt = get_context;
67  my @contexts = get_servers_ctxt;
68  for (@contexts) {
69   set_context $_;
70   my $passwd = $forcepasswd || get_info 'nickserv';
71   next unless $passwd;
72   if (nickcmp(get_info('nick'), $target)) {
73    command join ' ', 'GHOST', $target, $passwd;
74   }
75  }
76  set_context $oldctxt;
77  return EAT_ALL;
78 }, {
79  help_text => 'AGHOST [nick] [password], kill usurping clients on all servers'
80 };
81
82 sub csmode {
83  my $cmd = join ' ', 'QUOTE CHANSERV', $_[2], get_info('channel');
84  my @targets = @{$_[0]};
85  shift @targets;
86  @targets = (get_info 'nick') unless @targets;
87  command join ' ', $cmd, $_ for @targets;
88  return EAT_ALL;
89 }
90
91 hook_command "C$_", \&csmode, {
92  data => $_,
93  help_text => join ' ', $_, '[nicks] ,', (lc $_),
94     'the specified targets (or you if none) on the current channel via ChanServ'
95 } for map { $_, "DE$_" } qw<VOICE HALFOP OP PROTECT>;
96
97 $ph = Xchat::XPI->new(
98  name   => 'IRC Services',
99  tag    => 'Services',
100  desc   => 'Various IRC services helpers',
101  author => 'Vincent Pit (VPIT)',
102  email  => 'perl@profvince.com',
103  url    => 'http://www.profvince.com',
104 );
105
106 1;