Sha256: 15d8fbf0691f05008e4975c26e3674450bbb8cceab1476dc2f9fd88c55a9b078

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require 'thor'
require 'whatup/cli/thor_interactive'

module Whatup
  module CLI
    # Server commands
    class Dm < Thor
      extend ThorInteractive

      Room = Whatup::Server::Room
      Client = Whatup::Server::Client

      desc 'msg [NAME]', 'Send a message to [NAME]'
      def msg name
        if recepient = Client.find_by(name: name)
          say <<~MSG
            Sending a direct message to #{name}...

            The message can span multiple lines.

            Type `.exit` when you're ready to send it.
          MSG
          current_user.composing_dm = recepient
          return
        end

        say "That user doesn't exist!"
      end

      desc 'list', 'List your received messages'
      def list
        say 'Your direct messages:'
        msgs = current_user.received_messages.map do |msg|
          <<~MSG
            From: #{msg.sender.name}

            #{msg.content}
          MSG
        end.join('-' * 10)
        say msgs
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
whatup-0.3.4 lib/whatup/cli/commands/interactive/dm.rb
whatup-0.3.3 lib/whatup/cli/commands/interactive/dm.rb
whatup-0.3.2 lib/whatup/cli/commands/interactive/dm.rb
whatup-0.3.1 lib/whatup/cli/commands/interactive/dm.rb
whatup-0.3.0 lib/whatup/cli/commands/interactive/dm.rb