]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - lib/rbot/core/journal.rb
Merge pull request #4 from ahpook/rename_karma
[user/henk/code/ruby/rbot.git] / lib / rbot / core / journal.rb
1 #-- vim:sw=2:et
2 #++
3 #
4 # :title: rbot journal management from IRC
5 #
6 # Author:: Matthias Hecker (apoc@geekosphere.org)
7
8 require 'rbot/journal'
9
10 module ::Irc
11 class Bot
12   # this should return the journal if the managing plugin has been loaded.
13   def journal
14     if @plugins['journal']
15       @plugins['journal'].broker
16     end
17   end
18 end
19 end
20
21 class JournalModule < CoreBotModule
22
23   attr_reader :broker
24
25   include Irc::Bot::Journal
26
27   Config.register Config::StringValue.new('journal.storage',
28     :default => nil,
29     :requires_rescan => true,
30     :desc => 'storage engine used by the journal')
31   Config.register Config::StringValue.new('journal.storage.uri',
32     :default => nil,
33     :requires_rescan => true,
34     :desc => 'storage database uri')
35
36   def initialize
37     super
38     storage = nil
39     name = @bot.config['journal.storage']
40     uri = @bot.config['journal.storage.uri']
41     if name
42       begin
43         storage = Storage.create(name, uri)
44       rescue
45         error 'journal storage initialization error!'
46         error $!
47         error $@.join("\n")
48       end
49     end
50     debug 'journal broker starting up...'
51     @broker = JournalBroker.new(storage: storage)
52   end
53
54   def cleanup
55     super
56     debug 'journal broker shutting down...'
57     @broker.shutdown
58     @broker = nil
59   end
60
61   def help(plugin, topic='')
62     'journal'
63   end
64
65 end
66
67 journal = JournalModule.new
68 journal.priority = -2
69