From 7091b004eee879d36792d6da3b8fd4fb1b5f71bf Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sat, 9 May 2009 15:34:51 +0200 Subject: [PATCH] Converted .op, .deop, .voice and .devoice --- Channel.pm => Commands/Channel.pm | 53 ++++++++++++------------------- database/roles.sql | 4 ++- ndawn.pl | 7 ++-- 3 files changed, 28 insertions(+), 36 deletions(-) rename Channel.pm => Commands/Channel.pm (71%) diff --git a/Channel.pm b/Commands/Channel.pm similarity index 71% rename from Channel.pm rename to Commands/Channel.pm index 9152e8d..c1a5f7b 100644 --- a/Channel.pm +++ b/Commands/Channel.pm @@ -1,5 +1,5 @@ #************************************************************************** -# Copyright (C) 2006 by Michael Andreen * +# Copyright (C) 2008 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 * @@ -16,41 +16,28 @@ # 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/; +package NDIRC::Commands::Channel; -sub op { - my ($nick) = @_; - umode("op","op",$nick); -} +use strict; +use warnings; +use feature ':5.10'; -sub deop { - my ($nick) = @_; - umode("deop","op",$nick); -} +use Moose; +use MooseX::MethodAttributes; -sub voice { - my ($nick) = @_; - umode("voice","voice",$nick); -} +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) = @_; -sub devoice { - my ($nick) = @_; - umode("devoice","voice",$nick); -} + my ($access) = $self->name =~ /(op|voice)/; -sub umode { - my ($command,$access,$nick) = @_; my $where = ""; - unless (defined $nick){ - $nick = $ND::nick; + if ($msg =~ /^\s*$/){ + $msg = $c->nick; $where = "OR f.name = 'auto_$access'"; } @@ -62,13 +49,15 @@ SELECT DISTINCT c.name FROM users u JOIN channel_flags f ON f.id = gf.flag WHERE u.hostmask ILIKE ? AND c.name = ? AND (f.name = '$access' $where); }; - if (masterop()){ + if ($c->check_user_roles(qw/irc_masterop/)){ $mode = 1; }else{ - ($mode) = $ND::DBH->selectrow_array($mode,undef,$ND::address,$ND::target); + ($mode) = $c->model->selectrow_array($mode,undef,$c->host,$c->channel); } if ($mode){ - $ND::server->command("$command $ND::target $nick"); + $c->server->command($self->name . " " . $c->channel . " $msg"); + }else{ + $c->reply("No access to " . $self->name . " in this channel"); } } diff --git a/database/roles.sql b/database/roles.sql index e0263be..49de323 100644 --- a/database/roles.sql +++ b/database/roles.sql @@ -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'); diff --git a/ndawn.pl b/ndawn.pl index ffb7e58..744aef4 100644 --- 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) = @_; -- 2.39.2