Class: MatrixQQ::Matrix::Forward

Inherits:
Object
  • Object
show all
Defined in:
lib/matrix_qq/matrix/forward/main.rb,
lib/matrix_qq/matrix/forward/group.rb

Overview

send matrix massage to other

Defined Under Namespace

Classes: Group

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dbus, qq, info) ⇒ Forward

Returns a new instance of Forward.



10
11
12
13
14
# File 'lib/matrix_qq/matrix/forward/main.rb', line 10

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

Class Attribute Details

.send_toObject

Returns the value of attribute send_to.



6
7
8
# File 'lib/matrix_qq/matrix/forward/main.rb', line 6

def send_to
  @send_to
end

Instance Method Details

#call_module(event, room, type) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/matrix_qq/matrix/forward/main.rb', line 36

def call_module(event, room, type)
  Forward.send_to[type.to_s].each do |func|
    puts "Start #{func.name}" if $VERBOSE
    func.new(@dbus, @qq, event, room).run
    puts "End #{func.name}" if $VERBOSE
  end
end

#each_event(events, tunnel) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/matrix_qq/matrix/forward/main.rb', line 26

def each_event(events, tunnel)
  events.each do |event|
    next unless event['type'] == 'm.room.message'
    next if exist event['content']['forword']
    tunnel[:to].each_pair do |to_room, type|
      call_module(event, to_room, type)
    end
  end
end

#exist(forword) ⇒ Object



44
45
46
47
# File 'lib/matrix_qq/matrix/forward/main.rb', line 44

def exist(forword)
  return false if forword.nil?
  !forword
end

#runObject



16
17
18
19
20
21
22
23
24
# File 'lib/matrix_qq/matrix/forward/main.rb', line 16

def run
  return unless @info.is_a? Hash
  @info.each_pair do |room, value|
    tunnel = Config[:tunnel][room]
    next if tunnel.nil?
    next unless tunnel[:type] == 'matrix'
    each_event value['timeline']['events'], tunnel
  end
end