X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FChannel.pm;h=f83969ea8f4594f69b3f790e015412c608672329;hb=a7e034b3599d41cdf5a158b14bd1715451f89a0c;hp=c1a5f7b5f405a864f0acb1d961f5faae22d14590;hpb=7091b004eee879d36792d6da3b8fd4fb1b5f71bf;p=NDIRC.git diff --git a/Commands/Channel.pm b/Commands/Channel.pm index c1a5f7b..f83969e 100644 --- a/Commands/Channel.pm +++ b/Commands/Channel.pm @@ -33,32 +33,110 @@ sub op { my ($self,$c,$msg) = @_; - my ($access) = $self->name =~ /(op|voice)/; + $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'"; + 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; + $mode = substr $access[0], 0,1; }else{ - ($mode) = $c->model->selectrow_array($mode,undef,$c->host,$c->channel); + ($mode) = $c->model->selectrow_array($mode,undef,$c->uid,$c->channel,\@access); } if ($mode){ - $c->server->command($self->name . " " . $c->channel . " $msg"); + $c->command(mode => $c->channel, "$mod$mode", $msg); }else{ $c->reply("No access to " . $self->name . " in this channel"); } } +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) = @_; + + 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, $_); + } +} + +sub hostname + : Help(Shows your hostname, as seen by the bots.) +{ + my ($self,$c,$msg) = @_; + + $c->reply('Your hostname is: '.$c->host); +} + +########################################################### +# Written by Guy Malachi http://guymal.com +# 18 August, 2002 +########################################################### +sub generate_random_string +{ + my $length_of_randomstring=shift;# the length of + # the random string to generate + + my @chars=('a'..'z','A'..'Z','0'..'9','_'); + my $random_string; + foreach (1..$length_of_randomstring) + { + # rand @chars will generate a random + # number between 0 and scalar @chars + $random_string .= $chars[rand @chars]; + } + return $random_string; +} + +sub getpass + : Help(Gives new users a random password.) + : Type(pm) +{ + my ($self,$c,$msg) = @_; + my $dbh = $c->model; + + my $password = generate_random_string 10; + my $update = $dbh->do(q{ +UPDATE users SET password = MD5( ? ) +WHERE uid ? AND password ='' + },undef,$password,$c->uid); + if ($update > 0){ + $c->reply("Password set to: $password (you can change it on webbie)"); + }else{ + $c->reply("Couldn't set password. Either it has already been set or you don't have an account"); + } +} + 1;