2010-03-22 08:33:44 +01:00
|
|
|
# File: BotAdminCommands.pm
|
2010-03-24 07:47:40 +01:00
|
|
|
# Author: pragma_
|
2010-03-22 08:33:44 +01:00
|
|
|
#
|
|
|
|
# Purpose: Administrative command subroutines.
|
|
|
|
|
|
|
|
package PBot::BotAdminCommands;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2010-03-24 07:47:40 +01:00
|
|
|
use vars qw($VERSION);
|
|
|
|
$VERSION = $PBot::PBot::VERSION;
|
2010-03-22 08:33:44 +01:00
|
|
|
|
|
|
|
use Carp ();
|
|
|
|
|
|
|
|
sub new {
|
|
|
|
if(ref($_[1]) eq 'HASH') {
|
|
|
|
Carp::croak("Options to BotAdminCommands should be key/value pairs, not hash reference");
|
|
|
|
}
|
|
|
|
|
|
|
|
my ($class, %conf) = @_;
|
|
|
|
|
|
|
|
my $self = bless {}, $class;
|
|
|
|
$self->initialize(%conf);
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub initialize {
|
|
|
|
my ($self, %conf) = @_;
|
|
|
|
|
|
|
|
my $pbot = delete $conf{pbot};
|
|
|
|
if(not defined $pbot) {
|
|
|
|
Carp::croak("Missing pbot reference to BotAdminCommands");
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->{pbot} = $pbot;
|
|
|
|
|
|
|
|
$pbot->commands->register(sub { return $self->login(@_) }, "login", 0);
|
|
|
|
$pbot->commands->register(sub { return $self->logout(@_) }, "logout", 0);
|
|
|
|
$pbot->commands->register(sub { return $self->join_channel(@_) }, "join", 45);
|
|
|
|
$pbot->commands->register(sub { return $self->part_channel(@_) }, "part", 45);
|
|
|
|
$pbot->commands->register(sub { return $self->ack_die(@_) }, "die", 50);
|
|
|
|
$pbot->commands->register(sub { return $self->add_admin(@_) }, "addadmin", 60);
|
2010-03-29 14:30:35 +02:00
|
|
|
$pbot->commands->register(sub { return $self->del_admin(@_) }, "deladmin", 60);
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub login {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
|
|
|
|
if($self->{pbot}->admins->loggedin($from, "$nick!$user\@$host")) {
|
2010-03-29 14:30:35 +02:00
|
|
|
return "/msg $nick You are already logged into channel $from.";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
my $result = $self->{pbot}->admins->login($from, "$nick!$user\@$host", $arguments);
|
|
|
|
return "/msg $nick $result";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub logout {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
2010-03-29 14:30:35 +02:00
|
|
|
return "/msg $nick Uh, you aren't logged into channel $from." if(not $self->{pbot}->admins->loggedin($from, "$nick!$user\@$host"));
|
2010-03-22 08:33:44 +01:00
|
|
|
$self->{pbot}->admins->logout($from, "$nick!$user\@$host");
|
|
|
|
return "/msg $nick Good-bye, $nick.";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub add_admin {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
2010-03-29 14:30:35 +02:00
|
|
|
|
|
|
|
my ($name, $channel, $hostmask, $level, $password) = split / /, $arguments, 5;
|
|
|
|
|
|
|
|
if(not defined $name or not defined $channel or not defined $hostmask or not defined $level
|
|
|
|
or not defined $password) {
|
|
|
|
return "/msg $nick Usage: addadmin name channel hostmask level password";
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->{pbot}->{admins}->add_admin($name, $channel, $hostmask, $level, $password);
|
|
|
|
$self->{pbot}->{admins}->save_admins;
|
|
|
|
return "Admin added.";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub del_admin {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
2010-03-29 14:30:35 +02:00
|
|
|
|
|
|
|
my ($channel, $hostmask) = split / /, $arguments, 2;
|
|
|
|
|
|
|
|
if(not defined $channel or not defined $hostmask) {
|
|
|
|
return "/msg $nick Usage: deladmin channel hostmask";
|
|
|
|
}
|
|
|
|
|
|
|
|
if($self->{pbot}->{admins}->remove_admin($channel, $hostmask)) {
|
|
|
|
return "Admin removed.";
|
|
|
|
} else {
|
|
|
|
return "No such admin found.";
|
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub join_channel {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
|
|
|
|
# FIXME -- update %channels hash?
|
|
|
|
$self->{pbot}->logger->log("$nick!$user\@$host made me join $arguments\n");
|
|
|
|
$self->{pbot}->conn->join($arguments);
|
2010-04-02 19:33:18 +02:00
|
|
|
return "/msg $nick Joining $arguments";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub part_channel {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
|
|
|
|
# FIXME -- update %channels hash?
|
|
|
|
$self->{pbot}->logger->log("$nick!$user\@$host made me part $arguments\n");
|
|
|
|
$self->{pbot}->conn->part($arguments);
|
2010-04-02 19:33:18 +02:00
|
|
|
return "/msg $nick Parting $arguments";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub ack_die {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
$self->{pbot}->logger->log("$nick!$user\@$host made me exit.\n");
|
|
|
|
$self->{pbot}->factoids->save_factoids();
|
2010-04-06 21:15:42 +02:00
|
|
|
$self->{pbot}->ignorelist->save_ignores();
|
2010-03-22 08:33:44 +01:00
|
|
|
$self->{pbot}->conn->privmsg($from, "Good-bye.") if defined $from;
|
|
|
|
$self->{pbot}->conn->quit("Departure requested.");
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub export {
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
|
|
|
|
if(not defined $arguments) {
|
|
|
|
return "/msg $nick Usage: export <modules|factoids|admins>";
|
|
|
|
}
|
|
|
|
|
|
|
|
if($arguments =~ /^modules$/i) {
|
|
|
|
return "/msg $nick Coming soon.";
|
|
|
|
}
|
|
|
|
|
|
|
|
if($arguments =~ /^quotegrabs$/i) {
|
|
|
|
return PBot::Quotegrabs::export_quotegrabs();
|
|
|
|
}
|
|
|
|
|
|
|
|
if($arguments =~ /^factoids$/i) {
|
|
|
|
return PBot::Factoids::export_factoids();
|
|
|
|
}
|
|
|
|
|
|
|
|
if($arguments =~ /^admins$/i) {
|
|
|
|
return "/msg $nick Coming soon.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|