]> git.donarmstrong.com Git - infobot.git/blob - src/Factoids/DBCommon.pl
changed email address
[infobot.git] / src / Factoids / DBCommon.pl
1 #
2 #  DBStubs.pl: DB independent (I hope, heh) factoid support
3 #      Author: dms
4 #     Version: v0.6d (20000223)
5 #     Created: 19991020
6 #
7
8 if (&IsParam("useStrict")) { use strict; }
9
10 #####
11 # Usage: &setFactInfo($faqtoid, $type, $what, ?, ?);
12 sub setFactInfo {
13     &dbSet("factoids", "factoid_key", $_[0], $_[1], $_[2]);
14 }   
15
16 #####
17 # Usage: &IsLocked($faqtoid);
18 sub IsLocked {
19     my ($faqtoid) = @_;
20     my $thisnuh   = &getFactInfo($faqtoid, "locked_by");
21
22     if (defined $thisnuh and $thisnuh ne "") {
23         if (!&IsHostMatch($thisnuh) and &IsFlag("o") ne "o") {
24             &performReply("cannot alter locked factoids");
25             return 1;
26         }
27     }
28
29     return 0;
30 }
31
32 #####
33 # Usage: &AddModified($faqtoid,$nuh);
34 sub AddModified {
35     my ($faqtoid,$nuh) = @_;
36     my $modified_by = &getFactInfo($faqtoid, "modified_by");
37     my (@modifiedlist, @modified, %modified);
38
39     if (defined $modified_by) {
40         push(@modifiedlist, split(/\,/, $modified_by)); 
41     }
42     push(@modifiedlist,$nuh);
43
44     foreach (reverse @modifiedlist) {
45         /^(\S+)!(\S+)@(\S+)$/;
46         my $nick = lc $1;
47         next if (exists $modified{$nick});
48
49         $modified{$nick} = $_;
50         push(@modified,$nick);
51     }
52
53     undef @modifiedlist;
54
55     foreach (reverse @modified) {
56         push(@modifiedlist, $modified{$_});
57     }
58     shift(@modifiedlist) while (scalar @modifiedlist > 3);
59
60     &setFactInfo($faqtoid,"modified_by",   join(",",@modifiedlist));
61     &setFactInfo($faqtoid,"modified_time", time());
62
63     return 1;
64 }
65
66 #####
67 ### Commands which use the fundamental functions... Helpers?
68 #####
69
70 #####
71 # Usage: &CmdLock($function,$faqtoid);
72 sub CmdLock {
73     my ($faqtoid) = @_;
74
75     my $thisnuh = &getFactInfo($faqtoid,"locked_by");
76
77     if (defined $thisnuh and $thisnuh ne "") {
78         my $locked_by = (split(/\!/,$thisnuh))[0];
79         &msg($who,"factoid \002$faqtoid\002 has already been locked by $locked_by.");
80         return 0;
81     }
82
83     $thisnuh ||= &getFactInfo($faqtoid,"created_by");
84
85     # fixes bug found on 19991103.
86     # code needs to be reorganised though.
87     if ($thisnuh ne "") {
88         if (!&IsHostMatch($thisnuh) && IsFlag("o") ne "o") {
89             &msg($who, "sorry, you are not allowed to lock '$faqtoid'.");
90             return 0;
91         }
92     }
93
94     &performReply("locking factoid \002$faqtoid\002");
95     &setFactInfo($faqtoid,"locked_by",$nuh);
96     &setFactInfo($faqtoid,"locked_time", time());
97
98     return 1;
99 }
100
101 #####
102 # Usage: &CmdUnLock($faqtoid);
103 sub CmdUnLock {
104     my ($faqtoid) = @_;
105
106     my $thisnuh = &getFactInfo($faqtoid,"locked_by");
107
108     if (!defined $thisnuh) {
109         &msg($who, "factoid \002$faqtoid\002 is not locked.");
110         return 0;
111     }
112
113     if ($thisnuh ne "" and !&IsHostMatch($thisnuh) and &IsFlag("o") ne "o") {
114         &msg($who, "sorry, you are not allowed to unlock factoid '$faqtoid'.");
115         return 0;
116     }
117
118     &performReply("unlocking factoid \002$faqtoid\002");
119     &setFactInfo($faqtoid,"locked_by",   "");
120     &setFactInfo($faqtoid,"locked_time", "");
121
122     return 1;
123 }
124
125 1;