Created
July 12, 2013 01:51
-
-
Save resure/5980840 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Logger | |
| include Cinch::Plugin | |
| listen_to :connect, method: :setup | |
| # listen_to :disconnect, method: :cleanup | |
| listen_to :channel, method: :log_message | |
| listen_to :topic, method: :log_topic | |
| listen_to :action, method: :log_action | |
| listen_to :leaving, method: :log_leaving | |
| listen_to :join, method: :log_join | |
| def setup(*) | |
| @db = DB[:messages] | |
| end | |
| def log_message msg | |
| return if msg.message.start_with? "\u0001" | |
| @db.insert created_at: Time.now, | |
| nickname: msg.user.nick, | |
| authname: (msg.user.authed? ? msg.user.authname : ''), | |
| content: msg.message, | |
| type: 'msg', | |
| channel: msg.channel.to_s | |
| end | |
| def log_topic msg | |
| @db.insert created_at: Time.now, | |
| nickname: msg.user.nick, | |
| authname: (msg.user.authed? ? msg.user.authname : ''), | |
| content: msg.channel.topic, | |
| type: 'topic', | |
| channel: msg.channel.to_s | |
| end | |
| def log_action msg | |
| return unless msg.message =~ /^\u0001ACTION(.*?)\u0001/ | |
| @db.insert created_at: Time.now, | |
| nickname: msg.user.nick, | |
| authname: (msg.user.authed? ? msg.user.authname : ''), | |
| content: $1.strip, | |
| type: 'action', | |
| channel: msg.channel.to_s | |
| end | |
| def log_join msg | |
| @db.insert created_at: Time.now, | |
| nickname: msg.user.nick, | |
| authname: (msg.user.authed? ? msg.user.authname : ''), | |
| type: 'join', | |
| channel: msg.channel.to_s | |
| end | |
| def log_leaving msg, user | |
| @db.insert created_at: Time.now, | |
| nickname: user.nick, | |
| authname: (user.authed? ? user.authname : ''), | |
| type: 'leaving', | |
| channel: msg.channel.to_s | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment