]> ruin.nu Git - NDIRC.git/commitdiff
Converted .op, .deop, .voice and .devoice
authorMichael Andreen <harv@ruin.nu>
Sat, 9 May 2009 13:34:51 +0000 (15:34 +0200)
committerMichael Andreen <harv@ruin.nu>
Sat, 9 May 2009 13:35:51 +0000 (15:35 +0200)
Channel.pm [deleted file]
Commands/Channel.pm [new file with mode: 0644]
database/roles.sql
ndawn.pl

diff --git a/Channel.pm b/Channel.pm
deleted file mode 100644 (file)
index 9152e8d..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   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  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-package NDIRC::Channel;
-use strict;
-use warnings;
-use NDIRC::Access;
-require Exporter;
-
-our @ISA = qw/Exporter/;
-
-our @EXPORT = qw/op deop voice devoice/;
-
-sub op {
-       my ($nick) = @_;
-       umode("op","op",$nick);
-}
-
-sub deop {
-       my ($nick) = @_;
-       umode("deop","op",$nick);
-}
-
-sub voice {
-       my ($nick) = @_;
-       umode("voice","voice",$nick);
-}
-
-sub devoice {
-       my ($nick) = @_;
-       umode("devoice","voice",$nick);
-}
-
-sub umode {
-       my ($command,$access,$nick) = @_;
-       my $where = "";
-       unless (defined $nick){
-               $nick = $ND::nick;
-               $where = "OR f.name = 'auto_$access'";
-       }
-
-       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);
-               };
-       if (masterop()){
-               $mode = 1;
-       }else{
-               ($mode) = $ND::DBH->selectrow_array($mode,undef,$ND::address,$ND::target);
-       }
-       if ($mode){
-               $ND::server->command("$command $ND::target $nick");
-       }
-}
-
-1;
diff --git a/Commands/Channel.pm b/Commands/Channel.pm
new file mode 100644 (file)
index 0000000..c1a5f7b
--- /dev/null
@@ -0,0 +1,64 @@
+#**************************************************************************
+#   Copyright (C) 2008 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   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  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   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) = @_;
+
+       my ($access) = $self->name =~ /(op|voice)/;
+
+       my $where = "";
+       if ($msg =~ /^\s*$/){
+               $msg = $c->nick;
+               $where = "OR f.name = 'auto_$access'";
+       }
+
+       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);
+               };
+       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");
+       }
+}
+
+1;
index e0263be5796837d1e8a8f7e8db1bb2b3edc1816a..49de3231f378a6731c302e68af784baf401dd414 100644 (file)
@@ -1,11 +1,13 @@
 INSERT INTO roles VALUES('irc_p_nick');
 INSERT INTO roles VALUES('irc_p_intel');
+INSERT INTO roles VALUES('irc_masterop');
 
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel');
+INSERT INTO group_roles (gid,role) VALUES(1,'irc_masterop');
 
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_p_nick');
-INSERT INTO group_roles (gid,role) VALUES(3,'irc_p_intel');
+INSERT INTO group_roles (gid,role) VALUES(3,'irc_masterop');
 
 INSERT INTO group_roles (gid,role) VALUES(5,'irc_p_nick');
 INSERT INTO group_roles (gid,role) VALUES(5,'irc_p_intel');
index ffb7e5851a9ec17c1c396af7722d7887b6290a49..744aef4a17ca8519c2b44833c560b47831f679c3 100644 (file)
--- a/ndawn.pl
+++ b/ndawn.pl
@@ -55,10 +55,11 @@ my $TICK = $DBH->selectrow_array('SELECT tick()');
 
 my $disp = new NDIRC::Dispatcher;
 
-$disp->load('Basic','PA');
+$disp->load('Basic','PA','Channel');
 
-$disp->add_channel('#testarlite', ['pub','help']);
-$disp->add_channel('#testarmer', ['pub','help']);
+$disp->add_channel('#testarlite', ['pub','help','channel']);
+$disp->add_channel('#testarmer', ['pub','help','channel']);
+$disp->add_channel('pm', ['pub','help','pm']);
 
 sub event_pubmsg {
        my ($server, $msg, $nick, $address, $channel) = @_;