#for the case of testing, just run this file adding in the end a call to rules with the parameters you want if defined?(respond) @testing = false else @testing = true @questions = Hash.new() def respond(message, dest) puts message end #context: previous message #to: user that should answer def ask(question, context, to, dest) puts "Bot: #{question}" @questions[to] = context end end # from: Full name of the person sending the message # command: command to run # processed: in case the command has been already processed on Bot class, by default false # help: =================================== # help: # help: *These are specific commands for this bot on this Channel.* # help: They will be accessible only when the bot is listening to you just writing the command # help: or the bot is not listening to you but requested on demand, or in a private conversation with the Smart Bot. # help: To run a command on demand: # help: `!THE_COMMAND` # help: `@NAME_OF_BOT THE_COMMAND` # help: `NAME_OF_BOT THE_COMMAND` # help: def rules(user, command, processed, dest) from = user.name if @testing puts "#{from}: #{command}" if @questions.keys.include?(from) context = @questions[from] @questions[from] = command command = context end end firstname = from.split(" ").first case command # help: ---------------------------------------------- # help: `echo SOMETHING` # help: repeats SOMETHING # help: when /^echo\s(.+)/i respond $1, dest # help: ---------------------------------------------- # help: `go to sleep` # help: it will sleep the bot for 5 seconds # help: when /^go\sto\ssleep/i unless @questions.keys.include?(from) ask("do you want me to take a siesta?", command, from, dest) else case @questions[from] when /yes/i, /yep/i, /sure/i @questions.delete(from) respond "zZzzzzzZZZZZZzzzzzzz!", dest respond "I'll be sleeping for 5 secs... just for you", dest sleep 5 when /no/i, /nope/i, /cancel/i @questions.delete(from) respond "Thanks, I'm happy to be awake", dest else respond "I don't understand", dest ask("are you sure do you want me to sleep? (yes or no)", "go to sleep", from, dest) end end else unless processed resp = %w{ what huh sorry }.sample respond "#{firstname}: #{resp}?", dest end end end #for the case of testing just running this file, write the dialogue in here: if @testing require "nice_hash" user = { name: "Peter Johson", id: "Uxxxxxx" } rules user, "go to sleep, you look tired", false, nil rules user, "yes", false, nil end