Sha256: a0a3d73c7b29a52d177bdd2bd36551df6a5630d5b91f640721a46f297f0c39e8

Contents?: true

Size: 598 Bytes

Versions: 2

Compression:

Stored size: 598 Bytes

Contents

class ConsoleAdapter
  CLIENT_ID = "CONSOLE"

  def initialize(name: "@socrates")
    @name = name
  end

  def client_id_from_context(_context)
    CLIENT_ID
  end

  def send_message(message, *)
    puts "\n#{colorize(@name, "32;1")}: #{message}"
  end

  def send_direct_message(message, user, *)
    name =
      if user.respond_to?(:name)
        user.name
      elsif user.respond_to?(:id)
        user.id
      else
        user
      end

    puts "\n[DM] #{colorize(name, "34;1")}: #{message}"
  end

  private

  def colorize(str, color_code)
    "\e[#{color_code}m#{str}\e[0m"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
socrates-0.1.1 lib/socrates/adapters/console_adapter.rb
socrates-0.1.0 lib/socrates/adapters/console_adapter.rb