Sha256: 4b1f140da82db23b5db8605e95147170399b42d9cb0d0e7ecce924fbf90a5501

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

module MatrixQQ
  class Matrix
    # send matrix massage to other
    class Forward
      class << self
        attr_accessor :send_to
      end
      self.send_to = Hash.new { |h, k| h[k] = [] }

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

      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

      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

      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

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

    Matrix.join << Forward
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
matrix_qq-0.3.3 lib/matrix_qq/matrix/forward/main.rb
matrix_qq-0.3.2 lib/matrix_qq/matrix/forward/main.rb
matrix_qq-0.3.1 lib/matrix_qq/matrix/forward/main.rb
matrix_qq-0.3.0 lib/matrix_qq/matrix/forward/main.rb