[
  {
    "path": ".gitignore",
    "content": ".idea\n*.gem\n/.bundle/\n/.yardoc\n/Gemfile.lock\n/_yardoc/\n/coverage/\n/doc/\n/pkg/\n/spec/reports/\n/tmp/\n*.bundle\n*.so\n*.o\n*.a\nmkmf.log"
  },
  {
    "path": ".rspec",
    "content": "--color\n--format documentation"
  },
  {
    "path": ".travis.yml",
    "content": "language: ruby\nrvm:\n  - \"2.0.0\"\n  - \"2.2.0\"\n  - \"2.2.2\"\n"
  },
  {
    "path": "Gemfile",
    "content": "source 'https://rubygems.org'\n\ngemspec"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2016 Lee Sun-Hyoup\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# SimpleSlackBot\n[![Build Status](https://travis-ci.org/kciter/simple-slack-bot.svg?branch=master)](https://travis-ci.org/kciter/simple-slack-bot)\n\nThis library wrapping [slack-ruby-client](https://github.com/dblock/slack-ruby-client) library\n\n## Preview\n<img src=\"https://github.com/kciter/simple-slack-bot/raw/master/images/preview.gif\" alt=\"Preview gif\">\n\n## Installation\nAdd this line to your application's Gemfile:\n```ruby\ngem 'simple-slack-bot'\n```\nAnd then execute:\n```\n$ bundle\n```\nOr install it yourself as:\n```\n$ gem install simple-slack-bot\n```\n\n## Simple Usage\nThis is simple!\n```ruby\nrequire 'simple-slack-bot'\n\nbot = SlackBot::Client.new\n\nbot.configure do |config|\n  config.join_message = 'Hello!'\n  config.debug = true # \n  config.token = 'YOUR SLACK BOT TOKEN'\nend\n\nbot.add_command /Hello/ do |data|\n  bot.message(data['channel'], \"Hello. <@#{data['user']}>!\")\nend\n\nbot.start!\n```\nRefer to the Slack event message for [data](https://api.slack.com/events/message)\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2016 Lee Sun-Hyoup\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "Rakefile",
    "content": "require 'rubygems'\nrequire 'bundler'\nrequire 'bundler/gem_tasks'\nrequire 'rspec/core/rake_task'\n\ntask :default => :spec\nRSpec::Core::RakeTask.new"
  },
  {
    "path": "lib/simple_slack_bot/client.rb",
    "content": "require 'slack-ruby-client'\n\nmodule SlackBot\n  class Client\n    attr_accessor :slack_web_client, :slack_realtime_client\n    attr_accessor :commands\n    attr_accessor(*Config::ATTRIBUTES)\n\n    def initialize\n      @commands = []\n    end\n\n    def add_command(regex)\n      command = Command.new(self)\n      command.regex = regex\n      command.action = -> (data) { yield(data) }\n      @commands << command\n    end\n\n    def start!\n      if config.token.nil?\n        puts 'You must setting a token.'\n        return\n      end\n\n      slack_init\n      message_event_init\n\n      EM.run do\n        @slack_realtime_client.start!\n      end\n    end\n\n    def config\n      Config\n    end\n\n    def configure\n      block_given? ? yield(Config) : Config\n    end\n\n    def web_message(channel, text)\n      @slack_web_client.chat_postMessage(channel: channel, text: text, as_user: true)\n    end\n\n    def message(channel, text)\n      @slack_realtime_client.message channel: channel, text: text\n    end\n\n    protected\n\n    def slack_init\n      Slack.configure do |config|\n        config.token = self.config.token\n      end\n\n      Slack::RealTime.configure do |config|\n        config.concurrency = Slack::RealTime::Concurrency::Eventmachine\n      end\n\n      @slack_web_client = Slack::Web::Client.new\n      @slack_realtime_client = Slack::RealTime::Client.new\n    end\n\n    def message_event_init\n      client = @slack_realtime_client\n      client.on :message do |data|\n        File.open('bot.log', 'a') { |file| file.write(data.to_s + \"\\n\") }\n        puts data if config.debug.eql?(true)\n\n        case data['subtype']\n        when 'channel_join' then\n          client.message channel: data['channel'], text: config.join_message\n        end\n\n        @commands.each do |command|\n          command.execute(data) if command.match?(data['text'])\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/simple_slack_bot/command.rb",
    "content": "module SlackBot\n  class Command\n    attr_accessor :bot_client, :regex, :help_message, :action\n\n    def initialize(bot_client)\n      @bot_client = bot_client\n    end\n\n    def match?(str)\n      (@regex.nil? || @regex.match(str).nil?) ? false : true\n    end\n\n    def execute(data)\n      return if @action.nil?\n      @action.call(data)\n    end\n  end\nend\n"
  },
  {
    "path": "lib/simple_slack_bot/config.rb",
    "content": "module SlackBot\n  module Config\n    extend self\n\n    ATTRIBUTES = [\n      :debug,\n      :join_message,\n      :token\n    ]\n\n    attr_accessor(*Config::ATTRIBUTES)\n\n    self.debug = false\n    self.join_message = 'Hello!'\n    self.token = 'TOKEN'\n  end\n\n  module_function\n\n  def configure\n    block_given? ? yield(Config) : Config\n  end\n\n  def config\n    Config\n  end\nend\n"
  },
  {
    "path": "lib/simple_slack_bot/version.rb",
    "content": "module SlackBot\n  VERSION = '0.1.2'\nend"
  },
  {
    "path": "lib/simple_slack_bot.rb",
    "content": "require 'simple_slack_bot/command'\nrequire 'simple_slack_bot/config'\nrequire 'simple_slack_bot/client'\n"
  },
  {
    "path": "simple-slack-bot.gemspec",
    "content": "$LOAD_PATH.push File.expand_path('../lib', __FILE__)\nrequire 'simple_slack_bot/version'\n\nGem::Specification.new do |s|\n  s.name = 'simple-slack-bot'\n  s.version = SlackBot::VERSION\n  s.authors = ['Lee Sun-Hyoup']\n  s.email = ['kciter@naver.com']\n\n  s.files = `git ls-files`.split(\"\\n\")\n  s.homepage = 'http://github.com/kciter/simple-slack-bot'\n  s.licenses = ['MIT']\n  s.summary = %q{Simple Slack Bot for Ruby.}\n  s.description = %q{You can easily make Slack Bot!!!}\n\n  s.add_dependency 'slack-ruby-client', '~> 0.5.3'\n  s.add_dependency 'eventmachine', '~> 1.0', '>= 1.0.9'\n  s.add_dependency 'faye-websocket', '~> 0.10.2'\n  # s.add_dependency 'rufus-scheduler', '~> 3.2.0'\n\n  s.add_development_dependency 'bundler'\n  s.add_development_dependency 'rake'\n  s.add_development_dependency 'rspec'\nend"
  },
  {
    "path": "spec/client_spec.rb",
    "content": "require 'spec_helper'\n\ndescribe SlackBot::Client do\n  describe '#initialize' do\n    it 'have an empty commands array' do\n      expect(SlackBot::Client.new.commands).to eq []\n    end\n  end\n\n  describe '.add_command' do\n    bot = SlackBot::Client.new\n\n    it 'add command to commands array' do\n      result = bot.add_command('Hello')\n      expect(result).to eq bot.commands\n    end\n  end\nend\n"
  },
  {
    "path": "spec/command_spec.rb",
    "content": "require 'spec_helper'\n\ndescribe SlackBot::Command do\n  describe '#initialize' do\n    bot = SlackBot::Client.new\n\n    it 'have a bot_client' do\n      command = SlackBot::Command.new(bot)\n      expect(command.bot_client).to eq bot\n    end\n  end\n\n  describe '.match?' do\n    bot = SlackBot::Client.new\n    bot.add_command('Hello')\n\n    it 'iterate commands' do\n      bot.commands.each do |command|\n        expect(command.regex).to eq 'Hello'\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "spec/config_spec.rb",
    "content": "require 'spec_helper'\n\ndescribe SlackBot::Config do\n  describe '#initialize' do\n    it 'sets config' do\n      expect(SlackBot.config.join_message).to eq 'Hello!'\n      expect(SlackBot.config.debug).to eq false\n      expect(SlackBot.config.token).to eq 'TOKEN'\n    end\n  end\n\n  describe '#configure' do\n    before do\n      SlackBot.configure do |config|\n        config.join_message = 'Hi!'\n        config.debug = true\n        config.token = 'Invalid Token'\n      end\n    end\n\n    it 'sets config' do\n      expect(SlackBot.config.join_message).to eq 'Hi!'\n      expect(SlackBot.config.debug).to eq true\n      expect(SlackBot.config.token).to eq 'Invalid Token'\n    end\n  end\nend\n"
  },
  {
    "path": "spec/spec_helper.rb",
    "content": "require 'bundler/setup'\nBundler.setup\n\nrequire 'simple_slack_bot'\n\nRSpec.configure do |config|\nend\n"
  },
  {
    "path": "spec/version_spec.rb",
    "content": "require 'spec_helper'\n\ndescribe SlackBot do\n  it 'has a version' do\n    expect(SlackBot::VERSION).to_not be nil\n  end\nend"
  }
]