Class: Whatup::CLI::Interactive

Inherits:
Thor
  • Object
show all
Extended by:
ThorInteractive
Defined in:
lib/whatup/cli/commands/interactive/interactive.rb

Overview

Interactive client commands that are available after connecting

This class is run on the server

Constant Summary collapse

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

Instance Method Summary collapse

Methods included from ThorInteractive

banner, extended

Instance Method Details

#exitObject



88
89
90
# File 'lib/whatup/cli/commands/interactive/interactive.rb', line 88

def exit
  current_user.exit!
end

#listObject



47
48
49
50
51
# File 'lib/whatup/cli/commands/interactive/interactive.rb', line 47

def list
  say 'All connected clients:'
  server.clients_except(current_user).each { |c| say "  #{c.status}" }
  say "* #{current_user.status}"
end

#room(name) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/whatup/cli/commands/interactive/interactive.rb', line 54

def room name
  if room = Room.find_by(name: name)
    current_user.puts <<~MSG
      Entering #{room.name}... enjoy your stay!

      Type `.exit` to exit this chat room.

      Currently in this room:
      #{room.clients.map do |client|
          "- #{client.name}\n"
        end.join}
    MSG
    current_user.update! room: room

    server.clients.reject { |c| c.id == current_user.id }.each do |c|
      c.puts <<~MSG
        #{current_user.name} has arrived! Play nice, kids.
      MSG
    end

    room.clients << current_user
    return
  end

  room = server.new_room! name: name, clients: [current_user]

  current_user.puts <<~MSG
    Created and entered #{room.name}... invite some people or something!

    Type `.exit` to exit this chat room.
  MSG
end