X-Git-Url: https://ruin.nu/git/?p=NDIRC.git;a=blobdiff_plain;f=Commands%2FChannel.pm;h=2206072bcc1c14af56bcdb882f5b623020eb4c9c;hp=117817e09bc4792b55ecb238fb62ee60e5503ac4;hb=57134323940284d9e14e7a2860e5dae0a551c938;hpb=7630b437c2612d3c98dcd3aac8d0600cbed60697 diff --git a/Commands/Channel.pm b/Commands/Channel.pm index 117817e..2206072 100644 --- a/Commands/Channel.pm +++ b/Commands/Channel.pm @@ -1,5 +1,5 @@ #************************************************************************** -# Copyright (C) 2008 by Michael Andreen * +# Copyright (C) 2009 by Michael Andreen * # * # This program is free software; you can redistribute it and/or modify * # it under the terms of the GNU General Public License as published by * @@ -17,84 +17,101 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * #**************************************************************************/ -package NDIRC::Commands::Channel; - use strict; use warnings; use feature ':5.10'; -use Moose; -use MooseX::MethodAttributes; - -sub op - : Alias(qw/deop voice devoice/) - : Help(syntax: .op [nicks] | Gives op to the specified nicks, or yourself if no command is given) - : Type(channel) -{ - my ($self,$c,$msg) = @_; +use MooseX::Declare; +use NDIRC::Dispatcher; - my ($access) = $self->name =~ /(op|voice)/; +my $access = class extends NDIRC::Command { + method execute ($c,$msg) { + $self->name =~ /(de)?(op|voice)/; + my @access = ($2); + my $mod = $1 ? '-' : ''; - my $where = ""; - if ($msg =~ /^\s*$/){ - $msg = $c->nick; - $where = "OR f.name = 'auto_$access'"; - } + if ($msg =~ /^\s*$/){ + $msg = $c->nick; + push @access, "auto_$access[0]"; + } - my $mode = qq{ -SELECT DISTINCT c.name FROM users u - JOIN groupmembers g ON g.uid = u.uid - JOIN channel_group_flags gf ON g.gid = gf.group - JOIN channels c ON gf.channel = c.id - JOIN channel_flags f ON f.id = gf.flag -WHERE u.hostmask ILIKE ? AND c.name = ? AND (f.name = '$access' $where); + my $mode = q{ +SELECT DISTINCT LOWER(flag) FROM users u + JOIN groupmembers g USING (uid) + JOIN channel_group_flags gf USING (gid) + JOIN channel_flags f USING (flag) +WHERE uid = $1 AND channel = $2 AND f.name = ANY($3); }; - if ($c->check_user_roles(qw/irc_masterop/)){ - $mode = 1; - }else{ - ($mode) = $c->model->selectrow_array($mode,undef,$c->host,$c->channel); - } - if ($mode){ - $c->server->command($self->name . " " . $c->channel . " $msg"); - }else{ - $c->reply("No access to " . $self->name . " in this channel"); + if ($c->check_user_roles(qw/irc_masterop/)){ + $mode = substr $access[0], 0,1; + }else{ + ($mode) = $c->model->selectrow_array($mode,undef,$c->uid,$c->channel,\@access); + } + if ($mode){ + $c->command(mode => $c->channel, "$mod$mode", $msg); + }else{ + $c->reply("No access to " . $self->name . " in this channel"); + } } -} +}; + +command op => { + help => q(syntax: .op [nicks] | Gives op to the specified nicks, or yourself if no command is given), + type => q(channel), +}, $access; + +command deop => { + help => q(syntax: .deop [nicks] | Removes op from the specified nicks, or yourself if no command is given), + type => q(channel), +}, $access; -sub invite - :Help(Syntax: invite [channel] | If no channel is specified it invites you to all channel you have auto invite access on) - : Type(pm) -{ - my ($self,$c,$msg) = @_; +command voice => { + help => q(syntax: .voice [nicks] | Gives voice to the specified nicks, or yourself if no command is given), + type => q(channel), +}, $access; - my ($channel) = $msg =~ /^\s*(\S+)?\s*$/ or die 'ARGS'; +command devoice => { + help => q(syntax: .voice [nicks] | Removes voice from the specified nicks, or yourself if no command is given), + type => q(channel), +}, $access; - my @channels; - if ($channel && $c->check_user_roles('irc_masterinvite')){ - print "master $channel"; - push @channels,$channel; - }else{ - print "master $channel"; - my @access = ('auto_invite'); - push @access, 'invite' if $channel; - my $channels = $c->model->prepare(q{ -SELECT DISTINCT c.name FROM users u - JOIN groupmembers g ON g.uid = u.uid - JOIN channel_group_flags gf ON g.gid = gf.group - JOIN channels c ON gf.channel = c.id - JOIN channel_flags f ON f.id = gf.flag -WHERE u.hostmask ILIKE $1 AND COALESCE(c.name = $2,TRUE) - AND (f.name = ANY($3) ) - }); - $channels->execute($c->host,$channel,\@access); - while (my ($channel) = $channels->fetchrow()){ +command invite => { + help => q(Syntax: invite [channel] | If no channel is specified it invites you to all channel you have auto invite access on), + type => q(pm) +}, class extends NDIRC::Command { + method execute ($c,$msg) { + my ($channel) = $msg =~ /^\s*(\S+)?\s*$/ or die 'ARGS'; + + my @channels; + if ($channel && $c->check_user_roles('irc_masterinvite')){ push @channels,$channel; + }else{ + my @access = ('i'); + push @access, 'I' if $channel; + my $channels = $c->model->prepare(q{ +SELECT DISTINCT channel FROM users u + JOIN groupmembers g USING (uid) + JOIN channel_group_flags gf USING (gid) +WHERE uid = $1 AND COALESCE(channel = $2,TRUE) + AND (flag = ANY($3) ) + }); + $channels->execute($c->uid,$channel,\@access); + while (my ($channel) = $channels->fetchrow()){ + push @channels,$channel; + } + } + for (@channels){ + $c->command(invite => $c->nick, $_); } } - for (@channels){ - print; - $c->server->command("invite ". $c->nick ." $_"); +}; + +command hostname => { + help => q(Shows your hostname, as seen by the bots.) +}, class extends NDIRC::Command { + method execute ($c,$msg) { + $c->reply('Your hostname is: '.$c->host); } -} +}; 1;