Skip to content

Instantly share code, notes, and snippets.

@resure
Created July 12, 2013 01:51
Show Gist options
  • Select an option

  • Save resure/5980840 to your computer and use it in GitHub Desktop.

Select an option

Save resure/5980840 to your computer and use it in GitHub Desktop.
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