]> ruin.nu Git - NDIRC.git/blob - Commands/Channel.pm
Converted the invite command, turning it into a real command
[NDIRC.git] / Commands / Channel.pm
1 #**************************************************************************
2 #   Copyright (C) 2008 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
4 #   This program is free software; you can redistribute it and/or modify  *
5 #   it under the terms of the GNU General Public License as published by  *
6 #   the Free Software Foundation; either version 2 of the License, or     *
7 #   (at your option) any later version.                                   *
8 #                                                                         *
9 #   This program is distributed in the hope that it will be useful,       *
10 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 #   GNU General Public License for more details.                          *
13 #                                                                         *
14 #   You should have received a copy of the GNU General Public License     *
15 #   along with this program; if not, write to the                         *
16 #   Free Software Foundation, Inc.,                                       *
17 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18 #**************************************************************************/
19
20 package NDIRC::Commands::Channel;
21
22 use strict;
23 use warnings;
24 use feature ':5.10';
25
26 use Moose;
27 use MooseX::MethodAttributes;
28
29 sub op
30         : Alias(qw/deop voice devoice/)
31         : Help(syntax: .op [nicks] | Gives op to the specified nicks, or yourself if no command is given)
32         : Type(channel)
33 {
34         my ($self,$c,$msg) = @_;
35
36         my ($access) = $self->name =~ /(op|voice)/;
37
38         my $where = "";
39         if ($msg =~ /^\s*$/){
40                 $msg = $c->nick;
41                 $where = "OR f.name = 'auto_$access'";
42         }
43
44         my $mode = qq{
45 SELECT DISTINCT c.name FROM users u
46         JOIN groupmembers g ON g.uid = u.uid
47         JOIN channel_group_flags gf ON g.gid = gf.group
48         JOIN channels c ON gf.channel = c.id
49         JOIN channel_flags f ON f.id = gf.flag
50 WHERE u.hostmask ILIKE ? AND c.name = ? AND (f.name = '$access' $where);
51                 };
52         if ($c->check_user_roles(qw/irc_masterop/)){
53                 $mode = 1;
54         }else{
55                 ($mode) = $c->model->selectrow_array($mode,undef,$c->host,$c->channel);
56         }
57         if ($mode){
58                 $c->server->command($self->name . " " . $c->channel . " $msg");
59         }else{
60                 $c->reply("No access to " . $self->name . " in this channel");
61         }
62 }
63
64 sub invite
65         :Help(Syntax: invite [channel] | If no channel is specified it invites you to all channel you have auto invite access on)
66         : Type(pm)
67 {
68         my ($self,$c,$msg) = @_;
69
70         my ($channel) = $msg =~ /^\s*(\S+)?\s*$/ or die 'ARGS';
71
72         my @channels;
73         if ($channel && $c->check_user_roles('irc_masterinvite')){
74                 print "master $channel";
75                 push @channels,$channel;
76         }else{
77                 print "master $channel";
78                 my @access = ('auto_invite');
79                 push @access, 'invite' if $channel;
80                 my $channels = $c->model->prepare(q{
81 SELECT DISTINCT c.name FROM users u
82         JOIN groupmembers g ON g.uid = u.uid
83         JOIN channel_group_flags gf ON g.gid = gf.group
84         JOIN channels c ON gf.channel = c.id
85         JOIN channel_flags f ON f.id = gf.flag
86 WHERE u.hostmask ILIKE $1 AND COALESCE(c.name = $2,TRUE)
87         AND (f.name = ANY($3) )
88                 });
89                 $channels->execute($c->host,$channel,\@access);
90                 while (my ($channel) = $channels->fetchrow()){
91                         push @channels,$channel;
92                 }
93         }
94         for (@channels){
95                 print;
96                 $c->server->command("invite ". $c->nick ." $_");
97         }
98 }
99
100 1;