cinch-hangouts 1.0.1 → 1.0.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.
data/lib/cinch-hangouts.rb
CHANGED
@@ -5,6 +5,7 @@ require 'cinch/toolbox'
|
|
5
5
|
require 'time-lord'
|
6
6
|
|
7
7
|
module Cinch::Plugins
|
8
|
+
# Plugin to track Google Hangout links
|
8
9
|
class Hangouts
|
9
10
|
include Cinch::Plugin
|
10
11
|
@@hangout_filename = ''
|
@@ -12,7 +13,8 @@ module Cinch::Plugins
|
|
12
13
|
|
13
14
|
attr_accessor :storage
|
14
15
|
|
15
|
-
self.help =
|
16
|
+
self.help = 'Use .hangouts to see the info for any recent hangouts. You ' +
|
17
|
+
'can also use .hangouts subscribe to sign up for notifications'
|
16
18
|
|
17
19
|
match /hangouts\z/, method: :list_hangouts
|
18
20
|
match /hangouts subscribe/, method: :subscribe
|
@@ -20,72 +22,74 @@ module Cinch::Plugins
|
|
20
22
|
|
21
23
|
listen_to :channel
|
22
24
|
|
23
|
-
# This is the regex that captures hangout links
|
24
|
-
#
|
25
|
-
|
26
|
-
# The regex will need to be updated if the url scheme changes in the future.
|
27
|
-
HANGOUTS_REGEX = /plus\.google\.com\/hangouts\/_\/([a-z0-9]{10,40})(\?|$)/
|
25
|
+
# This is the regex that captures hangout links
|
26
|
+
# The regex will need to be updated if the url scheme changes in the future
|
27
|
+
HANGOUTS_REGEX = %r(plus\.google\.com/hangouts/_/([a-z0-9]{10,40})(\?|$))
|
28
28
|
|
29
29
|
def initialize(*args)
|
30
30
|
super
|
31
|
-
@@
|
32
|
-
|
31
|
+
@@subscription_filename = config[:subscription_filename] ||
|
32
|
+
'yaml/hangout_subscriptions.yml'
|
33
|
+
@@hangout_filename = config[:hangout_filename] ||
|
34
|
+
'yaml/hangouts.yml'
|
33
35
|
|
34
|
-
@
|
35
|
-
@response_type
|
36
|
+
@expire = config[:expire_period] || 120
|
37
|
+
@response_type = config[:response_type] || :notice
|
36
38
|
end
|
37
39
|
|
38
40
|
def listen(m)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
hangout_id = m.message[HANGOUTS_REGEX, 1]
|
42
|
+
process_hangout(hangout_id, m) if hangout_id
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_hangout(hangout_id, m)
|
46
|
+
if Hangout.find_by_id(hangout_id)
|
47
|
+
# If it's an old hangout capture a new expiration time
|
48
|
+
hangout.time = Time.now
|
49
|
+
hangout.save
|
50
|
+
else
|
51
|
+
hangout = Hangout.new(m.user.nick, hangout_id, Time.now)
|
52
|
+
hangout.save
|
53
|
+
Subscription.notify(hangout_id, @bot)
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
53
57
|
def subscribe(m)
|
54
58
|
nick = m.user.nick
|
55
59
|
if Subscription.for_user(nick)
|
56
|
-
msg =
|
60
|
+
msg = 'You are already subscribed. '
|
57
61
|
else
|
58
62
|
sub = Subscription.new(nick)
|
59
63
|
sub.save
|
60
|
-
msg =
|
64
|
+
msg = 'You are now subscribed.' +
|
65
|
+
'I will let you know when a hangout is linked. '
|
61
66
|
end
|
62
|
-
m.user.notice msg +
|
67
|
+
m.user.notice msg + 'To unsubscribe use `.hangouts unsubscribe`.'
|
63
68
|
end
|
64
69
|
|
65
70
|
def unsubscribe(m)
|
66
71
|
nick = m.user.nick
|
67
72
|
if Subscription.for_user(nick)
|
68
73
|
Subscription.for_user(nick).delete
|
69
|
-
msg =
|
74
|
+
msg = 'You are now unsubscribed, and will no ' +
|
75
|
+
'longer receive a messages. '
|
70
76
|
else
|
71
|
-
msg =
|
77
|
+
msg = 'You are not subscribed. '
|
72
78
|
end
|
73
|
-
m.user.notice msg +
|
79
|
+
m.user.notice msg + 'To subscribe use `.hangouts subscribe`.'
|
74
80
|
end
|
75
81
|
|
76
82
|
def list_hangouts(m)
|
77
|
-
Hangout.delete_expired(@
|
83
|
+
Hangout.delete_expired(@expire)
|
78
84
|
hangouts = Hangout.sorted
|
85
|
+
m.user.notice 'No hangouts have been linked recently!' if hangouts.empty?
|
79
86
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
m.user.notice "
|
84
|
-
|
85
|
-
|
86
|
-
m.user.notice "#{hangout.nick} started a hangout at #{Hangout.url(hangout.id)} " +
|
87
|
-
"it was last linked #{hangout.time.ago.to_words}"
|
88
|
-
end
|
87
|
+
m.user.notice 'These hangouts have been linked in the last ' +
|
88
|
+
"#{@expire} minutes. They may or may not still be going."
|
89
|
+
hangouts.each do |hangout|
|
90
|
+
m.user.notice "#{hangout.nick} started a hangout at " +
|
91
|
+
Hangout.url(hangout.id) +
|
92
|
+
" it was last linked #{hangout.time.ago.to_words}"
|
89
93
|
end
|
90
94
|
end
|
91
95
|
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# Class to manage Hangout information
|
1
3
|
class Hangout < Cinch::Plugins::Hangouts
|
2
|
-
attr_accessor :nick, :id, :time
|
4
|
+
attr_accessor :nick, :id, :time, :hangout_filename
|
3
5
|
|
4
6
|
def initialize(nick, id, time)
|
5
7
|
@nick = nick
|
@@ -9,8 +11,8 @@ class Hangout < Cinch::Plugins::Hangouts
|
|
9
11
|
|
10
12
|
def save
|
11
13
|
storage = CinchStorage.new(@@hangout_filename)
|
12
|
-
storage.data[:hangouts] ||=
|
13
|
-
storage.data[:hangouts][
|
14
|
+
storage.data[:hangouts] ||= {}
|
15
|
+
storage.data[:hangouts][id] = self
|
14
16
|
storage.save
|
15
17
|
end
|
16
18
|
|
@@ -33,8 +35,8 @@ class Hangout < Cinch::Plugins::Hangouts
|
|
33
35
|
|
34
36
|
def self.sorted
|
35
37
|
hangouts = listing.values
|
36
|
-
hangouts.sort! { |x,y| y.time <=> x.time }
|
37
|
-
|
38
|
+
hangouts.sort! { |x, y| y.time <=> x.time }
|
39
|
+
hangouts
|
38
40
|
end
|
39
41
|
|
40
42
|
def self.listing
|
@@ -52,7 +54,7 @@ class Hangout < Cinch::Plugins::Hangouts
|
|
52
54
|
def self.read_file
|
53
55
|
storage = CinchStorage.new(@@hangout_filename)
|
54
56
|
unless storage.data[:hangouts]
|
55
|
-
storage.data[:hangouts] =
|
57
|
+
storage.data[:hangouts] = {}
|
56
58
|
storage.save
|
57
59
|
end
|
58
60
|
storage
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# Class to handle user subscriptions
|
1
3
|
class Subscription < Cinch::Plugins::Hangouts
|
2
4
|
attr_accessor :nick, :all_links
|
3
5
|
|
4
6
|
def to_yaml
|
5
|
-
{
|
7
|
+
{}
|
6
8
|
end
|
7
9
|
|
8
10
|
def initialize(nick)
|
@@ -13,13 +15,13 @@ class Subscription < Cinch::Plugins::Hangouts
|
|
13
15
|
|
14
16
|
def save
|
15
17
|
subs = Subscription.storage
|
16
|
-
subs.data[
|
18
|
+
subs.data[nick] = self
|
17
19
|
subs.save
|
18
20
|
end
|
19
21
|
|
20
22
|
def delete
|
21
23
|
subs = Subscription.storage
|
22
|
-
subs.data[
|
24
|
+
subs.data[nick] = nil
|
23
25
|
subs.save
|
24
26
|
end
|
25
27
|
|
@@ -38,7 +40,8 @@ class Subscription < Cinch::Plugins::Hangouts
|
|
38
40
|
# Don't link the person who linked it.
|
39
41
|
if nick != sub.nick
|
40
42
|
user = Cinch::User.new(sub.nick, bot)
|
41
|
-
respond(user, "#{nick} just linked a new hangout at:
|
43
|
+
respond(user, "#{nick} just linked a new hangout at: " +
|
44
|
+
"#{Hangout.url(hangout_id)}")
|
42
45
|
end
|
43
46
|
end
|
44
47
|
end
|
@@ -49,4 +52,3 @@ class Subscription < Cinch::Plugins::Hangouts
|
|
49
52
|
CinchStorage.new(@@subscription_filename)
|
50
53
|
end
|
51
54
|
end
|
52
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-hangouts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10
|
12
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|