From feafb99135d10f84e12a6dc570b9d04314fb98dd Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Tue, 8 Sep 2020 13:35:49 -0700 Subject: [PATCH] fix some table issues --- etc/bb3.conf | 63 ++----------------------------- plugins/seen.pm | 98 ------------------------------------------------- postgresql.sql | 10 +++++ 3 files changed, 14 insertions(+), 157 deletions(-) delete mode 100644 plugins/seen.pm diff --git a/etc/bb3.conf b/etc/bb3.conf index 46e75a5..02d9459 100644 --- a/etc/bb3.conf +++ b/etc/bb3.conf @@ -38,25 +38,8 @@ 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 @@ -74,48 +57,10 @@ http_plugin_port 1092 ignore EvanCarol ignore EC - server 192.168.32.1 - username perlbot - password sindarin - port 65432 + server irc.freenode.net + username perlbot-dev + password notmypassword + port 6667 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 deleted file mode 100644 index 017dde3..0000000 --- a/plugins/seen.pm +++ /dev/null @@ -1,98 +0,0 @@ -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'. - diff --git a/postgresql.sql b/postgresql.sql index 2a8c650..7bf6ba6 100644 --- a/postgresql.sql +++ b/postgresql.sql @@ -4,10 +4,20 @@ BEGIN; DROP TABLE IF EXISTS public.factoid; CREATE TABLE public.factoid AS (SELECT * FROM sqlite.factoid); +CREATE SEQUENCE IF NOT EXISTS factoid_factoid_id_seq AS bigint OWNED BY public.factoid.factoid_id; +SELECT setval('factoid_factoid_id_seq', (select max(factoid_id)+1 from public.factoid)); +ALTER TABLE public.factoid ALTER COLUMN factoid_id SET DEFAULT nextval('factoid_factoid_id_seq'); +ALTER TABLE public.factoid ALTER COLUMN factoid_id SET NOT NULL; +ALTER TABLE public.factoid ADD PRIMARY KEY (factoid_id); + ALTER TABLE public.factoid ALTER COLUMN original_subject TYPE text; +ALTER TABLE public.factoid ALTER COLUMN original_subject SET NOT NULL; ALTER TABLE public.factoid ALTER COLUMN subject TYPE text; +ALTER TABLE public.factoid ALTER COLUMN subject SET NOT NULL; ALTER TABLE public.factoid ALTER COLUMN copula TYPE text; +ALTER TABLE public.factoid ALTER COLUMN copula SET NOT NULL; ALTER TABLE public.factoid ALTER COLUMN author TYPE text; +ALTER TABLE public.factoid ALTER COLUMN author SET NOT NULL; ALTER TABLE public.factoid ADD COLUMN deleted boolean DEFAULT false; ALTER TABLE public.factoid ADD COLUMN namespace text; ALTER TABLE public.factoid ADD COLUMN server text;