X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FFactoids%2FDBCommon.pl;h=5321c25f3dd2307b59add98e826aa43d4a4b25ea;hb=3536c5564f248374a76fa5eda24f4b9c5b2c54c1;hp=3ae369418753a59c10940135f9fcf05fe01f6d12;hpb=4af71a5a1add30c9150be6bb49b7aafabf17e63a;p=infobot.git diff --git a/src/Factoids/DBCommon.pl b/src/Factoids/DBCommon.pl index 3ae3694..5321c25 100644 --- a/src/Factoids/DBCommon.pl +++ b/src/Factoids/DBCommon.pl @@ -5,28 +5,48 @@ # Created: 19991020 # -if (&IsParam("useStrict")) { use strict; } +# use strict; # TODO ##### -# Usage: &setFactInfo($faqtoid, $type, $primval, $key, $val); +# Usage: &setFactInfo($faqtoid, $key, $val); sub setFactInfo { - &dbSet("factoids", - { factoid_key => $_[0] }, - { $_[1] => $_[2] } - ); -} + &sqlSet( 'factoids', { factoid_key => $_[0] }, { $_[1] => $_[2] } ); +} + +##### +# Usage: &getFactInfo($faqtoid, [$what]); +sub getFactInfo { + return &sqlSelect( 'factoids', $_[1], { factoid_key => $_[0] } ); +} + +##### +# Usage: &getFactoid($faqtoid); +sub getFactoid { + return &getFactInfo( $_[0], 'factoid_value' ); +} + +##### +# Usage: &delFactoid($faqtoid); +sub delFactoid { + my ($faqtoid) = @_; + + &sqlDelete( 'factoids', { factoid_key => $faqtoid } ); + &status("DELETED $faqtoid"); + + return 1; +} ##### # Usage: &IsLocked($faqtoid); sub IsLocked { my ($faqtoid) = @_; - my $thisnuh = &getFactInfo($faqtoid, "locked_by"); + my $thisnuh = &getFactInfo( $faqtoid, 'locked_by' ); - if (defined $thisnuh and $thisnuh ne "") { - if (!&IsHostMatch($thisnuh) and &IsFlag("o") ne "o") { - &performReply("cannot alter locked factoids"); - return 1; - } + if ( defined $thisnuh and $thisnuh ne '' ) { + if ( !&IsHostMatch($thisnuh) and &IsFlag('o') ne 'o' ) { + &performReply("cannot alter locked factoids"); + return 1; + } } return 0; @@ -35,33 +55,33 @@ sub IsLocked { ##### # Usage: &AddModified($faqtoid,$nuh); sub AddModified { - my ($faqtoid,$nuh) = @_; - my $modified_by = &getFactInfo($faqtoid, "modified_by"); - my (@modifiedlist, @modified, %modified); + my ( $faqtoid, $nuh ) = @_; + my $modified_by = &getFactInfo( $faqtoid, 'modified_by' ); + my ( @modifiedlist, @modified, %modified ); - if (defined $modified_by) { - push(@modifiedlist, split(/\,/, $modified_by)); + if ( defined $modified_by ) { + push( @modifiedlist, split( /\,/, $modified_by ) ); } - push(@modifiedlist,$nuh); + push( @modifiedlist, $nuh ); - foreach (reverse @modifiedlist) { - /^(\S+)!(\S+)@(\S+)$/; - my $nick = lc $1; - next if (exists $modified{$nick}); + foreach ( reverse @modifiedlist ) { + /^(\S+)!(\S+)@(\S+)$/; + my $nick = lc $1; + next if ( exists $modified{$nick} ); - $modified{$nick} = $_; - push(@modified,$nick); + $modified{$nick} = $_; + push( @modified, $nick ); } undef @modifiedlist; - foreach (reverse @modified) { - push(@modifiedlist, $modified{$_}); + foreach ( reverse @modified ) { + push( @modifiedlist, $modified{$_} ); } - shift(@modifiedlist) while (scalar @modifiedlist > 3); + shift(@modifiedlist) while ( scalar @modifiedlist > 3 ); - &setFactInfo($faqtoid,"modified_by", join(",",@modifiedlist)); - &setFactInfo($faqtoid,"modified_time", time()); + &setFactInfo( $faqtoid, 'modified_by', join( ",", @modifiedlist ) ); + &setFactInfo( $faqtoid, 'modified_time', time() ); return 1; } @@ -75,28 +95,29 @@ sub AddModified { sub CmdLock { my ($faqtoid) = @_; - my $thisnuh = &getFactInfo($faqtoid,"locked_by"); + my $thisnuh = &getFactInfo( $faqtoid, 'locked_by' ); - if (defined $thisnuh and $thisnuh ne "") { - my $locked_by = (split(/\!/,$thisnuh))[0]; - &msg($who,"factoid \002$faqtoid\002 has already been locked by $locked_by."); - return 0; + if ( defined $thisnuh and $thisnuh ne '' ) { + my $locked_by = ( split( /\!/, $thisnuh ) )[0]; + &msg( $who, + "factoid \002$faqtoid\002 has already been locked by $locked_by." ); + return 0; } - $thisnuh ||= &getFactInfo($faqtoid,"created_by"); + $thisnuh ||= &getFactInfo( $faqtoid, 'created_by' ); # fixes bug found on 19991103. # code needs to be reorganised though. - if ($thisnuh ne "") { - if (!&IsHostMatch($thisnuh) && IsFlag("o") ne "o") { - &msg($who, "sorry, you are not allowed to lock '$faqtoid'."); - return 0; - } + if ( $thisnuh ne '' ) { + if ( !&IsHostMatch($thisnuh) && IsFlag('o') ne 'o' ) { + &msg( $who, "sorry, you are not allowed to lock '$faqtoid'." ); + return 0; + } } &performReply("locking factoid \002$faqtoid\002"); - &setFactInfo($faqtoid,"locked_by",$nuh); - &setFactInfo($faqtoid,"locked_time", time()); + &setFactInfo( $faqtoid, 'locked_by', $nuh ); + &setFactInfo( $faqtoid, 'locked_time', time() ); return 1; } @@ -106,23 +127,27 @@ sub CmdLock { sub CmdUnLock { my ($faqtoid) = @_; - my $thisnuh = &getFactInfo($faqtoid,"locked_by"); + my $thisnuh = &getFactInfo( $faqtoid, 'locked_by' ); - if (!defined $thisnuh) { - &msg($who, "factoid \002$faqtoid\002 is not locked."); - return 0; + if ( !defined $thisnuh ) { + &msg( $who, "factoid \002$faqtoid\002 is not locked." ); + return 0; } - if ($thisnuh ne "" and !&IsHostMatch($thisnuh) and &IsFlag("o") ne "o") { - &msg($who, "sorry, you are not allowed to unlock factoid '$faqtoid'."); - return 0; + if ( $thisnuh ne '' and !&IsHostMatch($thisnuh) and &IsFlag('o') ne 'o' ) { + &msg( $who, + "sorry, you are not allowed to unlock factoid '$faqtoid'." ); + return 0; } &performReply("unlocking factoid \002$faqtoid\002"); - &setFactInfo($faqtoid,"locked_by", ""); - &setFactInfo($faqtoid,"locked_time", ""); + &setFactInfo( $faqtoid, 'locked_by', '' ); + &setFactInfo( $faqtoid, 'locked_time', '0' ) + ; # pgsql complains if NOT NULL set. So set 0 which is the default return 1; } 1; + +# vim:ts=4:sw=4:expandtab:tw=80