Class: MatrixQQ::Matrix::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/matrix_qq/matrix/log.rb

Overview

Log message to stdout

Instance Method Summary collapse

Constructor Details

#initialize(dbus, _, info) ⇒ Log

Returns a new instance of Log.



5
6
7
8
# File 'lib/matrix_qq/matrix/log.rb', line 5

def initialize(dbus, _, info)
  @dbus = dbus
  @info = info
end

Instance Method Details

#log_message(sender, content) ⇒ Object



21
22
23
24
# File 'lib/matrix_qq/matrix/log.rb', line 21

def log_message(sender, content)
  message = content['msgtype'] == 'm.text' ? content['body'] : content
  puts "#{sender}: #{message}"
end

#log_room(room) ⇒ Object



26
27
28
# File 'lib/matrix_qq/matrix/log.rb', line 26

def log_room(room)
  puts "#{self.room(room)['name']}:"
end

#room(room) ⇒ Object



30
31
32
# File 'lib/matrix_qq/matrix/log.rb', line 30

def room(room)
  @dbus.get "/rooms/#{room}/state/m.room.name"
end

#runObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/matrix_qq/matrix/log.rb', line 10

def run
  return unless @info.is_a? Hash
  @info.each_pair do |room, events|
    log_room room
    events['timeline']['events'].each do |event|
      next unless event['type'] == 'm.room.message'
      log_message event['sender_name'], event['content']
    end
  end
end