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

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.



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

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

Class Attribute Details

.send_toObject

Returns the value of attribute send_to.



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

def send_to
  @send_to
end

Instance Method Details

#call_module(event, room, type) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/matrix_qq/matrix/forward/main.rb', line 53

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, hackin = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/matrix_qq/matrix/forward/main.rb', line 42

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

#exist(forword) ⇒ Object



61
62
63
64
# File 'lib/matrix_qq/matrix/forward/main.rb', line 61

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

#runObject



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

def run
  return unless @info.is_a? Hash
  @info.each_pair do |room, value|
    all = run_exact room, value
    run_all room, value if all
  end
end

#run_all(room, value) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/matrix_qq/matrix/forward/main.rb', line 31

def run_all(room, value)
  tunnel = Config[:tunnel]['matrix']
  return if tunnel.nil?
  return unless tunnel[:type] == 'all'
  each_event \
    value['timeline']['events'],
    tunnel,
    'print_room' => true,
    'send_room' => room
end

#run_exact(room, value) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/matrix_qq/matrix/forward/main.rb', line 23

def run_exact(room, value)
  tunnel = Config[:tunnel][room]
  return false if tunnel.nil?
  return false unless tunnel[:type] == 'matrix'
  each_event value['timeline']['events'], tunnel
  MatrixQQ.intercept? tunnel
end