fuck_bot 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -2
- data/bin/fuck_bot +6 -1
- data/lib/dictionary.yml +39 -0
- data/lib/fuck_bot.rb +2 -1
- data/lib/fuck_bot/{event_machine.rb → client.rb} +3 -2
- data/lib/fuck_bot/message_resolver.rb +32 -9
- data/lib/fuck_bot/store.rb +43 -0
- data/lib/fuck_bot/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea66261af7876ae715afea65f3c98b99204de85b
|
4
|
+
data.tar.gz: c6ff9fa8435f4bd4cc2452a1f3ee26533834e5c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41efe5b7638cb87b28ef9797950aa95075b7c61c6322fd7033f50115a2c7df76a976d3045298d96a76303fa38bf85ff00b3bf78c9e1d6016f8ccd11b4fd071ae
|
7
|
+
data.tar.gz: 4088661f92a1a18a622382043b9437b29ac8f82388e278aecd0495aae5fb23201e855cc39baa80cd2887c0d76d6dbf8160e72acdc4045997318f7461908050c3
|
data/README.md
CHANGED
@@ -6,13 +6,24 @@
|
|
6
6
|
|
7
7
|
Slack bot to watch your language.
|
8
8
|
|
9
|
+
<img src='https://raw.githubusercontent.com/droptheplot/fuck_bot/master/screenshot.png' width='480'>
|
10
|
+
|
9
11
|
## Installation
|
10
12
|
|
11
13
|
* Install gem: `gem install fuck_bot`.
|
12
14
|
* Create bot ([https://slack.com/apps/A0F7YS25R-bots](https://slack.com/apps/A0F7YS25R-bots)).
|
13
15
|
* Choose the name (`fuck_bot` or whatever you want).
|
14
|
-
* Copy API Token (e.g. xoxb-29512306146-LT8dwEeZQWLNWZmN9xs0m9zj).
|
15
|
-
* Run: `
|
16
|
+
* Copy API Token (e.g. `xoxb-29512306146-LT8dwEeZQWLNWZmN9xs0m9zj`).
|
17
|
+
* Run: `fuck_bot xoxb-29512306146-LT8dwEeZQWLNWZmN9xs0m9zj`
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
fuck_bot [token] [store]
|
23
|
+
```
|
24
|
+
|
25
|
+
* **[token]** - Slack Bot token. (e.g. `xoxb-29512306146-LT8dwEeZQWLNWZmN9xs0m9zj`)
|
26
|
+
* **[store]** - Path to `.pstore` file to store statistics. Default: `~/fuck_bot.pstore`
|
16
27
|
|
17
28
|
## Contributing
|
18
29
|
|
data/bin/fuck_bot
CHANGED
data/lib/dictionary.yml
CHANGED
@@ -1,6 +1,45 @@
|
|
1
1
|
en:
|
2
2
|
- fuck
|
3
|
+
- fuckin
|
4
|
+
- fucking
|
3
5
|
- shit
|
6
|
+
- ass
|
7
|
+
- anal
|
8
|
+
- boobs
|
9
|
+
- tit
|
10
|
+
- tits
|
11
|
+
- titty
|
12
|
+
- butt
|
13
|
+
- cunt
|
14
|
+
- dick
|
15
|
+
- faggot
|
16
|
+
- blowjob
|
17
|
+
- bullshit
|
18
|
+
- butthole
|
19
|
+
- whore
|
4
20
|
ru:
|
5
21
|
- хуй
|
22
|
+
- хуйня
|
23
|
+
- хуило
|
24
|
+
- хуйло
|
25
|
+
- нихуя
|
26
|
+
- дохуя
|
27
|
+
- охуеть
|
6
28
|
- пиздец
|
29
|
+
- пизда
|
30
|
+
- пиздить
|
31
|
+
- спиздить
|
32
|
+
- ебать
|
33
|
+
- наебать
|
34
|
+
- заебать
|
35
|
+
- заебал
|
36
|
+
- заебись
|
37
|
+
- блядь
|
38
|
+
- блядки
|
39
|
+
- блядовать
|
40
|
+
- блядство
|
41
|
+
- мудак
|
42
|
+
- мудило
|
43
|
+
- уебок
|
44
|
+
- уебан
|
45
|
+
- выблядок
|
data/lib/fuck_bot.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module FuckBot
|
2
|
-
class
|
3
|
-
attr_reader :token, :user, :url, :ws
|
2
|
+
class Client
|
3
|
+
attr_reader :token, :user, :url, :ws, :store
|
4
4
|
|
5
5
|
def initialize(options = {})
|
6
6
|
@token = options.fetch(:token, ENV['FUCK_BOT_TOKEN'])
|
7
7
|
@logger = options.fetch(:logger, Logger.new(STDOUT))
|
8
|
+
@store = FuckBot::Store.new(options[:store])
|
8
9
|
|
9
10
|
rtm_start
|
10
11
|
end
|
@@ -1,8 +1,13 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
|
1
4
|
module FuckBot
|
2
5
|
class MessageResolver
|
3
|
-
|
6
|
+
BAD_WORD_RESPONSE = "Watch your language, <@%s>! «%s» is a bad word!".freeze
|
7
|
+
|
8
|
+
def initialize(data, client)
|
4
9
|
@data = data
|
5
|
-
@
|
10
|
+
@client = client
|
6
11
|
end
|
7
12
|
|
8
13
|
def bad
|
@@ -10,7 +15,17 @@ module FuckBot
|
|
10
15
|
|
11
16
|
return unless found_bad_word
|
12
17
|
|
13
|
-
|
18
|
+
@client.store.increment(@data['user']).save
|
19
|
+
|
20
|
+
send_response(
|
21
|
+
format(BAD_WORD_RESPONSE, @data['user'], found_bad_word)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def stats
|
26
|
+
return unless stats?
|
27
|
+
|
28
|
+
send_response(@client.store.to_stats)
|
14
29
|
end
|
15
30
|
|
16
31
|
def ping
|
@@ -20,10 +35,10 @@ module FuckBot
|
|
20
35
|
end
|
21
36
|
|
22
37
|
def call
|
23
|
-
return unless text_message?
|
38
|
+
return unless text_message? && !self?
|
24
39
|
|
25
40
|
rules.each do |rule|
|
26
|
-
public_send(rule)
|
41
|
+
break if public_send(rule)
|
27
42
|
end
|
28
43
|
end
|
29
44
|
|
@@ -34,15 +49,23 @@ module FuckBot
|
|
34
49
|
end
|
35
50
|
|
36
51
|
def text_message?
|
37
|
-
@data['type'] == 'message' && !@data['text'].empty?
|
52
|
+
@data['type'] == 'message' && !@data['text'].to_s.empty?
|
53
|
+
end
|
54
|
+
|
55
|
+
def stats?
|
56
|
+
@data['text'] == "<@#{@client.user['id']}>: stats"
|
38
57
|
end
|
39
58
|
|
40
59
|
def ping?
|
41
|
-
@data['text'] == "<@#{@
|
60
|
+
@data['text'] == "<@#{@client.user['id']}>: ping"
|
61
|
+
end
|
62
|
+
|
63
|
+
def self?
|
64
|
+
@data['user'] == @client.user['id']
|
42
65
|
end
|
43
66
|
|
44
67
|
def find_bad_word
|
45
|
-
text = @data['text'].downcase
|
68
|
+
text = @data['text'].mb_chars.downcase.to_s
|
46
69
|
|
47
70
|
FuckBot::Dictionary.instance.words.find do |word|
|
48
71
|
text.include?(word)
|
@@ -50,7 +73,7 @@ module FuckBot
|
|
50
73
|
end
|
51
74
|
|
52
75
|
def send_response(text)
|
53
|
-
@
|
76
|
+
@client.ws.send(
|
54
77
|
Oj.dump(
|
55
78
|
id: generate_id,
|
56
79
|
type: :message,
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'pstore'
|
2
|
+
|
3
|
+
module FuckBot
|
4
|
+
class Store
|
5
|
+
STATS_RESPONSE = '<@%s>: %s'.freeze
|
6
|
+
|
7
|
+
attr_accessor :data
|
8
|
+
|
9
|
+
def initialize(path)
|
10
|
+
path ||= File.join(Dir.home, '.fuck_bot.pstore')
|
11
|
+
@ref = PStore.new(path)
|
12
|
+
|
13
|
+
load_data
|
14
|
+
end
|
15
|
+
|
16
|
+
def save
|
17
|
+
@ref.transaction do
|
18
|
+
@ref[:data] = @data
|
19
|
+
@ref.commit
|
20
|
+
end
|
21
|
+
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def increment(user_id)
|
26
|
+
@data[user_id] += 1
|
27
|
+
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_stats
|
32
|
+
@data.sort_by { |_, v| -v }.map do |user, count|
|
33
|
+
format(STATS_RESPONSE, user, count)
|
34
|
+
end.join("\n")
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def load_data
|
40
|
+
@data = @ref.transaction { @ref[:data] } || Hash.new(0)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/fuck_bot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fuck_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Novikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faye-websocket
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 2.15.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.2.6
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.2.6
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,9 +163,10 @@ files:
|
|
149
163
|
- bin/fuck_bot
|
150
164
|
- lib/dictionary.yml
|
151
165
|
- lib/fuck_bot.rb
|
166
|
+
- lib/fuck_bot/client.rb
|
152
167
|
- lib/fuck_bot/dictionary.rb
|
153
|
-
- lib/fuck_bot/event_machine.rb
|
154
168
|
- lib/fuck_bot/message_resolver.rb
|
169
|
+
- lib/fuck_bot/store.rb
|
155
170
|
- lib/fuck_bot/version.rb
|
156
171
|
homepage: https://github.com/droptheplot/fuck_bot
|
157
172
|
licenses:
|