Sha256: 85dd9cabaec43e8d899f883100b7b98a37131dc0ae797354d56deb1d53a459b0

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 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 @info['event_id']
          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(event_id)
        MatrixQQ::Matrix::Send.ignore.delete(event_id)
      end
    end # Forward

    Matrix.join << Forward
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
matrix_qq-0.2.0 lib/matrix_qq/matrix/forward/main.rb
matrix_qq-0.1.1 lib/matrix_qq/matrix/forward/main.rb