5 # Configure this to the location of your kharma database.
6 my $kharma_db = "/var/tmp/kharma.db";
8 # This should probably be a real Perl module ...
9 require "/usr/share/monolith-chat/bots/chatbotlib.pl";
13 # Get a list of all rooms.
14 my @rooms = cb_get_all_rooms ();
18 dbmopen %kharma, $kharma_db, 0666;
22 # Get next posting message.
23 my $msg = cb_wait_message (rooms => \@rooms,
24 msgtypes => CB_POSTING);
25 my $userid = $msg->{userid};
26 my $resid = $msg->{resid};
27 my $text = $msg->{text};
29 # Only ordinary users are allowed to change kharma.
32 # Does it contain [some word]++ or [some word]--?
33 change_kharma ($_, 1, $resid, $userid)
34 foreach (map { lc } ($text =~ m/\b([-\w.]+)\+\+\b/g));
35 change_kharma ($_, -1, $resid, $userid)
36 foreach (map { lc } ($text =~ m/\b([-\w.]+)--\b/g));
39 # User is asking for the ranking of a particular word.
40 if ($text =~ /^rank\s+([-\w.]+)\s*$/i)
44 if (! exists $kharma{$word})
48 text => "$word has no kharma");
52 my $k = $kharma{$word};
58 text => "$word has 1 point of kharma");
64 text => "$word has $k points of kharma");
78 if (! exists $kharma{$word})
83 # XXX Check that users don't change kharma too frequently.
84 $kharma{$word} += $change;
85 my $k = $kharma{$word};
90 delete $kharma{$word};
94 text => "$word has no kharma and has been garbage collected");
100 text => "$word has 1 point of kharma");
106 text => "$word has $k points of kharma");