Class: Whatup::CLI::Interactive
- Inherits:
-
Thor
- Object
- Thor
- Whatup::CLI::Interactive
- 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
- #dm(name) ⇒ Object
- #exit ⇒ Object
- #list ⇒ Object
-
#room(name) ⇒ Object
rubocop:disable Metrics/AbcSize.
Methods included from ThorInteractive
Instance Method Details
#dm(name) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/whatup/cli/commands/interactive/interactive.rb', line 88 def dm name if recepient = Client.find_by(name: name) say " Sending a direct message to \#{name}...\n\n The message can span multiple lines.\n\n Type `.exit` when you're ready to send it.\n MSG\n current_user.composing_dm = recepient\n return\n end\n\n say \"That user doesn't exist!\"\nend\n" |
#exit ⇒ Object
105 106 107 |
# File 'lib/whatup/cli/commands/interactive/interactive.rb', line 105 def exit current_user.exit! end |
#list ⇒ Object
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
rubocop:disable Metrics/AbcSize
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 # rubocop:disable Metrics/AbcSize if room = Room.find_by(name: name) current_user.puts " Entering \#{room.name}... enjoy your stay!\n\n Type `.exit` to exit this chat room.\n\n Currently in this room:\n \#{room.clients.map do |client|\n \"- \#{client.name}\\n\"\n end.join}\n MSG\n current_user.update! room: room\n\n server.clients.reject { |c| c.id == current_user.id }.each do |c|\n c.puts <<~MSG\n \#{current_user.name} has arrived! Play nice, kids.\n MSG\n end\n\n room.clients << current_user\n return\n end\n\n room = server.new_room! name: name, clients: [current_user]\n\n current_user.puts <<~MSG\n Created and entered \#{room.name}... invite some people or something!\n\n Type `.exit` to exit this chat room.\n MSG\nend\n" |