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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bcad5f258d6f12adc8bf514bb42b091e9110c73
4
- data.tar.gz: feeac45bcda8da737ecd41ba628e274a10b57645
3
+ metadata.gz: 54491438c61fbc0c1e79e1d389c516515f56e432
4
+ data.tar.gz: 3c56a186e20caaa7c40ae13111c1bc83ec2f429f
5
5
  SHA512:
6
- metadata.gz: 39c955ee2d2b30aae1ccdf8f853b3f37024bd67e5ff82750627431af3458f3d5a4696f868a8fe5f027e6ac0c4ded17fc1b95817484ade07164f70c997ea95dfd
7
- data.tar.gz: ed6ff5dbc00eaf9267c0be105ce3ade7ee99e6c54941b1198c9c5b99318dbc27e4674a064febcff3272743024f3207b157753a3c6b1185c533028c0e8563b008
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 certain words in the twitter stream.
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 by rubygems
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 by the certain term.')
6
+ description: 'Track the twitter stream with the term.')
7
7
 
8
- on(/twitter untrack by (?<term>.+)\z/,
8
+ on(/twitter untrack (?<id>\d+)\z/,
9
9
  name: 'untrack',
10
- description: 'Untrack the twitter stream by the certain term.')
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
- words = term.strip.split(/\s+/).sort
28
- cache[:terms].push(words).uniq!
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("Done.")
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[:term].split(',').each do |term|
43
- words = term.strip.split(/\s+/).sort
44
- cache[:terms].delete(words)
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("Done.")
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| message.reply(words.join(' ') }.join("\n")
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
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module TwitterTrack
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  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 = ['haccht00@gmail.com']
10
- spec.summary = "Ruboty handler to track tweets in the twitter stream."
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.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: 2015-12-25 00:00:00.000000000 Z
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 tweets in the twitter stream.
69
+ description: Ruboty handler to track the twitter stream with the given words.
70
70
  email:
71
- - haccht00@gmail.com
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 tweets in the twitter stream.
109
+ summary: Ruboty handler to track the twitter stream with the given words.
110
110
  test_files: []