ruboty-tweetstream 0.0.3 → 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.
- checksums.yaml +4 -4
- data/README.md +12 -11
- data/lib/ruboty/handlers/tweetstream.rb +69 -21
- data/lib/ruboty/tweetstream/stream.rb +6 -8
- data/lib/ruboty/tweetstream/version.rb +1 -1
- data/ruboty-tweetstream.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82fd6a29c2eb198bc028cdaf0cc7795460543646
|
4
|
+
data.tar.gz: 0706a612363b5f0f7ae1dab7c8ba818841e2f8da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2591f7c7baea9dd4fee1ea2b1dbe3f0da0ce41227ca003ab005b8b0ddbf6b01ed65ba632323d249ba9fa793b99fe85e5139673a5a0ff6bc5490a0850db21a859
|
7
|
+
data.tar.gz: d2f7fb74fbd96ec6e7c7ece17de47dcbc2a17ee1a8a8d7cb55bf26997fdfc9baf20639d3e75db666689558d21e54f9c9bc17e20402ab4d6462116e1986cb98ed
|
data/README.md
CHANGED
@@ -13,29 +13,30 @@ gem 'ruboty-tweetstream'
|
|
13
13
|
## Usage
|
14
14
|
|
15
15
|
```
|
16
|
-
@ruboty add
|
17
|
-
@ruboty delete
|
18
|
-
@ruboty list
|
16
|
+
@ruboty add stream @<username>
|
17
|
+
@ruboty delete stream <id>
|
18
|
+
@ruboty list streams
|
19
|
+
@ruboty list streams --all
|
19
20
|
```
|
20
21
|
|
21
22
|
## Example
|
22
23
|
|
23
24
|
```
|
24
|
-
> @ruboty add
|
25
|
+
> @ruboty add stream @kaihar4
|
25
26
|
'@kaihar4' stream is started.
|
26
|
-
@kaihar4>
|
27
|
-
@kaihar4>
|
28
|
-
> @ruboty list
|
29
|
-
@kaihar4
|
30
|
-
> @ruboty delete
|
31
|
-
'
|
27
|
+
@kaihar4> test1
|
28
|
+
@kaihar4> test2
|
29
|
+
> @ruboty list streams
|
30
|
+
123: @kaihar4
|
31
|
+
> @ruboty delete stream 123
|
32
|
+
'123' stream is stopped.
|
32
33
|
```
|
33
34
|
|
34
35
|
## Setup
|
35
36
|
|
36
37
|
Ruboty::Tweetstream requires access tokens.
|
37
38
|
|
38
|
-
Please get from [
|
39
|
+
Please get keys from [here](https://apps.twitter.com/).
|
39
40
|
|
40
41
|
```
|
41
42
|
export CONSUMER_KEY=
|
@@ -1,11 +1,25 @@
|
|
1
1
|
require 'twitter'
|
2
|
+
require 'xrc'
|
3
|
+
|
4
|
+
Ruboty::Message.class_eval do
|
5
|
+
XMPP_PATERN = /\A(?:([^@]*)@)??([^@\/]*)(?:\/(.*?))?\z/
|
6
|
+
|
7
|
+
def channel
|
8
|
+
if XMPP_PATERN === from
|
9
|
+
# Get foobar@example.com in foobar@example.com/bot
|
10
|
+
Xrc::Jid.new(from).strip
|
11
|
+
else
|
12
|
+
from
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
2
16
|
|
3
17
|
module Ruboty
|
4
18
|
module Handlers
|
5
19
|
class Tweetstream < Base
|
6
|
-
on /add
|
7
|
-
on /list
|
8
|
-
on /delete
|
20
|
+
on /add stream @(?<username>.+)/, name: 'add', description: 'Add a tweetstream'
|
21
|
+
on /list streams(?<all_flag> --all)?\z/, name: 'list', description: 'Show all tweetstreams'
|
22
|
+
on /delete stream (?<id>.+)/, name: 'delete', description: 'Delete a tweetstream'
|
9
23
|
|
10
24
|
def initialize(*args)
|
11
25
|
super
|
@@ -13,55 +27,75 @@ module Ruboty
|
|
13
27
|
end
|
14
28
|
|
15
29
|
def add(message)
|
30
|
+
id = generate_id
|
16
31
|
username = message[:username]
|
17
|
-
|
32
|
+
channel = message.channel
|
33
|
+
|
34
|
+
if stream_exists?(username, channel)
|
18
35
|
message.reply("'@#{username}' stream is already started.")
|
19
36
|
else
|
20
37
|
stream = Ruboty::Tweetstream::Stream.new(
|
21
38
|
message.original.except(:robot).merge(
|
22
39
|
username: username,
|
23
|
-
|
40
|
+
twitter_id: twitter_id(username),
|
41
|
+
channel: channel
|
24
42
|
)
|
25
43
|
)
|
26
44
|
|
27
45
|
stream.start(robot)
|
28
|
-
running_streams[
|
46
|
+
running_streams[id] = stream
|
29
47
|
|
30
|
-
streams[
|
48
|
+
streams[id] = stream.hash
|
31
49
|
message.reply("'@#{username}' stream is started.")
|
32
50
|
end
|
51
|
+
rescue Twitter::Error::Forbidden
|
52
|
+
message.reply('Unable to verify your credentials.')
|
33
53
|
end
|
34
54
|
|
35
55
|
def delete(message)
|
36
|
-
|
37
|
-
if streams.has_key?(
|
38
|
-
running_streams[
|
39
|
-
running_streams.delete(
|
56
|
+
id = message[:id].to_i
|
57
|
+
if streams.has_key?(id)
|
58
|
+
running_streams[id].stop
|
59
|
+
running_streams.delete(id)
|
40
60
|
|
41
|
-
streams.delete(
|
42
|
-
message.reply("'
|
61
|
+
streams.delete(id)
|
62
|
+
message.reply("'#{id}' stream is stopped.")
|
43
63
|
else
|
44
|
-
message.reply("'
|
64
|
+
message.reply("'#{id}' stream is not found.")
|
45
65
|
end
|
46
66
|
end
|
47
67
|
|
48
68
|
def list(message)
|
49
|
-
|
69
|
+
sorted_streams = streams.sort_by {|_id, hash| hash[:username]}
|
70
|
+
|
71
|
+
if message[:all_flag]
|
72
|
+
stream_list = sorted_streams.map do |id, hash|
|
73
|
+
stream = "#{id}: @#{hash[:username]}"
|
74
|
+
stream << " (#{hash[:channel]})" unless hash[:channel].nil?
|
75
|
+
stream
|
76
|
+
end
|
77
|
+
else
|
78
|
+
stream_list = sorted_streams.map { |id, hash|
|
79
|
+
# Skip the channel that registered from other channel.
|
80
|
+
next unless hash[:channel] == message.channel
|
81
|
+
|
82
|
+
"#{id}: @#{hash[:username]}"
|
83
|
+
}.compact
|
84
|
+
end
|
85
|
+
|
86
|
+
if stream_list.empty?
|
50
87
|
message.reply("The stream doesn't exist.")
|
51
88
|
else
|
52
|
-
stream_list
|
53
|
-
"@#{username}"
|
54
|
-
end.join("\t")
|
55
|
-
message.reply(stream_list, code: true)
|
89
|
+
message.reply(stream_list.join("\n"), code: true)
|
56
90
|
end
|
57
91
|
end
|
58
92
|
|
59
93
|
def restart
|
60
|
-
streams.each do |
|
94
|
+
streams.each do |id, hash|
|
61
95
|
stream = Ruboty::Tweetstream::Stream.new(hash)
|
62
96
|
|
63
97
|
stream.start(robot)
|
64
|
-
running_streams[
|
98
|
+
running_streams[id] = stream
|
65
99
|
end
|
66
100
|
end
|
67
101
|
|
@@ -82,6 +116,20 @@ module Ruboty
|
|
82
116
|
end
|
83
117
|
client.user(username).id
|
84
118
|
end
|
119
|
+
|
120
|
+
def generate_id
|
121
|
+
loop do
|
122
|
+
id = rand(1000)
|
123
|
+
break id unless streams.has_key?(id)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def stream_exists?(username, channel)
|
128
|
+
streams.each do |_id, hash|
|
129
|
+
return true if hash[:username] == username && hash[:channel] == channel
|
130
|
+
end
|
131
|
+
return false
|
132
|
+
end
|
85
133
|
end
|
86
134
|
end
|
87
135
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'twitter'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
self.
|
7
|
-
!self.full_text.include?("@#{username}")
|
8
|
-
end
|
3
|
+
Twitter::Tweet.class_eval do
|
4
|
+
def is_pure_user_tweet?(username)
|
5
|
+
self.in_reply_to_screen_name.nil? &&\
|
6
|
+
!self.full_text.include?("@#{username}")
|
9
7
|
end
|
10
8
|
end
|
11
9
|
|
@@ -27,10 +25,10 @@ module Ruboty
|
|
27
25
|
|
28
26
|
def start(robot)
|
29
27
|
@thread = Thread.start do
|
30
|
-
@client.filter(follow: hash[:
|
28
|
+
@client.filter(follow: hash[:twitter_id].to_s) do |object|
|
31
29
|
if object.is_a?(Twitter::Tweet) && object.is_pure_user_tweet?(hash[:username])
|
32
30
|
Message.new(
|
33
|
-
hash.except(:username, :
|
31
|
+
hash.except(:username, :twitter_id).merge(robot: robot)
|
34
32
|
).reply("@#{hash[:username]}> #{object.full_text}")
|
35
33
|
end
|
36
34
|
end
|
data/ruboty-tweetstream.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-tweetstream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaihar4
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: xrc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|