diff options
-rw-r--r-- | lib/rbot/core/journal.rb | 8 | ||||
-rw-r--r-- | lib/rbot/core/journal_irclog.rb | 108 | ||||
-rw-r--r-- | lib/rbot/journal.rb | 1 | ||||
-rw-r--r-- | lib/rbot/journal/postgres.rb | 1 |
4 files changed, 33 insertions, 85 deletions
diff --git a/lib/rbot/core/journal.rb b/lib/rbot/core/journal.rb index f8a88620..4bd4ec3c 100644 --- a/lib/rbot/core/journal.rb +++ b/lib/rbot/core/journal.rb @@ -28,7 +28,13 @@ class JournalModule < CoreBotModule name = @bot.config['journal.storage'] uri = @bot.config['journal.storage.uri'] if name - storage = Storage.create(name, uri) + begin + storage = Storage.create(name, uri) + rescue + error 'journal storage initialization error!' + error $! + error $@.join("\n") + end end debug 'journal broker starting up...' @broker = JournalBroker.new(storage: storage) diff --git a/lib/rbot/core/journal_irclog.rb b/lib/rbot/core/journal_irclog.rb index 37baab45..0617d991 100644 --- a/lib/rbot/core/journal_irclog.rb +++ b/lib/rbot/core/journal_irclog.rb @@ -17,7 +17,7 @@ class JournalIrcLogModule < CoreBotModule :default => [], :desc => 'exclude journal irc logging for those channel/users') - def irclog(payload) + def publish(payload) if payload[:target] target = payload[:target] whitelist = @bot.config['journal.irclog.whitelist'] @@ -32,97 +32,37 @@ class JournalIrcLogModule < CoreBotModule @bot.journal.publish('irclog', payload) end - # messages sent by the bot - def sent(m) - case m - when NoticeMessage - irclog type: 'notice', source: m.source, target: m.target, message: m.message, server: m.server - when PrivMessage - if m.ctcp - irclog type: 'ctcp', source: m.source, target: m.target, ctcp: m.ctcp, message: m.message, server: m.server - else - irclog type: 'privmsg', source: m.source, target: m.target, message: m.message, server: m.server - end - when QuitMessage - m.was_on.each { |ch| - irclog type: 'quit', source: m.source, target: ch, message: m.message, server: m.server - } - end - end - - # messages received from other clients - def listen(m) - case m - when PrivMessage - method = 'log_message' - else - method = 'log_' + m.class.name.downcase.match(/^irc::(\w+)message$/).captures.first - end - if self.respond_to?(method) - self.__send__(method, m) - else - warning 'unhandled journal irc logging for ' + method - end - end - def log_message(m) - if m.ctcp - irclog type: 'ctcp', source: m.source, target: m.target, ctcp: m.ctcp, message: m.message, server: m.server + unless m.kind_of? BasicUserMessage + warning 'journal irc logger can\'t log %s message' % [m.class.to_s] else - irclog type: 'privmsg', source: m.source, target: m.target, message: m.message, server: m.server + payload = { + type: m.class.name.downcase.match(/(\w+)message/).captures.first, + addressed: m.address?, + replied: m.replied?, + identified: m.identified?, + + source: m.source.to_s, + source_user: m.botuser.to_s, + source_address: m.sourceaddress, + target: m.target.to_s, + server: m.server.to_s, + + message: m.logmessage, + } + publish(payload) end end - def log_notice(m) - irclog type: 'notice', source: m.source, target: m.target, message: m.message, server: m.server - end - - def motd(m) - irclog type: 'motd', source: m.server, target: m.target, message: m.message, server: m.server - end - - def log_nick(m) - (m.is_on & @bot.myself.channels).each { |ch| - irclog type: 'nick', old: m.oldnick, new: m.newnick, target: ch, server: m.server - } - end - - def log_quit(m) - (m.was_on & @bot.myself.channels).each { |ch| - irclog type: 'quit', source: m.source, target: ch, message: m.message, server: m.server - } - end - - def modechange(m) - irclog type: 'mode', source: m.source, target: m.target, mode: m.message, server: m.server - end - - def log_join(m) - irclog type: 'join', source: m.source, target: m.channel, server: m.server - end - - def log_part(m) - irclog type: 'part', source: m.source, target: m.channel, message: m.message, server: m.server - end - - def log_kick(m) - irclog type: 'kick', source: m.source, target: m.channel, kicked: m.target, message: m.message, server: m.server - end - - def log_invite(m) - irclog type: 'invite', source: m.source, target: m.target, message: m.message, server: m.server + # messages sent + def sent(m) + log_message(m) end - def log_topic(m) - case m.info_or_set - when :set - irclog type: 'topic', source: m.source, target: m.channel, message: m.topic, server: m.server - when :info - topic = m.channel.topic - irclog type: 'topic_info', source: topic.set_by, target: m.channel, set_on: topic.set_on, message: m.topic, server: m.server - end + # messages received + def listen(m) + log_message(m) end - end plugin = JournalIrcLogModule.new diff --git a/lib/rbot/journal.rb b/lib/rbot/journal.rb index 0903fc9f..9f586f7f 100644 --- a/lib/rbot/journal.rb +++ b/lib/rbot/journal.rb @@ -345,6 +345,7 @@ module Journal end def publish(topic, payload) + debug 'journal publish message in %s: %s' % [topic, payload.inspect] @queue << JournalMessage::create(topic, payload) nil end diff --git a/lib/rbot/journal/postgres.rb b/lib/rbot/journal/postgres.rb index 62590110..87a59306 100644 --- a/lib/rbot/journal/postgres.rb +++ b/lib/rbot/journal/postgres.rb @@ -55,6 +55,7 @@ module Journal end @jsonb = (version >= 940) log 'journal storage: no jsonb support, consider upgrading postgres' unless @jsonb + log 'journal storage: postgres backend is using JSONB :)' if @jsonb drop if opts[:drop] create_table |