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: &IsLocked($faqtoid);
23 my $thisnuh = &getFactInfo($faqtoid, "locked_by");
25 if (defined $thisnuh and $thisnuh ne "") {
26 if (!&IsHostMatch($thisnuh) and &IsFlag("o") ne "o") {
27 &performReply("cannot alter locked factoids");
36 # Usage: &AddModified($faqtoid,$nuh);
38 my ($faqtoid,$nuh) = @_;
39 my $modified_by = &getFactInfo($faqtoid, "modified_by");
40 my (@modifiedlist, @modified, %modified);
42 if (defined $modified_by) {
43 push(@modifiedlist, split(/\,/, $modified_by));
45 push(@modifiedlist,$nuh);
47 foreach (reverse @modifiedlist) {
48 /^(\S+)!(\S+)@(\S+)$/;
50 next if (exists $modified{$nick});
52 $modified{$nick} = $_;
53 push(@modified,$nick);
58 foreach (reverse @modified) {
59 push(@modifiedlist, $modified{$_});
61 shift(@modifiedlist) while (scalar @modifiedlist > 3);
63 &setFactInfo($faqtoid,"modified_by", join(",",@modifiedlist));
64 &setFactInfo($faqtoid,"modified_time", time());
70 ### Commands which use the fundamental functions... Helpers?
74 # Usage: &CmdLock($function,$faqtoid);
78 my $thisnuh = &getFactInfo($faqtoid,"locked_by");
80 if (defined $thisnuh and $thisnuh ne "") {
81 my $locked_by = (split(/\!/,$thisnuh))[0];
82 &msg($who,"factoid \002$faqtoid\002 has already been locked by $locked_by.");
86 $thisnuh ||= &getFactInfo($faqtoid,"created_by");
88 # fixes bug found on 19991103.
89 # code needs to be reorganised though.
91 if (!&IsHostMatch($thisnuh) && IsFlag("o") ne "o") {
92 &msg($who, "sorry, you are not allowed to lock '$faqtoid'.");
97 &performReply("locking factoid \002$faqtoid\002");
98 &setFactInfo($faqtoid,"locked_by",$nuh);
99 &setFactInfo($faqtoid,"locked_time", time());
105 # Usage: &CmdUnLock($faqtoid);
109 my $thisnuh = &getFactInfo($faqtoid,"locked_by");
111 if (!defined $thisnuh) {
112 &msg($who, "factoid \002$faqtoid\002 is not locked.");
116 if ($thisnuh ne "" and !&IsHostMatch($thisnuh) and &IsFlag("o") ne "o") {
117 &msg($who, "sorry, you are not allowed to unlock factoid '$faqtoid'.");
121 &performReply("unlocking factoid \002$faqtoid\002");
122 &setFactInfo($faqtoid,"locked_by", "");
123 &setFactInfo($faqtoid,"locked_time", "");