1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut synced 2025-06-07 10:35:41 -04:00

Add in the allowpaste plugin to control the pastebin

This commit is contained in:
Ryan Voots 2016-06-26 19:11:02 -04:00
parent a0b2f7c715
commit 0c1f9a4f85
5 changed files with 136 additions and 8 deletions

View file

@ -2,6 +2,7 @@ server "*" {
channel "*" {
plugin "*" { addressed: true }
plugin "join" { access: op; addressed: true }
plugin "allowpaste" { access: op; addressed: true }
plugin "part" { access: op }
plugin "reload_plugins" { access: root }
plugin "restart" { access: root }

View file

@ -20,6 +20,27 @@ sub new {
return $self;
}
{
my $dbh;
sub dbh {
if( $dbh and $dbh->ping ) {
return $dbh;
}
$dbh = DBI->connect( "dbi:SQLite:dbname=var/allowpaste.db", "", "", { PrintError => 0, RaiseError => 1 } );
return $dbh;
}
}
sub get_status {
my ($chancon) = @_;
my $status = dbh()->selectrow_hashref('SELECT value FROM allowpaste WHERE channel = ?', {}, $chancon);
return ($status // {})->{value};
}
sub _start {
my( $self, $kernel ) = @_[OBJECT,KERNEL];
my $conf = $self->{conf};
@ -50,13 +71,19 @@ sub receive_paste {
if( $alert_channel !~ /^\s*---/ ) { # Ignore things like "---irc.freenode, skip server names
my($server,$nick,$channel) = split /:/,$alert_channel,3;
$_[KERNEL]->post( "Bot::BB3::Roles::IRC",
external_message =>
$server,
$nick,
$channel,
"$who pasted a new file at $link - $summary"
);
my $setting = get_status($alert_channel) // 1;
if ($setting) {
$_[KERNEL]->post( "Bot::BB3::Roles::IRC",
external_message =>
$server,
$nick,
$channel,
"$who pasted a new file at $link - $summary"
);
} else {
return; # we've been disallowed
}
}
}
}

View file

@ -500,6 +500,16 @@ sub external_message {
}
}
sub get_server_conf {
my( $self, $input_pci_id) = @_[OBJECT,ARG0];
for my $pci_id ( keys %{ $self->{bot_confs} } ) {
my $conf = $self->{bot_confs}->{$pci_id};
my $poco_irc = $self->get_component($pci_id);
}
}
sub channel_list {
my( $self, $kernel, $sender ) = @_[OBJECT,KERNEL,SENDER];

90
plugins/allowpaste.pm Normal file
View file

@ -0,0 +1,90 @@
package Bot::BB3::Plugin::Allowpaste;
use POE::Component::IRC::Common qw/l_irc/;
use DBD::SQLite;
use strict;
sub new {
my( $class ) = @_;
my $self = bless {}, $class;
$self->{name} = "allowpaste";
$self->{opts} = {
command => 1,
};
return $self;
}
sub dbh {
my( $self ) = @_;
if( $self->{dbh} and $self->{dbh}->ping ) {
return $self->{dbh};
}
my $dbh = $self->{dbh} = DBI->connect( "dbi:SQLite:dbname=var/allowpaste.db", "", "", { PrintError => 0, RaiseError => 1 } );
return $dbh;
}
sub postload {
my( $self, $pm ) = @_;
my $sql = "CREATE TABLE allowpaste (
channel VARCHAR(255) NOT NULL UNIQUE,
value INTEGER NOT NULL,
setby VARCHAR(255) NOT NULL,
set_date INTEGER NOT NULL
);
";
$pm->create_table( $self->dbh, "allowpaste", $sql );
delete $self->{dbh}; # UGLY HAX GO.
# Basically we delete the dbh we cached so we don't fork
# with one active
}
sub get_status {
my ($self, $chancon) = @_;
my $status = $self->dbh->selectrow_hashref('SELECT value FROM allowpaste WHERE channel = ?', {}, $chancon);
return ($status // {})->{value};
}
sub set_status {
my ($self, $chancon, $setting, $who) = @_;
if (defined $self->get_status($chancon)) {
$self->dbh->do('UPDATE allowpaste SET value = ?, setby = ?, set_date = ? WHERE channel = ?', {}, $setting eq 'on' ? 1 : 0, $who, time(), $chancon);
} else {
$self->dbh->do('INSERT INTO allowpaste (channel, value, setby, set_date) VALUES (?, ?, ?, ?)', {}, $chancon, $setting eq 'on' ? 1 : 0, $who, time());
}
}
sub command {
my( $self, $said, $pm ) = @_;
my( $set_to ) = @{ $said->{recommended_args} };
my $server_conf = $pm->{bb3}{'Bot::BB3::Roles::IRC'}{bot_confs}{$said->{pci_id}};
my ($botname, $servername) = @{$server_conf}{qw/botname server/};
my $channel = $said->{channel};
my $chanconstruct = "$servername:$botname:$channel";
if ($set_to && (lc($set_to) eq 'on' || lc($set_to) eq 'off')) {
$self->set_status($chanconstruct, $set_to, $said->{name});
return('handled', "This channel has pastebin set [$set_to]");
} else {
my $status = $self->get_status($chanconstruct)//1 ? 'on' : 'off';
return('handled', "This channel has pastebin set to [$status] :: $chanconstruct");
}
}
no warnings 'void';
"Bot::BB3::Plugin::Allowpaste";
__DATA__
The allowpaste plugin. Lets operators disable pastes being announced in the channel. allowpaste [on|off] => Tell you the state, or turn it on or off.

View file

@ -1,6 +1,6 @@
use strict;
use warnings;
use Bing::Translate;
#use Bing::Translate;