Permalink
Browse files

Move logging to a script

  • Loading branch information...
1 parent 774b22f commit 7fab8e0ab751a9a0f18bc750592d52c281af4750 @hagabaka committed Mar 28, 2012
Showing with 17 additions and 22 deletions.
  1. +1 −1 README.rdoc
  2. +5 −21 lib/quassel/client.rb
  3. +11 −0 lib/quassel/scripts/log.rb
View
@@ -23,6 +23,6 @@ Ruby scripts to send and respond to IRC messages and events.
- running Quassel core
- qtruby
- bindata
-- matchmaker
+- case
- eventful
View
@@ -1,9 +1,11 @@
require 'quassel/connection'
-require 'matchmaker'
require 'helpers'
+require 'eventful'
module Quassel
class Client
+ include Eventful
+
def initialize(username, password, host = nil, port = nil)
connection = Connection.new(host, port)
@@ -22,30 +24,12 @@ def initialize(username, password, host = nil, port = nil)
Password: password
end
- connection.on :message_received do |c, message|
- Case message do
- of [Quassel::RPC_CALL, '2displayMsg(Message)', _] do
- puts Quassel::Client.format_message('%{timestamp} %{buffer.name} %{sender} %{content}', message[2])
- require 'pry'
- end
- of _ do
- p message
- end
- end
+ connection.on :message_received do |_, message|
+ fire :message_received, message
end
connection.connect
end
-
- def self.format_message(format, message)
- hash = {}
- format.scan(/%\{([^}]+)}/) do |(key)|
- hash[key.to_sym] = key.split('.').inject(message) do |result, part|
- result.send part
- end
- end
- format % hash
- end
end
end
View
@@ -0,0 +1,11 @@
+require 'case'
+require 'Qt'
+
+DISPLAY_MESSAGE = Qt::ByteArray.new('2displayMsg(Message)')
+
+Quassel::Client::INSTANCE.on :message_received do |_, message|
+ if Case[Quassel::RPC_CALL, DISPLAY_MESSAGE, Case::Any] === message
+ m = message[2]
+ puts "#{m.timestamp} #{m.buffer.name} #{m.sender} #{m.content}"
+ end
+end

0 comments on commit 7fab8e0

Please sign in to comment.