ruboty-twitter_track 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +5 -5
- data/lib/ruboty/handlers/twitter_track.rb +24 -15
- data/lib/ruboty/twitter_track/version.rb +1 -1
- data/ruboty-twitter_track.gemspec +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54491438c61fbc0c1e79e1d389c516515f56e432
|
4
|
+
data.tar.gz: 3c56a186e20caaa7c40ae13111c1bc83ec2f429f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d9ccb877689b0f62efc1a6147c945325fcbc0568e594ca361357a2bb17911c9633b7a220108cbe6fb9e19dc53a926ef9cabf1f2d864cf83b7a5f6435707647f
|
7
|
+
data.tar.gz: ed1375c1d5e801b5e6431537ab6c14019cf6c7ec97f4d2a53b55a1266d829b13c6b3044328b71999f1fc222989b3beaefaf5f04c1152fef925a60470f6578de9
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Ruboty::TwitterTrack
|
2
2
|
|
3
|
-
Ruboty handler to track
|
3
|
+
Ruboty handler to track the twitter stream with the given words.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,17 +18,17 @@ And then execute:
|
|
18
18
|
|
19
19
|
```
|
20
20
|
> @ruboty twitter track by rubygems
|
21
|
-
@ruboty> Tracked 'rubygems'
|
21
|
+
@ruboty> Tracked 'rubygems'.
|
22
22
|
|
23
23
|
@ruboty> https://twitter.com/haccht/status/123456789
|
24
24
|
@ruboty> https://twitter.com/haccht/status/123456790
|
25
25
|
@ruboty> https://twitter.com/haccht/status/123456791
|
26
26
|
|
27
27
|
> @ruboty twitter tracking
|
28
|
-
@ruboty> 'rubygems'
|
28
|
+
@ruboty> '100: rubygems'
|
29
29
|
|
30
|
-
> @ruboty twitter untrack
|
31
|
-
@ruboty> Untracked 'rubygems'
|
30
|
+
> @ruboty twitter untrack 100
|
31
|
+
@ruboty> Untracked '100: rubygems'.
|
32
32
|
```
|
33
33
|
|
34
34
|
## Env
|
@@ -3,11 +3,11 @@ module Ruboty
|
|
3
3
|
class TwitterTrack < Base
|
4
4
|
on(/twitter track by (?<term>.+)\z/,
|
5
5
|
name: 'track',
|
6
|
-
description: 'Track the twitter stream
|
6
|
+
description: 'Track the twitter stream with the term.')
|
7
7
|
|
8
|
-
on(/twitter untrack
|
8
|
+
on(/twitter untrack (?<id>\d+)\z/,
|
9
9
|
name: 'untrack',
|
10
|
-
description: 'Untrack the twitter stream
|
10
|
+
description: 'Untrack the twitter stream with the term.')
|
11
11
|
|
12
12
|
on(/twitter tracking\z/,
|
13
13
|
name: 'tracking',
|
@@ -24,13 +24,14 @@ module Ruboty
|
|
24
24
|
cache[:message] = message.original.except(:robot)
|
25
25
|
|
26
26
|
message[:term].split(',').each do |term|
|
27
|
-
|
28
|
-
|
27
|
+
key = generate_id
|
28
|
+
words = term.strip.split(/\s+/)
|
29
|
+
cache[:terms][key] = words
|
29
30
|
end
|
30
31
|
|
31
32
|
begin
|
32
|
-
@stream.restart(cache[:message], cache[:terms])
|
33
|
-
message.reply("
|
33
|
+
@stream.restart(cache[:message], cache[:terms].values)
|
34
|
+
message.reply("Tracked '#{message[:term]}'.")
|
34
35
|
rescue Twitter::Error::Forbidden
|
35
36
|
message.reply("Unable to verify your credentials.")
|
36
37
|
end
|
@@ -39,14 +40,16 @@ module Ruboty
|
|
39
40
|
def untrack(message)
|
40
41
|
cache[:message] = message.original.except(:robot)
|
41
42
|
|
42
|
-
message[:
|
43
|
-
|
44
|
-
|
43
|
+
key = message[:id]
|
44
|
+
words = cache[:terms].delete(key)
|
45
|
+
unless words
|
46
|
+
message.reply("'#{key}' not found.")
|
47
|
+
return
|
45
48
|
end
|
46
49
|
|
47
50
|
begin
|
48
|
-
@stream.restart(cache[:message], cache[:terms])
|
49
|
-
message.reply("
|
51
|
+
@stream.restart(cache[:message], cache[:terms].values)
|
52
|
+
message.reply("Untracked '#{key}: #{words.join(' ')}'.")
|
50
53
|
rescue Twitter::Error::Forbidden
|
51
54
|
message.reply("Unable to verify your credentials.")
|
52
55
|
end
|
@@ -56,19 +59,25 @@ module Ruboty
|
|
56
59
|
if cache[:terms].empty?
|
57
60
|
message.reply("Tracking no terms.")
|
58
61
|
else
|
59
|
-
response = cache[:terms].map { |words|
|
60
|
-
message.reply(response, code:true)
|
62
|
+
response = cache[:terms].map { |key, words| "#{key}: #{words.join(' ')}" }
|
63
|
+
message.reply(response.join("\n"), code:true)
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
64
67
|
def cache
|
65
68
|
unless robot.brain.data[Ruboty::TwitterTrack::NAMESPACE]
|
66
|
-
status = { message: nil, terms:
|
69
|
+
status = { message: nil, terms: {} }
|
67
70
|
robot.brain.data[Ruboty::TwitterTrack::NAMESPACE] = status
|
68
71
|
end
|
69
72
|
|
70
73
|
robot.brain.data[Ruboty::TwitterTrack::NAMESPACE]
|
71
74
|
end
|
75
|
+
|
76
|
+
private
|
77
|
+
def generate_id
|
78
|
+
id = (100..999).to_a.sample
|
79
|
+
cache[:terms][id].nil? ? id : generate_id
|
80
|
+
end
|
72
81
|
end
|
73
82
|
end
|
74
83
|
end
|
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = 'ruboty-twitter_track'
|
7
7
|
spec.version = Ruboty::TwitterTrack::VERSION
|
8
8
|
spec.authors = ['haccht']
|
9
|
-
spec.email = ['
|
10
|
-
spec.summary = "Ruboty handler to track
|
9
|
+
spec.email = ['haccht@users.noreply.github.com']
|
10
|
+
spec.summary = "Ruboty handler to track the twitter stream with the given words."
|
11
11
|
spec.description = spec.summary
|
12
12
|
spec.homepage = 'https://github.com/haccht/ruboty-twitter_track'
|
13
13
|
spec.license = 'MIT'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-twitter_track
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- haccht
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|
@@ -66,9 +66,9 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Ruboty handler to track
|
69
|
+
description: Ruboty handler to track the twitter stream with the given words.
|
70
70
|
email:
|
71
|
-
-
|
71
|
+
- haccht@users.noreply.github.com
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
@@ -106,5 +106,5 @@ rubyforge_project:
|
|
106
106
|
rubygems_version: 2.4.5
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
|
-
summary: Ruboty handler to track
|
109
|
+
summary: Ruboty handler to track the twitter stream with the given words.
|
110
110
|
test_files: []
|