2 # DBStubs.pl: DB independent (I hope, heh) factoid support
4 # Version: v0.6d (20000223)
8 if (&IsParam("useStrict")) { use strict; }
11 # Usage: &setFactInfo($faqtoid, $type, $primval, $key, $val);
14 { factoid_key => $_[0] },
15 { $_[1] => $_[2] } # dbquote done in dbset!
20 # Usage: &getFactInfo($faqtoid, [$what]);
21 sub main::getFactInfo {
22 return &dbGet("factoids", $_[1], "factoid_key=".&dbQuote($_[0]) );
26 # Usage: &getFactoid($faqtoid);
27 sub main::getFactoid {
28 return &getFactInfo($_[0], "factoid_value");
32 # Usage: &setFactInfo($faqtoid, $type, $what);
33 sub main::setFactInfo {
34 &dbSet("factoids", "factoid_key", $_[0], $_[1], $_[2]);
38 # Usage: &delFactoid($faqtoid);
39 sub main::delFactoid {
42 &dbDel("factoids", "factoid_key",$faqtoid);
43 &status("DELETED $faqtoid");
49 # Usage: &IsLocked($faqtoid);
52 my $thisnuh = &getFactInfo($faqtoid, "locked_by");
54 if (defined $thisnuh and $thisnuh ne "") {
55 if (!&IsHostMatch($thisnuh) and &IsFlag("o") ne "o") {
56 &performReply("cannot alter locked factoids");
65 # Usage: &AddModified($faqtoid,$nuh);
67 my ($faqtoid,$nuh) = @_;
68 my $modified_by = &getFactInfo($faqtoid, "modified_by");
69 my (@modifiedlist, @modified, %modified);
71 if (defined $modified_by) {
72 push(@modifiedlist, split(/\,/, $modified_by));
74 push(@modifiedlist,$nuh);
76 foreach (reverse @modifiedlist) {
77 /^(\S+)!(\S+)@(\S+)$/;
79 next if (exists $modified{$nick});
81 $modified{$nick} = $_;
82 push(@modified,$nick);
87 foreach (reverse @modified) {
88 push(@modifiedlist, $modified{$_});
90 shift(@modifiedlist) while (scalar @modifiedlist > 3);
92 &setFactInfo($faqtoid,"modified_by", join(",",@modifiedlist));
93 &setFactInfo($faqtoid,"modified_time", time());
99 ### Commands which use the fundamental functions... Helpers?
103 # Usage: &CmdLock($function,$faqtoid);
107 my $thisnuh = &getFactInfo($faqtoid,"locked_by");
109 if (defined $thisnuh and $thisnuh ne "") {
110 my $locked_by = (split(/\!/,$thisnuh))[0];
111 &msg($who,"factoid \002$faqtoid\002 has already been locked by $locked_by.");
115 $thisnuh ||= &getFactInfo($faqtoid,"created_by");
117 # fixes bug found on 19991103.
118 # code needs to be reorganised though.
119 if ($thisnuh ne "") {
120 if (!&IsHostMatch($thisnuh) && IsFlag("o") ne "o") {
121 &msg($who, "sorry, you are not allowed to lock '$faqtoid'.");
126 &performReply("locking factoid \002$faqtoid\002");
127 &setFactInfo($faqtoid,"locked_by",$nuh);
128 &setFactInfo($faqtoid,"locked_time", time());
134 # Usage: &CmdUnLock($faqtoid);
138 my $thisnuh = &getFactInfo($faqtoid,"locked_by");
140 if (!defined $thisnuh) {
141 &msg($who, "factoid \002$faqtoid\002 is not locked.");
145 if ($thisnuh ne "" and !&IsHostMatch($thisnuh) and &IsFlag("o") ne "o") {
146 &msg($who, "sorry, you are not allowed to unlock factoid '$faqtoid'.");
150 &performReply("unlocking factoid \002$faqtoid\002");
151 &setFactInfo($faqtoid,"locked_by", "");
152 &setFactInfo($faqtoid,"locked_time", "");