my $ssnick = 'SpamServ';
my %chanlist;
-use SrSv::Process::InParent qw(list_conf loadconf saveconf);
+use SrSv::Process::InParent qw(list_conf loadconf loadchans saveconf savechans);
# should load both spamserv.conf and chans.conf (if available)
loadconf();
+loadchans();
addhandler('PRIVMSG', undef, undef, 'spamserv::ss_privmsg');
addhandler('NOTICE', undef, undef, 'spamserv::ss_notice');
}
elsif (lc $dst eq "spamserv") {
my $user = { NICK => $src, AGENT => $dst };
- unless(adminserv::is_svsop($user, adminserv::S_ROOT())) {
+ unless(adminserv::is_ircop($user)) {
notice($user, "Permission denied");
return;
}
my @args = split(/\s+/, $msg);
my $cmd = shift @args;
- if ($cmd =~ /^help$/) {
+
+ if ($cmd =~ /^help$/i) {
sendhelp($user, 'spamserv', @args);
}
+
+ elsif ($cmd =~ /^rehash/i) {
+ notice($user, "Loading configuration");
+ loadconf();
+ }
+
+ if ($cmd =~ /^listconf$/i) {
+ notice($user, "Configuration:", list_conf);
+ }
+
+ elsif ($cmd =~ /^save/i) {
+ notice($user, "Saving configuration");
+ saveconf();
+ }
+
+ elsif ($msg =~ /^set (\S+) (.*)/i) {
+ if (!adminserv::is_svsop($user, adminserv::S_ROOT())) {
+ notice($user, 'You do not have sufficient rank for this command');
+ return;
+ }
+ if (update_conf($1, $2)) {
+ notice($user, "Configuration: $1 = $2");
+ } else {
+ notice($user, "This appears to be an invalid option");
+ }
+ }
elsif ($cmd =~ /^watch$/i) {
ss_watch($user, shift @args, @args);
}
sub ss_list($) {
my ($user) = @_;
- notice($user, 'Channels currently being being watched');
+ notice($user, 'Channels currently being watched');
foreach my $cn (keys(%chanlist)) {
notice($user, ' '.$cn);
}
$chanlist{lc $cn} = 1;
agent_join((split /!/, $fakehost)[0], $cn) if defined $fakehost;
notice($user, "Channel \002$cn\002 will now be watched");
- saveconf();
+ savechans();
return 1;
} else {
notice($user, "Channel \002$cn\002 is already being watched");
delete($chanlist{lc $cn});
agent_part((split /!/, $fakehost)[0], $cn, '') if defined $fakehost;
notice($user, "Channel \002$cn\002 will not be watched");
- saveconf();
+ savechans();
return 1;
} else {
notice($user, "Channel \002$cn\002 is not being watched");
}
}
-sub saveconf() {
+sub savechans() {
my @channels = keys(%chanlist);
Storable::nstore(\@channels, "config/spamserv/chans.conf");
}
+sub saveconf() {
+ writeHash(\%conf, "config/spamserv/spamserv.conf");
+}
+
+sub list_conf() {
+ my @k = keys(%conf);
+ my @v = values(%conf);
+ my @reply;
+
+ for(my $i=0; $i<@k; $i++) {
+ push @reply, $k[$i]." = ".$v[$i];
+ }
+ return @reply;
+}
+
sub loadconf() {
# doesn't seem to pick up any of the values
%conf = readHash("config/spamserv/spamserv.conf");
+}
+sub loadchans() {
return unless(-f "config/spamserv/chans.conf");
my @channels = @{Storable::retrieve("config/spamserv/chans.conf")};
foreach my $cn (@channels) {
}
}
+sub update_conf($$) {
+ my ($k,$v) = @_;
+ if (exists($conf{$k})) {
+ $conf{$k} = $v;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
sub join_chans() {
foreach my $cn (keys(%chanlist)) {
agent_join((split /!/, $fakehost)[0], $cn);
sub init { }
sub begin { }
sub end { }
-sub unload { saveconf(); }
+sub unload { savechans(); saveconf(); }
1;