Class: MatrixQQ::Matrix::Log
- Inherits:
-
Object
- Object
- MatrixQQ::Matrix::Log
- Defined in:
- lib/matrix_qq/matrix/log.rb
Overview
Log message to stdout
Instance Method Summary collapse
-
#initialize(dbus, _, info) ⇒ Log
constructor
A new instance of Log.
- #log_message(sender, content) ⇒ Object
- #log_room(room) ⇒ Object
- #match_bot(message) ⇒ Object
- #room(room) ⇒ Object
- #run ⇒ Object
- #user(user) ⇒ Object
- #user_bot(message) ⇒ Object
- #user_bot?(message) ⇒ Boolean
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 25 26 27 28 29 30 |
# File 'lib/matrix_qq/matrix/log.rb', line 21 def (sender, content) name = user sender if content['msgtype'] == 'm.text' = content['body'] name, = user_bot if user_bot? else = content end puts "#{name}: #{message}" end |
#log_room(room) ⇒ Object
32 33 34 |
# File 'lib/matrix_qq/matrix/log.rb', line 32 def log_room(room) puts "#{self.room(room)['name']}:" end |
#match_bot(message) ⇒ Object
44 45 46 |
# File 'lib/matrix_qq/matrix/log.rb', line 44 def match_bot() .match(/^(\(.*?\))?\[(.*?)\]\s*/) end |
#room(room) ⇒ Object
36 37 38 |
# File 'lib/matrix_qq/matrix/log.rb', line 36 def room(room) @dbus.get "/rooms/#{room}/state/m.room.name" end |
#run ⇒ Object
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' event['sender'], event['content'] end end end |
#user(user) ⇒ Object
40 41 42 |
# File 'lib/matrix_qq/matrix/log.rb', line 40 def user(user) @dbus.get("/profile/#{user}/displayname")['displayname'] end |
#user_bot(message) ⇒ Object
54 55 56 57 58 |
# File 'lib/matrix_qq/matrix/log.rb', line 54 def user_bot() m = match_bot return unless m [m[2], m.post_match] end |
#user_bot?(message) ⇒ Boolean
48 49 50 51 52 |
# File 'lib/matrix_qq/matrix/log.rb', line 48 def user_bot?() m = match_bot return true if m false end |