1 #**************************************************************************
2 # Copyright (C) 2009 by Michael Andreen <harvATruinDOTnu> *
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. *
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. *
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 #**************************************************************************/
25 use NDIRC::Dispatcher;
27 my $access = class extends NDIRC::Command {
28 method execute ($c,$msg) {
29 $self->name =~ /(de)?(op|voice)/;
31 my $mod = $1 ? '-' : '';
35 push @access, "auto_$access[0]";
39 SELECT DISTINCT LOWER(flag) FROM users u
40 JOIN groupmembers g USING (uid)
41 JOIN channel_group_flags gf USING (gid)
42 JOIN channel_flags f USING (flag)
43 WHERE uid = $1 AND channel = $2 AND f.name = ANY($3);
45 if ($c->check_user_roles(qw/irc_masterop/)){
46 $mode = substr $access[0], 0,1;
48 ($mode) = $c->model->selectrow_array($mode,undef,$c->uid,$c->channel,\@access);
51 $c->command(mode => $c->channel, "$mod$mode", $msg);
53 $c->reply("No access to " . $self->name . " in this channel");
59 help => q(syntax: .op [nicks] | Gives op to the specified nicks, or yourself if no command is given),
64 help => q(syntax: .deop [nicks] | Removes op from the specified nicks, or yourself if no command is given),
69 help => q(syntax: .voice [nicks] | Gives voice to the specified nicks, or yourself if no command is given),
74 help => q(syntax: .voice [nicks] | Removes voice from the specified nicks, or yourself if no command is given),
79 help => q(Syntax: invite [channel] | If no channel is specified it invites you to all channel you have auto invite access on),
81 }, class extends NDIRC::Command {
82 method execute ($c,$msg) {
83 my ($channel) = $msg =~ /^\s*(\S+)?\s*$/ or die 'ARGS';
86 if ($channel && $c->check_user_roles('irc_masterinvite')){
87 push @channels,$channel;
90 push @access, 'I' if $channel;
91 my $channels = $c->model->prepare(q{
92 SELECT DISTINCT channel FROM users u
93 JOIN groupmembers g USING (uid)
94 JOIN channel_group_flags gf USING (gid)
95 WHERE uid = $1 AND COALESCE(channel = $2,TRUE)
98 $channels->execute($c->uid,$channel,\@access);
99 while (my ($channel) = $channels->fetchrow()){
100 push @channels,$channel;
104 $c->command(invite => $c->nick, $_);
109 command hostname => {
110 help => q(Shows your hostname, as seen by the bots.)
111 }, class extends NDIRC::Command {
112 method execute ($c,$msg) {
113 $c->reply('Your hostname is: '.$c->host);
118 help => q(Gives new users a random password.),
120 }, class extends NDIRC::Command {
122 ###########################################################
123 # Written by Guy Malachi http://guymal.com
125 ###########################################################
126 sub generate_random_string
128 my $length_of_randomstring=shift;# the length of
129 # the random string to generate
131 my @chars=('a'..'z','A'..'Z','0'..'9','_');
133 foreach (1..$length_of_randomstring)
135 # rand @chars will generate a random
136 # number between 0 and scalar @chars
137 $random_string .= $chars[rand @chars];
139 return $random_string;
142 method execute ($c,$msg) {
145 my $password = generate_random_string 10;
146 my $update = $dbh->do(q{
147 UPDATE users SET password = MD5( ? )
148 WHERE uid = ? AND password =''
149 },undef,$password,$c->uid);
151 $c->reply("Password set to: $password (you can change it on webbie)");
153 $c->reply("Couldn't set password. Either it has already been set or you don't have an account");