class BotPlatform::Cli
Attributes
bot_id[RW]
bot_instance[RW]
bot_name[RW]
room_id[RW]
user_name[RW]
Public Class Methods
new(instance)
click to toggle source
# File lib/bot_platform/cli.rb, line 12 def initialize(instance) @bot_name = "bot" @user_name = "user" @bot_instance = instance ENV['BOT_CHANNELS'] = 'console' Signal.trap(:INT) do puts "\nbye." exit 0 end end
Public Instance Methods
help()
click to toggle source
# File lib/bot_platform/cli.rb, line 76 def help <<-USAGE usage: history exit, quit, \\q - close shell and exit help, \\h, \\? - print this usage clear, \\c - clear the terminal screen USAGE end
process(cmd)
click to toggle source
# File lib/bot_platform/cli.rb, line 52 def process(cmd) headers = {"X-Bot-Platform-Bot":@bot_name} body = {bot_id:@bot_id, room_id:@room_id} if cmd.start_with? '/' body[:type] = "cmd_back" cmd.slice!(0) body[:cmd] = cmd else body[:type] = "message" body[:text] = cmd end instance = @bot_instance BotPlatform::Adapter.instance.process_activity headers,body do |context| instance.on_turn context end end
prompt()
click to toggle source
# File lib/bot_platform/cli.rb, line 72 def prompt return "#{@user_name}> " end
run()
click to toggle source
# File lib/bot_platform/cli.rb, line 24 def run puts welcome_message opts = GetoptLong.new( ['--name', GetoptLong::OPTIONAL_ARGUMENT] ) opts.each do |opt, arg| case opt when '--name' then @bot_name = arg end end while cmd = Readline.readline(prompt, true) case cmd when "exit", "quit", '\q' then exit when "help", '\h', '\?' then puts help when 'clear', '\c' then system 'clear' else # bot incoming activity unless cmd.empty? process cmd end end end end
welcome_message()
click to toggle source
# File lib/bot_platform/cli.rb, line 86 def welcome_message <<-WELCOME Welcome to Bot Platform Command Line Interface (v0.1) \\------/ _ [| o ω o|] _ / |==\\__-__/=| \\ powered by Ningfeng Yang WELCOME end