Sha256: 5663f102cb25b6c0484837dfaf4822e352f025ef9f1f79dd8fc77a588ef23fa7

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

module MatrixQQ
  class QQ
    # Log message to stdout
    class Log
      def initialize(dbus, _, info)
        @dbus = dbus
        @info = info
      end

      def run
        return unless @info.is_a? Hash
        log_room @info['group_id'] if @info.key? 'group_id'
        msg = message @info['message']
        sender = user @info['user_id'], @info['group_id']
        log_message sender, msg
      end

      def message(messages)
        messages.inject('') do |obj, msg|
          obj + case msg['type']
                when 'at' then "@#{user msg['data']['qq'], @info['group_id']} "
                else QQ.cq_call msg
                end
        end
      end

      def log_message(name, message)
        puts "#{name}: #{message}"
      end

      def log_room(groupid)
        puts "#{room(groupid)}:"
      end

      def room(groupid)
        groupid
      end

      def user(user, group_id = nil)
        if group_id.nil?
          return @dbus.get_stranger_info(user_id: user)['nickname']
        end
        info = @dbus.get_group_member_info(user_id: user, group_id: group_id)
        info = info['data']
        name = info['card']
        name == '' ? info['nickname'] : name
      end
    end # Log

    QQ.message << Log
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
matrix_qq-0.5.5 lib/matrix_qq/qq/log.rb
matrix_qq-0.5.4 lib/matrix_qq/qq/log.rb
matrix_qq-0.5.3 lib/matrix_qq/qq/log.rb
matrix_qq-0.5.2 lib/matrix_qq/qq/log.rb
matrix_qq-0.5.1 lib/matrix_qq/qq/log.rb
matrix_qq-0.5.0 lib/matrix_qq/qq/log.rb
matrix_qq-0.4.0 lib/matrix_qq/qq/log.rb
matrix_qq-0.3.3 lib/matrix_qq/qq/log.rb
matrix_qq-0.3.2 lib/matrix_qq/qq/log.rb
matrix_qq-0.3.1 lib/matrix_qq/qq/log.rb
matrix_qq-0.3.0 lib/matrix_qq/qq/log.rb