fuck_bot 0.0.1
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +27 -0
- data/bin/fuck_bot +7 -0
- data/lib/dictionary.yml +6 -0
- data/lib/fuck_bot/dictionary.rb +16 -0
- data/lib/fuck_bot/event_machine.rb +60 -0
- data/lib/fuck_bot/message_resolver.rb +67 -0
- data/lib/fuck_bot/version.rb +3 -0
- data/lib/fuck_bot.rb +15 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dea2de9dece0ecffd84127b26187af66708b568a
|
4
|
+
data.tar.gz: 61406bc049e9c053b7d953f7bd43db5fd0fb0de2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf0907d0a34d9756800ae4ece2f245ec213bb2e84fab2bca08f6286b51aa496e74ba83f02ec0cbadd276643d9e171c33fba5490bf4246530dcffa53a4b122fbc
|
7
|
+
data.tar.gz: 9320a1325532eba10268b4f791d3ccdebee618761c5935b334e2a3ab22c56daf09899a392c47b1ba088ce81abe374def3e4394597a63ea8a566cff105611e7c2
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Sergey Novikov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# FuckBot
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/fuck_bot)
|
4
|
+
[](https://travis-ci.org/droptheplot/fuck_bot)
|
5
|
+
[](https://codeclimate.com/github/droptheplot/fuck_bot)
|
6
|
+
|
7
|
+
Slack bot to watch your language.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
* Install gem: `gem install fuck_bot`.
|
12
|
+
* Create bot ([https://slack.com/apps/A0F7YS25R-bots](https://slack.com/apps/A0F7YS25R-bots)).
|
13
|
+
* Choose the name (`fuck_bot` or whatever you want).
|
14
|
+
* Copy API Token (e.g. xoxb-29512306146-LT8dwEeZQWLNWZmN9xs0m9zj).
|
15
|
+
* Run: `bundle exec fuck_bot xoxb-29512306146-LT8dwEeZQWLNWZmN9xs0m9zj`
|
16
|
+
|
17
|
+
## Contributing
|
18
|
+
|
19
|
+
1. Fork it (https://github.com/droptheplot/fuck_bot/fork)
|
20
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
21
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
22
|
+
4. Push to the branch (git push origin my-new-feature)
|
23
|
+
5. Create new Pull Request
|
24
|
+
|
25
|
+
## License
|
26
|
+
|
27
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/bin/fuck_bot
ADDED
data/lib/dictionary.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module FuckBot
|
5
|
+
class Dictionary
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
attr_reader :words
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@words = YAML.load_file(File.join(__dir__, '../dictionary.yml'))
|
12
|
+
.values
|
13
|
+
.flatten
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module FuckBot
|
2
|
+
class EventMachine
|
3
|
+
attr_reader :token, :user, :url, :ws
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@token = options.fetch(:token, ENV['FUCK_BOT_TOKEN'])
|
7
|
+
@logger = options.fetch(:logger, Logger.new(STDOUT))
|
8
|
+
|
9
|
+
rtm_start
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
@ws = Faye::WebSocket::Client.new(@url)
|
14
|
+
|
15
|
+
@ws.on(:open, on_open)
|
16
|
+
@ws.on(:message, on_message)
|
17
|
+
@ws.on(:close, on_close)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def on_open
|
23
|
+
lambda do |_event|
|
24
|
+
@logger.info(:open)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_message
|
29
|
+
lambda do |event|
|
30
|
+
data = Oj.load(event.data)
|
31
|
+
|
32
|
+
@logger.info(data.inspect)
|
33
|
+
|
34
|
+
MessageResolver.new(data, self).call
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def on_close
|
39
|
+
lambda do |_event|
|
40
|
+
@logger.info(:close)
|
41
|
+
|
42
|
+
EM.stop
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def rtm_start
|
47
|
+
response = RestClient.post(
|
48
|
+
'https://slack.com/api/rtm.start',
|
49
|
+
token: @token,
|
50
|
+
simple_latest: true,
|
51
|
+
no_unreads: true
|
52
|
+
)
|
53
|
+
|
54
|
+
response = Oj.load(response.body)
|
55
|
+
|
56
|
+
@user = response['self']
|
57
|
+
@url = response['url']
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module FuckBot
|
2
|
+
class MessageResolver
|
3
|
+
def initialize(data, event_machine)
|
4
|
+
@data = data
|
5
|
+
@event_machine = event_machine
|
6
|
+
end
|
7
|
+
|
8
|
+
def bad
|
9
|
+
found_bad_word = find_bad_word
|
10
|
+
|
11
|
+
return unless found_bad_word
|
12
|
+
|
13
|
+
send_response("Watch your language! «#{found_bad_word}» is a bad word!")
|
14
|
+
end
|
15
|
+
|
16
|
+
def ping
|
17
|
+
return unless ping?
|
18
|
+
|
19
|
+
send_response(:pong)
|
20
|
+
end
|
21
|
+
|
22
|
+
def call
|
23
|
+
return unless text_message?
|
24
|
+
|
25
|
+
rules.each do |rule|
|
26
|
+
public_send(rule)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def rules
|
33
|
+
self.class.instance_methods(false) - [:call]
|
34
|
+
end
|
35
|
+
|
36
|
+
def text_message?
|
37
|
+
@data['type'] == 'message' && !@data['text'].empty?
|
38
|
+
end
|
39
|
+
|
40
|
+
def ping?
|
41
|
+
@data['text'] == "<@#{@event_machine.user['id']}>: ping"
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_bad_word
|
45
|
+
text = @data['text'].downcase
|
46
|
+
|
47
|
+
FuckBot::Dictionary.instance.words.find do |word|
|
48
|
+
text.include?(word)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def send_response(text)
|
53
|
+
@event_machine.ws.send(
|
54
|
+
Oj.dump(
|
55
|
+
id: generate_id,
|
56
|
+
type: :message,
|
57
|
+
channel: @data['channel'],
|
58
|
+
text: text
|
59
|
+
)
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def generate_id
|
64
|
+
(Time.now.to_f * 100_000).to_i
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/fuck_bot.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'faye/websocket'
|
3
|
+
require 'eventmachine'
|
4
|
+
require 'rest-client'
|
5
|
+
require 'oj'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
require 'fuck_bot/dictionary'
|
9
|
+
require 'fuck_bot/event_machine'
|
10
|
+
require 'fuck_bot/message_resolver'
|
11
|
+
|
12
|
+
Oj.default_options = { mode: :compat }
|
13
|
+
|
14
|
+
module FuckBot
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fuck_bot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Novikov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faye-websocket
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.10.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.4
|
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.2.0.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.8.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: oj
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.15.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.15.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: codeclimate-test-reporter
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Slack bot to watch your language.
|
140
|
+
email:
|
141
|
+
- novikov359@gmail.com
|
142
|
+
executables:
|
143
|
+
- fuck_bot
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- MIT-LICENSE
|
148
|
+
- README.md
|
149
|
+
- bin/fuck_bot
|
150
|
+
- lib/dictionary.yml
|
151
|
+
- lib/fuck_bot.rb
|
152
|
+
- lib/fuck_bot/dictionary.rb
|
153
|
+
- lib/fuck_bot/event_machine.rb
|
154
|
+
- lib/fuck_bot/message_resolver.rb
|
155
|
+
- lib/fuck_bot/version.rb
|
156
|
+
homepage: https://github.com/droptheplot/fuck_bot
|
157
|
+
licenses:
|
158
|
+
- MIT
|
159
|
+
metadata: {}
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options: []
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 2.6.4
|
177
|
+
signing_key:
|
178
|
+
specification_version: 4
|
179
|
+
summary: Slack bot to watch your language.
|
180
|
+
test_files: []
|
181
|
+
has_rdoc:
|