Jelajahi Sumber

Improve `help` and `questions` commands

Weiyi Lou 10 tahun lalu
induk
melakukan
ee15f70f22
1 mengubah file dengan 20 tambahan dan 10 penghapusan
  1. 20 10
      js/pgsh.js

+ 20 - 10
js/pgsh.js

@@ -6,7 +6,7 @@ Linux parsleygardens.net 3.4.5-6-7-i286 #8 PGS Vimputer 3.4.56-7 i286 \n\
 ~ Welcome to Parsley Gardens! ~\n\
 "He maketh me to lie down in green pa..."\n\
 \n\
-Type "help" for list of commands\n\
+Type `help` for list of commands\n\
 \n'
   this.commands = {
     'about': {
@@ -103,37 +103,47 @@ Type "help" for list of commands\n\
             if (!this.running) {
               this.running = true
               terminal.display.hide()
-              terminal.display.add('Welcome to the questions. Do you wish to continue?')
+              terminal.display.add('Welcome to the questions. Do you want to continue?')
               terminal.commandline.hidePrompt()
               return
             }
             if (input != 'exit') {
-              terminal.display.set('You answered the last question with "' + input + '"!\nWould you like another question?\n(Type "exit" to end)')
+              terminal.display.set('You answered with "' + input + '"!\nNext question!\n<span style="color:#555">(Type "exit" to end)</span>\n\n')
+              var rand = Math.floor(Math.random() * this.questions.length);
+              terminal.display.add(this.questions[rand])
             } else {
-              this.running = false
               terminal.display.restore()
               terminal.display.add('Thanks for answering questions!')
               terminal.commandline.showPrompt()
               terminal.returnToShell()
             }
-          }
+          },
+          'questions': [
+            'Isn\'t <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ" target="_blank">this song</a> the best?',
+            'Iggledy Piggledy',
+            '1 + 2 = ?',
+            'Am I a sandwich?',
+            'Where were you at 3:15am on April 14th?',
+            "Don't you mean prism?",
+            'Buts twelve by pies?'
+          ]
         }
       }
     },
     'help': {
-      'help': 'List all commands or view information for a command\nUsage: help [command]',
+      'help': 'List available commands or view information for a given command\nUsage: help [command]',
       'run': function(args, shell) {
         command = args.join(' ').trim()
         if (command in shell.commands) {
           return shell.commands[command].help
+        } else if (command) {
+          return 'Command not found: ' + command
         } else {
-          var output = (command) ? 'Command not found: ' + command + '\n' : ''
           var commands = [];
           for(var name in shell.commands) {
-            if (name !== 'Parent') { commands.push(name) }
+            commands.push(name)
           }
-          output += 'Available commands:\n' + commands.sort().join(' ')
-          return output
+          return 'Available commands:\n' + commands.sort().join(' ') + '\n\n`help [command]` for more information.'
         }
       }
     }