Sha256: dd59f38db5633a30276cda801310267f3161276819314b1d9ccbca602f60aea0

Contents?: true

Size: 1.79 KB

Versions: 15

Compression:

Stored size: 1.79 KB

Contents

class SlackSmartBot

  #context: previous message
  #to: user that should answer
  def ask(question, context = nil, to = nil, dest = nil)
    if dest.nil? and Thread.current.key?(:dest)
      dest = Thread.current[:dest]
    end
    if to.nil?
      to = Thread.current[:user].name
    end
    if context.nil?
      context = Thread.current[:command]
    end
    message = "#{to}: #{question}"
    if dest.nil?
      if config[:simulate]
        open("#{config.path}/buffer_complete.log", "a") { |f|
          f.puts "|#{@channel_id}|#{config[:nick_id]}|#{message}~~~"
        }
      else  
        if Thread.current[:on_thread]
          client.message(channel: @channel_id, text: message, as_user: true, thread_ts: Thread.current[:thread_ts])
        else
          client.message(channel: @channel_id, text: message, as_user: true)
        end
      end
      if config[:testing] and config.on_master_bot
        open("#{config.path}/buffer.log", "a") { |f|
          f.puts "|#{@channel_id}|#{config[:nick_id]}|#{message}"
        }
      end
    elsif dest[0] == "C" or dest[0] == "G" # channel
      if config[:simulate]
        open("#{config.path}/buffer_complete.log", "a") { |f|
          f.puts "|#{dest}|#{config[:nick_id]}|#{message}~~~"
        }
      else  
        if Thread.current[:on_thread]
          client.message(channel: dest, text: message, as_user: true, thread_ts: Thread.current[:thread_ts])
        else
          client.message(channel: dest, text: message, as_user: true)
        end
      end
      if config[:testing] and config.on_master_bot
        open("#{config.path}/buffer.log", "a") { |f|
          f.puts "|#{dest}|#{config[:nick_id]}|#{message}"
        }
      end
    elsif dest[0] == "D" #private message
      send_msg_user(dest, message)
    end
    @questions[to] = context
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
slack-smart-bot-1.8.2 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.8.1 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.8.0 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.7.0 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.6.8 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.6.7 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.6.6 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.6.5 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.6.4 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.6.3 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.6.2 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.6.1 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.6.0 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.5.1 lib/slack/smart-bot/comm/ask.rb
slack-smart-bot-1.5.0 lib/slack/smart-bot/comm/ask.rb