class SlackSmartBot def process(user, command, dest, dchannel, rules_file, typem, files, ts) from = user.name if user.profile.display_name.to_s.match?(/\A\s*\z/) user.profile.display_name = user.profile.real_name end display_name = user.profile.display_name processed = true on_demand = false if command.match(/^@?(#{config[:nick]}):*\s+(.+)/im) or command.match(/^()!!(.+)/im) or command.match(/^()\^(.+)/im) or command.match(/^()!(.+)/im) or command.match(/^()<@#{config[:nick_id]}>\s+(.+)/im) command2 = $2 Thread.current[:command] = command2 if command2.match?(/^()!!(.+)/im) or command.match?(/^()\^(.+)/im) Thread.current[:on_thread] = true end command = command2 on_demand = true end #todo: check :on_pg in this case if typem == :on_master or typem == :on_bot or typem == :on_pg or typem == :on_dm case command when /^\s*(Hello|Hallo|Hi|Hola|What's\sup|Hey|Hæ)\s(#{@salutations.join("|")})\s*$/i hi_bot(user, dest, dchannel, from, display_name) when /^\s*(Bye|Bæ|Good\sBye|Adiós|Ciao|Bless|Bless\sBless|Adeu)\s(#{@salutations.join("|")})\s*$/i bye_bot(dest, from, display_name) when /^\s*bot\s+(rules|help)\s*(.+)?$/i, /^bot,? what can I do/i $1.to_s.match?(/rules/i) ? specific = true : specific = false help_command = $2 bot_help(user, from, dest, dchannel, specific, help_command, rules_file) when /^\s*use\s+(rules\s+)?(from\s+)?<#C\w+\|(.+)>\s*$/i, /^use\s+(rules\s+)?(from\s+)?([^\s]+\s*$)/i channel = $3 use_rules(dest, channel, user, dchannel) when /^\s*stop using rules (from\s+)<#\w+\|(.+)>/i, /^stop using rules (from\s+)(.+)/i channel = $2 stop_using_rules(dest, channel, user, dchannel) when /^\s*extend\s+rules\s+(to\s+)<#C\w+\|(.+)>/i, /^extend\s+rules\s+(to\s+)(.+)/i, /^\s*use\s+rules\s+(on\s+)<#C\w+\|(.+)>/i, /^use\s+rules\s+(on\s+)(.+)/i channel = $2 extend_rules(dest, user, from, channel, typem) when /^\s*stop using rules (on\s+)<#\w+\|(.+)>/i, /^stop using rules (on\s+)(.+)/i channel = $2 stop_using_rules_on(dest, user, from, channel, typem) when /^\s*exit\sbot\s*$/i, /^quit\sbot\s*$/i, /^close\sbot\s*$/i exit_bot(command, from, dest, display_name) when /^\s*start\s(this\s)?bot$/i start_bot(dest, from) when /^\s*pause\s(this\s)?bot$/i pause_bot(dest, from) when /^\s*bot\sstatus/i bot_status(dest, from) when /\Anotify\s+<#(C\w+)\|.+>\s+(.+)\s*\z/im, /\Anotify\s+(all)?\s*(.+)\s*\z/im where = $1 message = $2 notify_message(dest, from, where, message) when /^\s*create\s+(cloud\s+)?bot\s+on\s+<#C\w+\|(.+)>\s*/i, /^create\s+(cloud\s+)?bot\s+on\s+(.+)\s*/i cloud = !$1.nil? channel = $2 create_bot(dest, from, cloud, channel) when /^\s*kill\sbot\son\s<#C\w+\|(.+)>\s*$/i, /^kill\sbot\son\s(.+)\s*$/i channel = $1 kill_bot_on_channel(dest, from, channel) when /^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(every)\s+(\d+)\s*(days|hours|minutes|seconds|mins|min|secs|sec|d|h|m|s)\s*(\s.+)?\s*$/i, /^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s.+)?\s*$/i silent = $2.to_s!='' name = $3.downcase type = $4 number_time = $5 period = $6 command_to_run = $7 add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent) when /^\s*(kill|delete|remove)\s+routine\s+(\w+)\s*$/i name = $2.downcase remove_routine(dest, from, name) when /^\s*(run|execute)\s+routine\s+(\w+)\s*$/i name = $2.downcase run_routine(dest, from, name) when /^\s*pause\s+routine\s+(\w+)\s*$/i name = $1.downcase pause_routine(dest, from, name) when /^\s*start\s+routine\s+(\w+)\s*$/i name = $1.downcase start_routine(dest, from, name) when /^\s*see\s+(all\s+)?routines\s*$/i all = $1.to_s != "" see_routines(dest, from, user, all) when /^\s*get\s+bot\s+logs?\s*$/i get_bot_logs(dest, from, typem) when /^\s*bot\s+stats\s*(.*)\s*$/i opts = $1.to_s all_opts = opts.downcase.split(' ') st_channel = opts.scan(/<#(\w+)\|.+>/).join st_from = opts.scan(/from\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join st_from = st_from.gsub('.','-').gsub('/','-') st_to = opts.scan(/to\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join st_to = st_to.gsub('.','-').gsub('/','-') st_user = opts.scan(/<@([^>]+)>/).join exclude_masters = opts.match?(/exclude\s+masters?/i) if all_opts.include?('today') st_from = st_to = "#{Time.now.strftime("%Y-%m-%d")}" end exclude_command = opts.scan(/exclude\s+([^\s]+)/i).join exclude_command = '' if exclude_command == 'masters' bot_stats(dest, from, typem, st_channel, st_from, st_to, st_user, exclude_masters, exclude_command) else processed = false end else processed = false end # only when :on and (listening or on demand or direct message) if @status == :on and (@questions.keys.include?(from) or (@listening.include?(from) and typem != :on_extended) or typem == :on_dm or typem == :on_pg or on_demand) processed2 = true case command # bot rules for extended channels when /^bot\s+rules\s*(.+)?$/i help_command = $1 bot_rules(dest, help_command, typem, rules_file, from) when /^\s*(add\s)?shortcut\s(for\sall)?\s*([^:]+)\s*:\s*(.+)/i, /^(add\s)sc\s(for\sall)?\s*([^:]+)\s*:\s*(.+)/i for_all = $2 shortcut_name = $3.to_s.downcase command_to_run = $4 add_shortcut(dest, from, typem, for_all, shortcut_name, command, command_to_run) when /^\s*(delete|remove)\s+shortcut\s+(.+)/i, /^(delete|remove)\s+sc\s+(.+)/i shortcut = $2.to_s.downcase delete_shortcut(dest, from, shortcut, typem, command) when /^\s*see\sshortcuts/i, /^see\ssc/i see_shortcuts(dest, from, typem) #kept to be backwards compatible when /^\s*id\schannel\s<#C\w+\|(.+)>\s*/i, /^id channel (.+)/ unless typem == :on_extended channel_name = $1 get_channels_name_and_id() if @channels_id.keys.include?(channel_name) respond "the id of #{channel_name} is #{@channels_id[channel_name]}", dest else respond "channel: #{channel_name} not found", dest end end when /^\s*ruby\s(.+)/im, /^\s*code\s(.+)/im code = $1 code.gsub!("\\n", "\n") code.gsub!("\\r", "\r") @logger.info code ruby_code(dest, code, rules_file) else processed2 = false end #of case processed = true if processed or processed2 end return processed end end