Repository: kciter/simple-slack-bot
Branch: master
Commit: c77c17806907
Files: 18
Total size: 8.6 KB
Directory structure:
gitextract_l28ift1u/
├── .gitignore
├── .rspec
├── .travis.yml
├── Gemfile
├── LICENSE
├── README.md
├── Rakefile
├── lib/
│ ├── simple_slack_bot/
│ │ ├── client.rb
│ │ ├── command.rb
│ │ ├── config.rb
│ │ └── version.rb
│ └── simple_slack_bot.rb
├── simple-slack-bot.gemspec
└── spec/
├── client_spec.rb
├── command_spec.rb
├── config_spec.rb
├── spec_helper.rb
└── version_spec.rb
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.idea
*.gem
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.bundle
*.so
*.o
*.a
mkmf.log
================================================
FILE: .rspec
================================================
--color
--format documentation
================================================
FILE: .travis.yml
================================================
language: ruby
rvm:
- "2.0.0"
- "2.2.0"
- "2.2.2"
================================================
FILE: Gemfile
================================================
source 'https://rubygems.org'
gemspec
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2016 Lee Sun-Hyoup
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# SimpleSlackBot
[](https://travis-ci.org/kciter/simple-slack-bot)
This library wrapping [slack-ruby-client](https://github.com/dblock/slack-ruby-client) library
## Preview
<img src="https://github.com/kciter/simple-slack-bot/raw/master/images/preview.gif" alt="Preview gif">
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'simple-slack-bot'
```
And then execute:
```
$ bundle
```
Or install it yourself as:
```
$ gem install simple-slack-bot
```
## Simple Usage
This is simple!
```ruby
require 'simple-slack-bot'
bot = SlackBot::Client.new
bot.configure do |config|
config.join_message = 'Hello!'
config.debug = true #
config.token = 'YOUR SLACK BOT TOKEN'
end
bot.add_command /Hello/ do |data|
bot.message(data['channel'], "Hello. <@#{data['user']}>!")
end
bot.start!
```
Refer to the Slack event message for [data](https://api.slack.com/events/message)
## License
The MIT License (MIT)
Copyright (c) 2016 Lee Sun-Hyoup
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: Rakefile
================================================
require 'rubygems'
require 'bundler'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
task :default => :spec
RSpec::Core::RakeTask.new
================================================
FILE: lib/simple_slack_bot/client.rb
================================================
require 'slack-ruby-client'
module SlackBot
class Client
attr_accessor :slack_web_client, :slack_realtime_client
attr_accessor :commands
attr_accessor(*Config::ATTRIBUTES)
def initialize
@commands = []
end
def add_command(regex)
command = Command.new(self)
command.regex = regex
command.action = -> (data) { yield(data) }
@commands << command
end
def start!
if config.token.nil?
puts 'You must setting a token.'
return
end
slack_init
message_event_init
EM.run do
@slack_realtime_client.start!
end
end
def config
Config
end
def configure
block_given? ? yield(Config) : Config
end
def web_message(channel, text)
@slack_web_client.chat_postMessage(channel: channel, text: text, as_user: true)
end
def message(channel, text)
@slack_realtime_client.message channel: channel, text: text
end
protected
def slack_init
Slack.configure do |config|
config.token = self.config.token
end
Slack::RealTime.configure do |config|
config.concurrency = Slack::RealTime::Concurrency::Eventmachine
end
@slack_web_client = Slack::Web::Client.new
@slack_realtime_client = Slack::RealTime::Client.new
end
def message_event_init
client = @slack_realtime_client
client.on :message do |data|
File.open('bot.log', 'a') { |file| file.write(data.to_s + "\n") }
puts data if config.debug.eql?(true)
case data['subtype']
when 'channel_join' then
client.message channel: data['channel'], text: config.join_message
end
@commands.each do |command|
command.execute(data) if command.match?(data['text'])
end
end
end
end
end
================================================
FILE: lib/simple_slack_bot/command.rb
================================================
module SlackBot
class Command
attr_accessor :bot_client, :regex, :help_message, :action
def initialize(bot_client)
@bot_client = bot_client
end
def match?(str)
(@regex.nil? || @regex.match(str).nil?) ? false : true
end
def execute(data)
return if @action.nil?
@action.call(data)
end
end
end
================================================
FILE: lib/simple_slack_bot/config.rb
================================================
module SlackBot
module Config
extend self
ATTRIBUTES = [
:debug,
:join_message,
:token
]
attr_accessor(*Config::ATTRIBUTES)
self.debug = false
self.join_message = 'Hello!'
self.token = 'TOKEN'
end
module_function
def configure
block_given? ? yield(Config) : Config
end
def config
Config
end
end
================================================
FILE: lib/simple_slack_bot/version.rb
================================================
module SlackBot
VERSION = '0.1.2'
end
================================================
FILE: lib/simple_slack_bot.rb
================================================
require 'simple_slack_bot/command'
require 'simple_slack_bot/config'
require 'simple_slack_bot/client'
================================================
FILE: simple-slack-bot.gemspec
================================================
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'simple_slack_bot/version'
Gem::Specification.new do |s|
s.name = 'simple-slack-bot'
s.version = SlackBot::VERSION
s.authors = ['Lee Sun-Hyoup']
s.email = ['kciter@naver.com']
s.files = `git ls-files`.split("\n")
s.homepage = 'http://github.com/kciter/simple-slack-bot'
s.licenses = ['MIT']
s.summary = %q{Simple Slack Bot for Ruby.}
s.description = %q{You can easily make Slack Bot!!!}
s.add_dependency 'slack-ruby-client', '~> 0.5.3'
s.add_dependency 'eventmachine', '~> 1.0', '>= 1.0.9'
s.add_dependency 'faye-websocket', '~> 0.10.2'
# s.add_dependency 'rufus-scheduler', '~> 3.2.0'
s.add_development_dependency 'bundler'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
end
================================================
FILE: spec/client_spec.rb
================================================
require 'spec_helper'
describe SlackBot::Client do
describe '#initialize' do
it 'have an empty commands array' do
expect(SlackBot::Client.new.commands).to eq []
end
end
describe '.add_command' do
bot = SlackBot::Client.new
it 'add command to commands array' do
result = bot.add_command('Hello')
expect(result).to eq bot.commands
end
end
end
================================================
FILE: spec/command_spec.rb
================================================
require 'spec_helper'
describe SlackBot::Command do
describe '#initialize' do
bot = SlackBot::Client.new
it 'have a bot_client' do
command = SlackBot::Command.new(bot)
expect(command.bot_client).to eq bot
end
end
describe '.match?' do
bot = SlackBot::Client.new
bot.add_command('Hello')
it 'iterate commands' do
bot.commands.each do |command|
expect(command.regex).to eq 'Hello'
end
end
end
end
================================================
FILE: spec/config_spec.rb
================================================
require 'spec_helper'
describe SlackBot::Config do
describe '#initialize' do
it 'sets config' do
expect(SlackBot.config.join_message).to eq 'Hello!'
expect(SlackBot.config.debug).to eq false
expect(SlackBot.config.token).to eq 'TOKEN'
end
end
describe '#configure' do
before do
SlackBot.configure do |config|
config.join_message = 'Hi!'
config.debug = true
config.token = 'Invalid Token'
end
end
it 'sets config' do
expect(SlackBot.config.join_message).to eq 'Hi!'
expect(SlackBot.config.debug).to eq true
expect(SlackBot.config.token).to eq 'Invalid Token'
end
end
end
================================================
FILE: spec/spec_helper.rb
================================================
require 'bundler/setup'
Bundler.setup
require 'simple_slack_bot'
RSpec.configure do |config|
end
================================================
FILE: spec/version_spec.rb
================================================
require 'spec_helper'
describe SlackBot do
it 'has a version' do
expect(SlackBot::VERSION).to_not be nil
end
end
gitextract_l28ift1u/
├── .gitignore
├── .rspec
├── .travis.yml
├── Gemfile
├── LICENSE
├── README.md
├── Rakefile
├── lib/
│ ├── simple_slack_bot/
│ │ ├── client.rb
│ │ ├── command.rb
│ │ ├── config.rb
│ │ └── version.rb
│ └── simple_slack_bot.rb
├── simple-slack-bot.gemspec
└── spec/
├── client_spec.rb
├── command_spec.rb
├── config_spec.rb
├── spec_helper.rb
└── version_spec.rb
SYMBOL INDEX (21 symbols across 4 files)
FILE: lib/simple_slack_bot/client.rb
type SlackBot (line 3) | module SlackBot
class Client (line 4) | class Client
method initialize (line 9) | def initialize
method add_command (line 13) | def add_command(regex)
method start! (line 20) | def start!
method config (line 34) | def config
method configure (line 38) | def configure
method web_message (line 42) | def web_message(channel, text)
method message (line 46) | def message(channel, text)
method slack_init (line 52) | def slack_init
method message_event_init (line 65) | def message_event_init
FILE: lib/simple_slack_bot/command.rb
type SlackBot (line 1) | module SlackBot
class Command (line 2) | class Command
method initialize (line 5) | def initialize(bot_client)
method match? (line 9) | def match?(str)
method execute (line 13) | def execute(data)
FILE: lib/simple_slack_bot/config.rb
type SlackBot (line 1) | module SlackBot
type Config (line 2) | module Config
function configure (line 20) | def configure
function config (line 24) | def config
FILE: lib/simple_slack_bot/version.rb
type SlackBot (line 1) | module SlackBot
Condensed preview — 18 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (10K chars).
[
{
"path": ".gitignore",
"chars": 129,
"preview": ".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"
},
{
"path": ".rspec",
"chars": 30,
"preview": "--color\n--format documentation"
},
{
"path": ".travis.yml",
"chars": 56,
"preview": "language: ruby\nrvm:\n - \"2.0.0\"\n - \"2.2.0\"\n - \"2.2.2\"\n"
},
{
"path": "Gemfile",
"chars": 38,
"preview": "source 'https://rubygems.org'\n\ngemspec"
},
{
"path": "LICENSE",
"chars": 1080,
"preview": "The MIT License (MIT)\n\nCopyright (c) 2016 Lee Sun-Hyoup\n\nPermission is hereby granted, free of charge, to any person obt"
},
{
"path": "README.md",
"chars": 2071,
"preview": "# SimpleSlackBot\n[](https://travis-ci.or"
},
{
"path": "Rakefile",
"chars": 145,
"preview": "require 'rubygems'\nrequire 'bundler'\nrequire 'bundler/gem_tasks'\nrequire 'rspec/core/rake_task'\n\ntask :default => :spec\n"
},
{
"path": "lib/simple_slack_bot/client.rb",
"chars": 1856,
"preview": "require 'slack-ruby-client'\n\nmodule SlackBot\n class Client\n attr_accessor :slack_web_client, :slack_realtime_client\n"
},
{
"path": "lib/simple_slack_bot/command.rb",
"chars": 350,
"preview": "module SlackBot\n class Command\n attr_accessor :bot_client, :regex, :help_message, :action\n\n def initialize(bot_cl"
},
{
"path": "lib/simple_slack_bot/config.rb",
"chars": 369,
"preview": "module SlackBot\n module Config\n extend self\n\n ATTRIBUTES = [\n :debug,\n :join_message,\n :token\n "
},
{
"path": "lib/simple_slack_bot/version.rb",
"chars": 39,
"preview": "module SlackBot\n VERSION = '0.1.2'\nend"
},
{
"path": "lib/simple_slack_bot.rb",
"chars": 103,
"preview": "require 'simple_slack_bot/command'\nrequire 'simple_slack_bot/config'\nrequire 'simple_slack_bot/client'\n"
},
{
"path": "simple-slack-bot.gemspec",
"chars": 798,
"preview": "$LOAD_PATH.push File.expand_path('../lib', __FILE__)\nrequire 'simple_slack_bot/version'\n\nGem::Specification.new do |s|\n "
},
{
"path": "spec/client_spec.rb",
"chars": 390,
"preview": "require 'spec_helper'\n\ndescribe SlackBot::Client do\n describe '#initialize' do\n it 'have an empty commands array' do"
},
{
"path": "spec/command_spec.rb",
"chars": 467,
"preview": "require 'spec_helper'\n\ndescribe SlackBot::Command do\n describe '#initialize' do\n bot = SlackBot::Client.new\n\n it "
},
{
"path": "spec/config_spec.rb",
"chars": 677,
"preview": "require 'spec_helper'\n\ndescribe SlackBot::Config do\n describe '#initialize' do\n it 'sets config' do\n expect(Sla"
},
{
"path": "spec/spec_helper.rb",
"chars": 99,
"preview": "require 'bundler/setup'\nBundler.setup\n\nrequire 'simple_slack_bot'\n\nRSpec.configure do |config|\nend\n"
},
{
"path": "spec/version_spec.rb",
"chars": 121,
"preview": "require 'spec_helper'\n\ndescribe SlackBot do\n it 'has a version' do\n expect(SlackBot::VERSION).to_not be nil\n end\nen"
}
]
About this extraction
This page contains the full source code of the kciter/simple-slack-bot GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 18 files (8.6 KB), approximately 2.7k tokens, and a symbol index with 21 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.