2 # DBStubs.pl: DB independent (I hope, heh) factoid support
4 # Version: v0.6d (20000223)
11 # Usage: &setFactInfo($faqtoid, $key, $val);
14 { factoid_key => $_[0] },
15 { $_[1] => $_[2] } # dbquote done in dbset!
20 # Usage: &getFactInfo($faqtoid, [$what]);
22 return &dbGet("factoids", $_[1], "factoid_key=".&dbQuote($_[0]) );
26 # Usage: &getFactoid($faqtoid);
28 return &getFactInfo($_[0], "factoid_value");
32 # Usage: &delFactoid($faqtoid);
36 &dbDel("factoids", "factoid_key",$faqtoid);
37 &status("DELETED $faqtoid");
43 # Usage: &IsLocked($faqtoid);
46 my $thisnuh = &getFactInfo($faqtoid, "locked_by");
48 if (defined $thisnuh and $thisnuh ne "") {
49 if (!&IsHostMatch($thisnuh) and &IsFlag("o") ne "o") {
50 &performReply("cannot alter locked factoids");
59 # Usage: &AddModified($faqtoid,$nuh);
61 my ($faqtoid,$nuh) = @_;
62 my $modified_by = &getFactInfo($faqtoid, "modified_by");
63 my (@modifiedlist, @modified, %modified);
65 if (defined $modified_by) {
66 push(@modifiedlist, split(/\,/, $modified_by));
68 push(@modifiedlist,$nuh);
70 foreach (reverse @modifiedlist) {
71 /^(\S+)!(\S+)@(\S+)$/;
73 next if (exists $modified{$nick});
75 $modified{$nick} = $_;
76 push(@modified,$nick);
81 foreach (reverse @modified) {
82 push(@modifiedlist, $modified{$_});
84 shift(@modifiedlist) while (scalar @modifiedlist > 3);
86 &setFactInfo($faqtoid,"modified_by", join(",",@modifiedlist));
87 &setFactInfo($faqtoid,"modified_time", time());
93 ### Commands which use the fundamental functions... Helpers?
97 # Usage: &CmdLock($function,$faqtoid);
101 my $thisnuh = &getFactInfo($faqtoid,"locked_by");
103 if (defined $thisnuh and $thisnuh ne "") {
104 my $locked_by = (split(/\!/,$thisnuh))[0];
105 &msg($who,"factoid \002$faqtoid\002 has already been locked by $locked_by.");
109 $thisnuh ||= &getFactInfo($faqtoid,"created_by");
111 # fixes bug found on 19991103.
112 # code needs to be reorganised though.
113 if ($thisnuh ne "") {
114 if (!&IsHostMatch($thisnuh) && IsFlag("o") ne "o") {
115 &msg($who, "sorry, you are not allowed to lock '$faqtoid'.");
120 &performReply("locking factoid \002$faqtoid\002");
121 &setFactInfo($faqtoid,"locked_by",$nuh);
122 &setFactInfo($faqtoid,"locked_time", time());
128 # Usage: &CmdUnLock($faqtoid);
132 my $thisnuh = &getFactInfo($faqtoid,"locked_by");
134 if (!defined $thisnuh) {
135 &msg($who, "factoid \002$faqtoid\002 is not locked.");
139 if ($thisnuh ne "" and !&IsHostMatch($thisnuh) and &IsFlag("o") ne "o") {
140 &msg($who, "sorry, you are not allowed to unlock factoid '$faqtoid'.");
144 &performReply("unlocking factoid \002$faqtoid\002");
145 &setFactInfo($faqtoid,"locked_by", "");
146 &setFactInfo($faqtoid,"locked_time", "");