diff options
author | Matthias Hecker <apoc@geekosphere.org> | 2015-06-21 00:05:38 +0200 |
---|---|---|
committer | Matthias Hecker <apoc@geekosphere.org> | 2015-06-21 00:05:38 +0200 |
commit | 5d98c9493ba069a0df7345157236caa938f9dcb2 (patch) | |
tree | c7c63ac629a7b5a9350c77c8ee0d6207587b83c0 /lib/rbot | |
parent | 732f8df5966f4b85ffe19e045e9aeccc35206fab (diff) |
journal: irc logging module
Diffstat (limited to 'lib/rbot')
-rw-r--r-- | lib/rbot/core/journal_irclog.rb | 131 | ||||
-rw-r--r-- | lib/rbot/journal.rb | 2 |
2 files changed, 133 insertions, 0 deletions
diff --git a/lib/rbot/core/journal_irclog.rb b/lib/rbot/core/journal_irclog.rb new file mode 100644 index 00000000..37baab45 --- /dev/null +++ b/lib/rbot/core/journal_irclog.rb @@ -0,0 +1,131 @@ +#-- vim:sw=2:et +#++ +# +# :title: irc logging into the journal +# +# Author:: Matthias Hecker (apoc@geekosphere.org) + +class JournalIrcLogModule < CoreBotModule + + include Irc::Bot::Journal + + Config.register Config::ArrayValue.new('journal.irclog.whitelist', + :default => [], + :desc => 'only perform journal irc logging for those channel/users') + + Config.register Config::ArrayValue.new('journal.irclog.blacklist', + :default => [], + :desc => 'exclude journal irc logging for those channel/users') + + def irclog(payload) + if payload[:target] + target = payload[:target] + whitelist = @bot.config['journal.irclog.whitelist'] + blacklist = @bot.config['journal.irclog.blacklist'] + unless whitelist.empty? + return unless whitelist.include? target + end + unless blacklist.empty? + return if blacklist.include? target + end + end + @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 + else + irclog type: 'privmsg', source: m.source, target: m.target, message: m.message, server: m.server + 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 + 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 + end + +end + +plugin = JournalIrcLogModule.new +# make sure the logger gets loaded after the journal +plugin.priority = -1 + diff --git a/lib/rbot/journal.rb b/lib/rbot/journal.rb index 8d897929..0903fc9f 100644 --- a/lib/rbot/journal.rb +++ b/lib/rbot/journal.rb @@ -77,6 +77,8 @@ module Journal end def self.create(topic, payload, opt={}) + # cleanup payload to only contain strings + payload = payload.map { |k, v| [k.to_s, v.to_s] }.to_h JournalMessage.new( id: opt[:id] || SecureRandom.uuid, timestamp: opt[:timestamp] || Time.now, |