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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$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->adminadd(@_) }, "adminadd", 60);
|
|
|
|
$pbot->{commands}->register(sub { return $self->adminrem(@_) }, "adminrem", 60);
|
|
|
|
$pbot->{commands}->register(sub { return $self->adminset(@_) }, "adminset", 60);
|
|
|
|
$pbot->{commands}->register(sub { return $self->adminunset(@_) }, "adminunset", 60);
|
|
|
|
$pbot->{commands}->register(sub { return $self->sl(@_) }, "sl", 60);
|
|
|
|
$pbot->{commands}->register(sub { return $self->export(@_) }, "export", 60);
|
2011-02-10 09:40:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub sl {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{conn}->sl($arguments);
|
2011-02-10 09:40:14 +01:00
|
|
|
return "Sent.\n";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub login {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
my $result = $self->{pbot}->{admins}->login($from, "$nick!$user\@$host", $arguments);
|
2010-03-22 08:33:44 +01:00
|
|
|
return "/msg $nick $result";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub logout {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
2014-05-18 22:09:05 +02:00
|
|
|
return "/msg $nick Uh, you aren't logged into channel $from." if(not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host"));
|
|
|
|
$self->{pbot}->{admins}->logout($from, "$nick!$user\@$host");
|
2010-03-22 08:33:44 +01:00
|
|
|
return "/msg $nick Good-bye, $nick.";
|
|
|
|
}
|
|
|
|
|
2010-08-15 10:25:35 +02:00
|
|
|
sub adminadd {
|
2010-03-22 08:33:44 +01:00
|
|
|
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) {
|
2015-07-10 08:25:31 +02:00
|
|
|
return "/msg $nick Usage: adminadd <name> <channel> <hostmask> <level> <password>";
|
2010-03-29 14:30:35 +02:00
|
|
|
}
|
|
|
|
|
2015-07-10 08:25:31 +02:00
|
|
|
$channel = '.*' if lc $channel eq 'global';
|
|
|
|
|
2010-03-29 14:30:35 +02:00
|
|
|
$self->{pbot}->{admins}->add_admin($name, $channel, $hostmask, $level, $password);
|
|
|
|
return "Admin added.";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2010-08-15 10:25:35 +02:00
|
|
|
sub adminrem {
|
2010-03-22 08:33:44 +01:00
|
|
|
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) {
|
2015-07-10 08:25:31 +02:00
|
|
|
return "/msg $nick Usage: adminrem <channel> <hostmask/name>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$channel = lc $channel;
|
|
|
|
$hostmask = lc $hostmask;
|
|
|
|
|
|
|
|
$channel = '.*' if $channel eq 'global';
|
|
|
|
|
|
|
|
if (exists $self->{pbot}->{admins}->{admins}->hash->{$channel}) {
|
|
|
|
if (not exists $self->{pbot}->{admins}->{admins}->hash->{$channel}->{$hostmask}) {
|
|
|
|
foreach my $mask (keys $self->{pbot}->{admins}->{admins}->hash->{$channel}) {
|
|
|
|
if ($self->{pbot}->{admins}->{admins}->hash->{$channel}->{$mask}->{name} eq $hostmask) {
|
|
|
|
$hostmask = $mask;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-29 14:30:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-08-15 10:25:35 +02:00
|
|
|
sub adminset {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
my ($channel, $hostmask, $key, $value) = split / /, $arguments, 4 if defined $arguments;
|
|
|
|
|
|
|
|
if(not defined $channel or not defined $hostmask) {
|
2015-07-10 08:25:31 +02:00
|
|
|
return "Usage: adminset <channel> <hostmask/name> <key> <value>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$channel = lc $channel;
|
|
|
|
$hostmask = lc $hostmask;
|
|
|
|
|
|
|
|
$channel = '.*' if $channel eq 'global';
|
|
|
|
|
|
|
|
if (exists $self->{pbot}->{admins}->{admins}->hash->{$channel}) {
|
|
|
|
if (not exists $self->{pbot}->{admins}->{admins}->hash->{$channel}->{$hostmask}) {
|
|
|
|
foreach my $mask (keys $self->{pbot}->{admins}->{admins}->hash->{$channel}) {
|
|
|
|
if ($self->{pbot}->{admins}->{admins}->hash->{$channel}->{$mask}->{name} eq $hostmask) {
|
|
|
|
$hostmask = $mask;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-15 10:25:35 +02:00
|
|
|
}
|
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
return $self->{pbot}->{admins}->{admins}->set($channel, $hostmask, $key, $value);
|
2010-08-15 10:25:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub adminunset {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
my ($channel, $hostmask, $key) = split / /, $arguments, 3 if defined $arguments;
|
|
|
|
|
|
|
|
if(not defined $channel or not defined $hostmask) {
|
2015-07-10 08:25:31 +02:00
|
|
|
return "Usage: adminunset <channel> <hostmask/name> <key>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$channel = lc $channel;
|
|
|
|
$hostmask = lc $hostmask;
|
|
|
|
|
|
|
|
$channel = '.*' if $channel eq 'global';
|
|
|
|
|
|
|
|
if (exists $self->{pbot}->{admins}->{admins}->hash->{$channel}) {
|
|
|
|
if (not exists $self->{pbot}->{admins}->{admins}->hash->{$channel}->{$hostmask}) {
|
|
|
|
foreach my $mask (keys $self->{pbot}->{admins}->{admins}->hash->{$channel}) {
|
|
|
|
if ($self->{pbot}->{admins}->{admins}->hash->{$channel}->{$mask}->{name} eq $hostmask) {
|
|
|
|
$hostmask = $mask;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-15 10:25:35 +02:00
|
|
|
}
|
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
return $self->{pbot}->{admins}->{admins}->unset($channel, $hostmask, $key);
|
2010-08-15 10:25:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
sub join_channel {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
|
2014-05-13 12:15:52 +02:00
|
|
|
foreach my $channel (split /\s+/, $arguments) {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("$nick!$user\@$host made me join $channel\n");
|
2014-12-18 09:46:13 +01:00
|
|
|
$self->{pbot}->{chanops}->join_channel($channel);
|
2014-05-13 12:15:52 +02:00
|
|
|
}
|
|
|
|
|
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) = @_;
|
|
|
|
|
2014-05-13 12:15:52 +02:00
|
|
|
$arguments = $from if not $arguments;
|
|
|
|
|
|
|
|
foreach my $channel (split /\s+/, $arguments) {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("$nick!$user\@$host made me part $channel\n");
|
2014-12-18 09:46:13 +01:00
|
|
|
$self->{pbot}->{chanops}->part_channel($channel);
|
2014-05-13 12:15:52 +02:00
|
|
|
}
|
|
|
|
|
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) = @_;
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("$nick!$user\@$host made me exit.\n");
|
2014-05-17 00:11:31 +02:00
|
|
|
$self->{pbot}->atexit();
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{conn}->privmsg($from, "Good-bye.") if defined $from;
|
|
|
|
$self->{pbot}->{conn}->quit("Departure requested.");
|
2010-03-22 08:33:44 +01:00
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub export {
|
2012-08-24 00:50:07 +02:00
|
|
|
my $self = shift;
|
2010-03-22 08:33:44 +01:00
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
|
|
|
|
if(not defined $arguments) {
|
2012-08-01 13:06:01 +02:00
|
|
|
return "/msg $nick Usage: export <modules|factoids|admins|quotegrabs>";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if($arguments =~ /^modules$/i) {
|
|
|
|
return "/msg $nick Coming soon.";
|
|
|
|
}
|
|
|
|
|
|
|
|
if($arguments =~ /^quotegrabs$/i) {
|
2014-05-18 22:09:05 +02:00
|
|
|
return $self->{pbot}->{quotegrabs}->export_quotegrabs;
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if($arguments =~ /^factoids$/i) {
|
2014-05-18 22:09:05 +02:00
|
|
|
return $self->{pbot}->{factoids}->export_factoids;
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if($arguments =~ /^admins$/i) {
|
|
|
|
return "/msg $nick Coming soon.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|