From e7985371748c6eda9eafa0bf16074c296004ae81 Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Tue, 8 Sep 2020 13:36:39 -0700 Subject: [PATCH] whoops --- etc/bb3.conf | 63 +++++++++++++++++++++++++++++-- plugins/seen.pm | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 plugins/seen.pm diff --git a/etc/bb3.conf b/etc/bb3.conf index 02d9459..46e75a5 100644 --- a/etc/bb3.conf +++ b/etc/bb3.conf @@ -38,8 +38,25 @@ http_plugin_port 1092 channel \#buubot + channel \#\#turtles + channel \#perlcafe channel \#webgui + channel \#citadel + channel \#modperl + channel \#perl + channel \#ipv6 channel \#perlbot + channel \#mrtg + channel \#ipv6-fr + channel \#freebsd-fr + channel \#botpark + channel \#css + channel \#modus + channel \#perl-cats + channel \#cout.dev + channel \#web-locals + channel \#regex + channel \#regexen ignore buubot ignore avarbot @@ -57,10 +74,48 @@ http_plugin_port 1092 ignore EvanCarol ignore EC - server irc.freenode.net - username perlbot-dev - password notmypassword - port 6667 + server 192.168.32.1 + username perlbot + password sindarin + port 65432 root_mask p3m/member/simcop2387 + + channel \#freenode-perl-cabal + channel \#perl-help + + ignore purl + ignore perlbot + + server 192.168.32.1 + username perlbot-magnet + password sindarin + port 65432 + root_mask ~simcop238@simcop2387.info + + + channel \#perlbot + channel \#perl + + ignore purl + ignore perlbot + + server 192.168.32.1 + username perlbot-oftc + password sindarin + port 65432 + root_mask ~simcop238@simcop2387.info + + + channel \#perl + + ignore purl + ignore perlbot + + server 192.168.32.1 + username perlbot-efnet + password sindarin + port 65432 + root_mask ~simcop238@simcop2387.info + diff --git a/plugins/seen.pm b/plugins/seen.pm new file mode 100644 index 0000000..017dde3 --- /dev/null +++ b/plugins/seen.pm @@ -0,0 +1,98 @@ +package Bot::BB3::Plugin::Seen; +use POE::Component::IRC::Common qw/l_irc/; +use DBD::SQLite; +use strict; + +sub new { + my( $class ) = @_; + my $self = bless {}, $class; + $self->{name} = "seen"; + $self->{opts} = { + command => 1, + handler => 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/seen.db", "", "", { PrintError => 0, RaiseError => 1 } ); + + return $dbh; +} +sub postload { + my( $self, $pm ) = @_; + + + my $sql = "CREATE TABLE seen ( + seen_id INTEGER PRIMARY KEY AUTOINCREMENT, + user VARCHAR(25), + lc_user VARCHAR(25), + message VARCHAR(250), + seen_date INTEGER + );"; + + $pm->create_table( $self->dbh, "seen", $sql ); + + delete $self->{dbh}; # UGLY HAX GO. + # Basically we delete the dbh we cached so we don't fork + # with one active +} + +sub command { + my( $self, $said, $pm ) = @_; + my( $target ) = @{ $said->{recommended_args} }; + + return () unless $said->{addressed}; + + my $seen = $self->dbh->selectrow_arrayref( "SELECT user,message,seen_date FROM seen WHERE lc_user = ?", + undef, + l_irc( $target ) + ); + + if( $seen and @$seen and $seen->[0] ) { + + return( 'handled', "I last saw $seen->[0] saying \"$seen->[1]\" at " . gmtime($seen->[2]) . " Z." ); + } + else { + return( 'handled', "I don't think I've seen $target." ); + } +} + +sub handle { + my ( $self, $said, $pm ) = @_; + eval { + my $count = $self->dbh->do( "UPDATE seen SET user = ?, message = ?, seen_date = ? WHERE lc_user = ?", + undef, + $said->{name}, + $said->{body}, + time(), + l_irc( $said->{name} ), + ); + + if( $count == 0 ) { + $self->dbh->do( "INSERT INTO seen (user,lc_user,message,seen_date) VALUES ( ?,?,?,? )", + undef, + $said->{name}, + l_irc($said->{name}), + $said->{body}, + time(), + ); + } + }; # ignore errors from database during non-addressed writes. + + return; +} + +no warnings 'void'; +"Bot::BB3::Plugin::Seen"; + +__DATA__ +The seen plugin. Attempts to keep track of every user the bot has 'seen'. Use the syntax, seen user; to ask the bot when it last saw the user named 'user'. +