simple-slack-bot 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4443f2c498d95875a06c189f44eefc04e74ad2ca
4
+ data.tar.gz: 226a295f130c9e097adee747b0815c87e05c8e8c
5
+ SHA512:
6
+ metadata.gz: 82e490c5500edc5961223e59737cd361c61d1e550fc2417b76e245bcc3cc9c46df3dce5c49d34aad23e820d30c6425d23f13a994c8d568b39830ce202e65955b
7
+ data.tar.gz: 4462537653ad89d21257ddc1ab13dc6dc2c74e7bffe7e88564c18010ae9b88ee4a662bc0846f0f37ebec4fd7c0e504d5af9bf2d8c9e73bbbf2c4e97d2cd2dcbb
@@ -0,0 +1,2 @@
1
+ .idea
2
+ *.gem
@@ -0,0 +1,4 @@
1
+
2
+ require 'simple_slack_bot/command'
3
+ require 'simple_slack_bot/config'
4
+ require 'simple_slack_bot/client'
@@ -0,0 +1,87 @@
1
+
2
+ require 'slack-ruby-client'
3
+
4
+ module SlackBot
5
+ class Client
6
+ attr_accessor :slack_web_client, :slack_realtime_client
7
+ attr_accessor :commands
8
+ attr_accessor(*Config::ATTRIBUTES)
9
+
10
+ def initialize
11
+ @commands = []
12
+ end
13
+
14
+ def add_command(regex)
15
+ command = Command.new(self)
16
+ command.regex = regex
17
+ command.action = lambda { |data|
18
+ yield(data)
19
+ }
20
+ @commands << command
21
+ end
22
+
23
+ def start!
24
+ if config.token.nil?
25
+ puts 'You must setting a token.'
26
+ return
27
+ end
28
+
29
+ self.slack_init
30
+ self.message_event_init
31
+
32
+ EM.run do
33
+ @slack_realtime_client.start!
34
+ end
35
+ end
36
+
37
+ def config
38
+ Config
39
+ end
40
+
41
+ def configure
42
+ block_given? ? yield(Config) : Config
43
+ end
44
+
45
+ def web_message(channel, text)
46
+ @slack_web_client.chat_postMessage(channel: channel, text: text, as_user: true)
47
+ end
48
+
49
+ def message(channel, text)
50
+ @slack_realtime_client.message channel: channel, text: text
51
+ end
52
+
53
+ protected
54
+
55
+ def slack_init
56
+ Slack.configure do |config|
57
+ config.token = self.config.token
58
+ end
59
+
60
+ Slack::RealTime.configure do |config|
61
+ config.concurrency = Slack::RealTime::Concurrency::Eventmachine
62
+ end
63
+
64
+ @slack_web_client = Slack::Web::Client.new
65
+ @slack_realtime_client = Slack::RealTime::Client.new
66
+ end
67
+
68
+ def message_event_init
69
+ client = @slack_realtime_client
70
+ client.on :message do |data|
71
+ File.open('bot.log', 'a') { |file| file.write(data.to_s + "\n") }
72
+ puts data if config.debug.eql?(true)
73
+
74
+ case data['subtype']
75
+ when 'channel_join' then
76
+ client.message channel: data['channel'], text: config.join_message
77
+ end
78
+
79
+ @commands.each do |command|
80
+ if command.match?(data['text'])
81
+ command.execute(data)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module SlackBot
3
+ class Command
4
+ attr_accessor :bot_client
5
+ attr_accessor :regex
6
+ attr_accessor :help_message
7
+ attr_accessor :action
8
+
9
+ def initialize(bot_client)
10
+ @bot_client = bot_client
11
+ end
12
+
13
+ def match?(str)
14
+ return false if @regex.nil? || @regex.match(str).nil?
15
+ true
16
+ end
17
+
18
+ def execute(data)
19
+ return if @action.nil?
20
+ @action.call(data)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+
2
+ module SlackBot
3
+ module Config
4
+ extend self
5
+
6
+ ATTRIBUTES = [
7
+ :debug,
8
+ :join_message,
9
+ :token
10
+ ]
11
+
12
+ def reset
13
+ self.debug = false
14
+ self.join_message = 'Hello!'
15
+ end
16
+
17
+ attr_accessor(*Config::ATTRIBUTES)
18
+ end
19
+ end
20
+
21
+ SlackBot::Config.reset()
@@ -0,0 +1,3 @@
1
+ module SlackBot
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,19 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+ require 'simple_slack_bot/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'simple-slack-bot'
6
+ s.version = SlackBot::VERSION
7
+ s.authors = ['Lee Sun-Hyoup']
8
+ s.email = ['kciter@naver.com']
9
+
10
+ s.files = `git ls-files`.split("\n")
11
+ s.homepage = 'http://github.com/kciter/simple-slack-bot'
12
+ s.licenses = ['MIT']
13
+ s.summary = %q{Simple Slack Bot for Ruby.}
14
+ s.description = %q{You can easily make Slack Bot!!!}
15
+
16
+ s.add_dependency 'slack-ruby-client', '~> 0.5.3'
17
+ s.add_dependency 'eventmachine', '~> 1.0', '>= 1.0.9'
18
+ s.add_dependency 'faye-websocket', '~> 0.10.2'
19
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple-slack-bot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lee Sun-Hyoup
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slack-ruby-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: eventmachine
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.0.9
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.9
47
+ - !ruby/object:Gem::Dependency
48
+ name: faye-websocket
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.10.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.10.2
61
+ description: You can easily make Slack Bot!!!
62
+ email:
63
+ - kciter@naver.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - lib/simple-slack-bot.rb
70
+ - lib/simple_slack_bot/client.rb
71
+ - lib/simple_slack_bot/command.rb
72
+ - lib/simple_slack_bot/config.rb
73
+ - lib/simple_slack_bot/version.rb
74
+ - simple-slack-bot.gemspec
75
+ homepage: http://github.com/kciter/simple-slack-bot
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Simple Slack Bot for Ruby.
99
+ test_files: []