robit 1.0.6 → 1.0.7

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: 9b702f7fa566c81565dd9c50315a8f161c40d58c
4
- data.tar.gz: 6cac2646b5cf23bde7311d601d29756e2bdf45a7
3
+ metadata.gz: f9b0bfff787afc2ebab624a7eaf168dd35270a42
4
+ data.tar.gz: d243686db3497aeb08e48c56fe839ef9709455fc
5
5
  SHA512:
6
- metadata.gz: 0449177e28d85571c163d5be9194d9bed9a250502b982612614217930d5a23edb529395e3931c20190b1bbc64e3aaa16b7e390c0dcd4890dcf731783f5a7bf6e
7
- data.tar.gz: c2c9947dee3665287cc8021b88c9d348b89d684244e5942a10a58ebc5ae47405922c144e7a024c5927f4d2ece8507fbdba708573588afcd5fd566d4d3965a77e
6
+ metadata.gz: af4e5abf97b6cfe983f722482ec64da579381cc2ba765c56837e7f791d18706c6ec75a17e8ac98d47a2b96dd62918ebe1b7e868727f898642c99719c23d70abe
7
+ data.tar.gz: e012d27499e0a6cae806fa5250039319f479c0155bdf02be07f47b4d4301ec34a50ed472af8ef7da18d9d48f7a86bc6805dbaa09bb41e889ec8924e3f5da773a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.6
1
+ 1.0.7
data/bin/robit CHANGED
@@ -86,7 +86,8 @@ Robut::Plugin.plugins = [
86
86
  Robut::Plugin::Lunch,
87
87
  Robut::Plugin::Later,
88
88
  Robut::Plugin::Help,
89
- Robut::Plugin::AliasNick
89
+ Robut::Plugin::AliasNick,
90
+ Robut::Plugin::Commitments
90
91
  ]
91
92
 
92
93
  Robut::Web.set :connection, Robut::Connection.new.connect
@@ -1,3 +1,4 @@
1
1
  require_relative 'robit/metadata'
2
2
  require_relative 'robit/plugins/status'
3
- require_relative 'robit/plugins/alias_nick'
3
+ require_relative 'robit/plugins/alias_nick'
4
+ require_relative 'robit/plugins/commitments'
@@ -0,0 +1,123 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'thread'
4
+ require 'json'
5
+
6
+
7
+ class Robut::Plugin::Commitments
8
+ include Robut::Plugin
9
+
10
+ def usage
11
+ [
12
+ 'Usage:',
13
+ "#commit - Return all commitments",
14
+ "#commit help - Return this help text",
15
+ "#commit clear - Delete all commitments",
16
+ "#commit delete <N> - Delete a commitment",
17
+ "#commit marquee - Start a rolling marquee",
18
+ "#commit <commitment> - Make a new commitment"
19
+ ].join("\n")
20
+ end
21
+
22
+ def handle time, sender, message
23
+ case message.strip.lines.join(' ')
24
+ when /^#commit$/
25
+ cs = commits
26
+ if cs.empty?
27
+ reply 'No commitments'
28
+ else
29
+ reply prettify(cs)
30
+ end
31
+ when /^#commit +help$/
32
+ reply usage
33
+ when /^#commit +clear$/
34
+ cs = clear
35
+ if cs.empty?
36
+ reply 'No commitments to clear'
37
+ else
38
+ reply 'Cleared commitments'
39
+ end
40
+ when /^#commit +delete +(\d+)$/
41
+ c = delete($1)
42
+ if c
43
+ reply 'Deleted commitment'
44
+ else
45
+ reply 'No such commitment to delete'
46
+ end
47
+ when /^#commit +marquee +stop?$/
48
+ if threads.include? current_room_name
49
+ threads.delete(current_room_name).kill
50
+ reply 'Stopped marquee'
51
+ else
52
+ reply 'No such marquee to stop'
53
+ end
54
+ when /^#commit +marquee( +\d+)?$/
55
+ if threads.include? current_room_name
56
+ reply 'Already going'
57
+ else
58
+ interval = ($1 || '60').strip.to_i
59
+ threads[current_room_name] = Thread.new do
60
+ periodically_update_topic current_room, interval
61
+ end
62
+ reply 'Started marquee'
63
+ end
64
+ when /^#commit +(.*?)$/m
65
+ cs = commit $1
66
+ reply prettify(cs)
67
+ when /^#commit/
68
+ reply 'Invalid ' + usage
69
+ end
70
+ end
71
+
72
+
73
+ private
74
+ def threads
75
+ @@threads ||= {}
76
+ end
77
+
78
+ def periodically_update_topic room, interval
79
+ loop do
80
+ c = commits.sample(1).shift
81
+ $stderr.puts 'periodically_update_topic room:%s interval:%d commit:%s' % [
82
+ room['name'].inspect, interval, c.inspect
83
+ ]
84
+ room['raw'].topic c if c
85
+ sleep interval
86
+ end
87
+ end
88
+
89
+ def prettify cs
90
+ cs.each_with_index.map { |c,i| '%d: %s' % [ i, c ] }.join("\n")
91
+ end
92
+
93
+ def commitments
94
+ store['commitments'] ||= {}
95
+ end
96
+
97
+ def commits
98
+ commitments[current_room_name] ||= []
99
+ end
100
+
101
+ def commit commitment
102
+ commits << commitment
103
+ end
104
+
105
+ def delete n
106
+ commits.delete_at n.to_i
107
+ end
108
+
109
+ def clear
110
+ commitments.delete current_room_name
111
+ end
112
+
113
+ def current_room
114
+ rooms = reply_to.connection.config.hipchat_rooms
115
+ room = rooms.select { |r| r['xmpp_jid'] == reply_to.name }.shift
116
+ raise 'Invalid room' unless room
117
+ return room
118
+ end
119
+
120
+ def current_room_name r=current_room
121
+ r && r['name']
122
+ end
123
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Clemmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2016-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twss-classifier
@@ -154,6 +154,7 @@ files:
154
154
  - lib/robit.rb
155
155
  - lib/robit/metadata.rb
156
156
  - lib/robit/plugins/alias_nick.rb
157
+ - lib/robit/plugins/commitments.rb
157
158
  - lib/robit/plugins/status.rb
158
159
  - robit.gemspec
159
160
  - tasks/package/Dockerfile